EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.compute.stub.config]

COVERAGE SUMMARY FOR SOURCE FILE [StubComputeServiceDependenciesModule.java]

nameclass, %method, %block, %line, %
StubComputeServiceDependenciesModule.java67%  (2/3)56%  (9/16)23%  (35/153)44%  (15/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class StubComputeServiceDependenciesModule$10%   (0/1)0%   (0/2)0%   (0/26)0%   (0/7)
StubComputeServiceDependenciesModule$1 (long, NodeMetadata, NodeState): void 0%   (0/1)0%   (0/12)0%   (0/1)
run (): void 0%   (0/1)0%   (0/14)0%   (0/6)
     
class StubComputeServiceDependenciesModule$StubSocketOpen100% (1/1)50%  (1/2)22%  (9/41)44%  (4/9)
apply (IPSocket): boolean 0%   (0/1)0%   (0/32)0%   (0/5)
StubComputeServiceDependenciesModule$StubSocketOpen (ConcurrentMap, String): ... 100% (1/1)100% (9/9)100% (4/4)
     
class StubComputeServiceDependenciesModule100% (1/1)67%  (8/12)30%  (26/86)58%  (11/19)
nodeWithState (NodeMetadata, NodeState): void 0%   (0/1)0%   (0/11)0%   (0/2)
provideNodeId (): Integer 0%   (0/1)0%   (0/4)0%   (0/1)
setState (NodeMetadata, NodeState, long): void 0%   (0/1)0%   (0/17)0%   (0/4)
stub (String, int, int, float): Hardware 0%   (0/1)0%   (0/28)0%   (0/1)
<static initializer> 100% (1/1)100% (12/12)100% (3/3)
StubComputeServiceDependenciesModule (): void 100% (1/1)100% (3/3)100% (2/2)
configure (): void 100% (1/1)100% (1/1)100% (1/1)
passwordPrefix (): String 100% (1/1)100% (2/2)100% (1/1)
privateIpPrefix (): String 100% (1/1)100% (2/2)100% (1/1)
provideNodes (): ConcurrentMap 100% (1/1)100% (2/2)100% (1/1)
publicIpPrefix (): String 100% (1/1)100% (2/2)100% (1/1)
socketOpen (StubComputeServiceDependenciesModule$StubSocketOpen): SocketOpen 100% (1/1)100% (2/2)100% (1/1)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.compute.stub.config;
20 
21import java.util.concurrent.ConcurrentHashMap;
22import java.util.concurrent.ConcurrentMap;
23import java.util.concurrent.ExecutorService;
24import java.util.concurrent.Executors;
25import java.util.concurrent.atomic.AtomicInteger;
26 
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.compute.domain.Hardware;
32import org.jclouds.compute.domain.NodeMetadata;
33import org.jclouds.compute.domain.NodeMetadataBuilder;
34import org.jclouds.compute.domain.NodeState;
35import org.jclouds.compute.domain.Processor;
36import org.jclouds.compute.domain.Volume;
37import org.jclouds.compute.domain.internal.VolumeImpl;
38import org.jclouds.net.IPSocket;
39import org.jclouds.predicates.SocketOpen;
40 
41import com.google.common.base.Throwables;
42import com.google.common.collect.ImmutableList;
43import com.google.inject.AbstractModule;
44import com.google.inject.Provides;
45 
46/**
47 * 
48 * @author Adrian Cole
49 */
50public class StubComputeServiceDependenciesModule extends AbstractModule {
51 
52   @Override
53   protected void configure() {
54 
55   }
56 
57   protected static final ConcurrentMap<String, NodeMetadata> backing = new ConcurrentHashMap<String, NodeMetadata>();
58 
59   // implementation details below
60   @Provides
61   @Singleton
62   ConcurrentMap<String, NodeMetadata> provideNodes() {
63      return backing;
64   }
65 
66   // STUB STUFF STATIC SO MULTIPLE CONTEXTS CAN SEE IT
67   private static final AtomicInteger nodeIds = new AtomicInteger(0);
68   static final ExecutorService service = Executors.newCachedThreadPool();
69 
70   @Provides
71   @Named("NODE_ID")
72   Integer provideNodeId() {
73      return nodeIds.incrementAndGet();
74   }
75 
76   @Singleton
77   @Provides
78   @Named("PUBLIC_IP_PREFIX")
79   String publicIpPrefix() {
80      return "144.175.1.";
81   }
82 
83   @Singleton
84   @Provides
85   @Named("PRIVATE_IP_PREFIX")
86   String privateIpPrefix() {
87      return "10.1.1.";
88   }
89 
90   @Singleton
91   @Provides
92   @Named("PASSWORD_PREFIX")
93   String passwordPrefix() {
94      return "password";
95   }
96 
97   @Singleton
98   @Provides
99   SocketOpen socketOpen(StubSocketOpen in) {
100      return in;
101   }
102 
103   @Singleton
104   public static class StubSocketOpen implements SocketOpen {
105      private final ConcurrentMap<String, NodeMetadata> nodes;
106      private final String publicIpPrefix;
107 
108      @Inject
109      public StubSocketOpen(ConcurrentMap<String, NodeMetadata> nodes, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix) {
110         this.nodes = nodes;
111         this.publicIpPrefix = publicIpPrefix;
112      }
113 
114      @Override
115      public boolean apply(IPSocket input) {
116         if (input.getAddress().indexOf(publicIpPrefix) == -1)
117            return false;
118         String id = input.getAddress().replace(publicIpPrefix, "");
119         NodeMetadata node = nodes.get(id);
120         return node != null && node.getState() == NodeState.RUNNING;
121      }
122 
123   }
124 
125   protected static void nodeWithState(NodeMetadata node, NodeState state) {
126      backing.put(node.getId(), NodeMetadataBuilder.fromNodeMetadata(node).state(state).build());
127   }
128 
129   public static void setState(final NodeMetadata node, final NodeState state, final long millis) {
130      if (millis == 0l)
131         nodeWithState(node, state);
132      else
133         service.execute(new Runnable() {
134 
135            @Override
136            public void run() {
137               try {
138                  Thread.sleep(millis);
139               } catch (InterruptedException e) {
140                  Throwables.propagate(e);
141               }
142               nodeWithState(node, state);
143            }
144 
145         });
146   }
147 
148   static Hardware stub(String type, int cores, int ram, float disk) {
149      return new org.jclouds.compute.domain.HardwareBuilder().ids(type).name(type)
150            .processors(ImmutableList.of(new Processor(cores, 1.0))).ram(ram)
151            .volumes(ImmutableList.<Volume> of(new VolumeImpl(disk, true, false))).build();
152   }
153 
154}

[all classes][org.jclouds.compute.stub.config]
EMMA 2.0.5312 (C) Vladimir Roubtsov