Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved more tests

And fixed some timing issues induced by me
  • Loading branch information...
commit 57f3b106a6faab8c8f96b847ad91aaff856d43ef 1 parent 94d9408
Mads Baardsgaard authored November 07, 2012
6  cn/src/integrationtest/java/org/cloudname/zk/ZkCloudnameIntegrationTest.java
@@ -311,9 +311,9 @@ public void testCoordinateListenerConnectionDiesReconnectAfterTimeout() throws
311 311
 
312 312
         log.info("Connection down.");
313 313
 
314  
-        Thread.sleep(900);
  314
+        Thread.sleep(9000);
315 315
         log.info("Recreating connection soon" + forwarderPort + "->" + zkport);
316  
-        Thread.sleep(200);
  316
+        Thread.sleep(1000);
317 317
         assertEquals(CoordinateListener.Event.NO_CONNECTION_TO_STORAGE,
318 318
                 listener.events.get(listener.events.size() -1 ));
319 319
         forwarder = new PortForwarder(forwarderPort, "127.0.0.1", zkport);
@@ -326,7 +326,7 @@ public void testCoordinateListenerConnectionDiesReconnectAfterTimeout() throws
326 326
             }
327 327
             Thread.sleep(300);
328 328
         }
329  
-        Thread.sleep(450);
  329
+        Thread.sleep(4500);
330 330
         assertEquals(CoordinateListener.Event.COORDINATE_OK, listener.events.get(listener.events.size() -1 ));
331 331
 
332 332
         forwarder.terminate();
87  cn/src/integrationtest/java/org/cloudname/zk/ZkResolverIntegrationTest.java
@@ -40,9 +40,6 @@
40 40
      * directory.  The setup procedure also allocates a port that is
41 41
      * free for the ZooKeeper server so that you should be able to run
42 42
      * multiple instances of this test.
43  
-     * TODO: This exact same method is in ZkResolverTest.
44  
-     * Should there even be an integration test for ZkResolver? All tests only depend on ZK.
45  
-     * Maybe merge this class with ZkResolverTest yet again?
46 43
      */
47 44
     @Before
48 45
     public void setup() throws Exception {
@@ -116,6 +113,86 @@ public void testStatus() throws Exception {
116 113
         assertEquals("Running message", status.getMessage());
117 114
     }
118 115
 
  116
+    @Test
  117
+    public void testBasicSyncResolving() throws Exception {
  118
+        List<Endpoint> endpoints = cn.getResolver().resolve("foo.1.service.user.cell");
  119
+        assertEquals(1, endpoints.size());
  120
+        assertEquals("foo", endpoints.get(0).getName());
  121
+        assertEquals("localhost", endpoints.get(0).getHost());
  122
+        assertEquals("1.service.user.cell", endpoints.get(0).getCoordinate().toString());
  123
+        assertEquals("data", endpoints.get(0).getEndpointData());
  124
+        assertEquals("http", endpoints.get(0).getProtocol());
  125
+    }
  126
+
  127
+
  128
+    @Test
  129
+    public void testAnyResolving() throws Exception {
  130
+        List<Endpoint> endpoints = cn.getResolver().resolve("foo.any.service.user.cell");
  131
+        assertEquals(1, endpoints.size());
  132
+        assertEquals("foo", endpoints.get(0).getName());
  133
+        assertEquals("localhost", endpoints.get(0).getHost());
  134
+        assertEquals("1.service.user.cell", endpoints.get(0).getCoordinate().toString());
  135
+    }
  136
+
  137
+    @Test
  138
+    public void testAllResolving() throws Exception {
  139
+        List<Endpoint> endpoints = cn.getResolver().resolve("all.service.user.cell");
  140
+        assertEquals(2, endpoints.size());
  141
+        assertEquals("foo", endpoints.get(0).getName());
  142
+        assertEquals("bar", endpoints.get(1).getName());
  143
+    }
  144
+
  145
+    /**
  146
+     * Tests that all registered endpoints are returned.
  147
+     */
  148
+    @Test
  149
+    public void testGetCoordinateDataAll() throws Exception {
  150
+        Resolver.CoordinateDataFilter filter = new Resolver.CoordinateDataFilter();
  151
+        Set<Endpoint> endpoints = cn.getResolver().getEndpoints(filter);
  152
+        assertEquals(4, endpoints.size());
  153
+    }
  154
+
  155
+    /**
  156
+     * Tests that all methods of the filters are called and some basic filtering are functional.
  157
+     */
  158
+    @Test
  159
+    public void testGetCoordinateDataFilterOptions() throws Exception {
  160
+        final StringBuilder filterCalls = new StringBuilder();
  161
+
  162
+        Resolver.CoordinateDataFilter filter = new Resolver.CoordinateDataFilter() {
  163
+            @Override
  164
+            public boolean includeCell(final String datacenter) {
  165
+                filterCalls.append(datacenter).append(":");
  166
+                return true;
  167
+            }
  168
+            @Override
  169
+            public boolean includeUser(final String user) {
  170
+                filterCalls.append(user).append(":");
  171
+                return true;
  172
+            }
  173
+            @Override
  174
+            public boolean includeService(final String service) {
  175
+                filterCalls.append(service).append(":");
  176
+                return true;
  177
+            }
  178
+            @Override
  179
+            public boolean includeEndpointname(final String endpointName) {
  180
+                return endpointName.equals("foo");
  181
+            }
  182
+            @Override
  183
+            public boolean includeServiceState(final ServiceState state) {
  184
+                return state == ServiceState.RUNNING;
  185
+            }
  186
+        };
  187
+        Set<Endpoint> endpoints = cn.getResolver().getEndpoints(filter);
  188
+        assertEquals(1, endpoints.size());
  189
+        Endpoint selectedEndpoint = endpoints.iterator().next();
  190
+
  191
+        assertEquals("foo", selectedEndpoint.getName());
  192
+        assertEquals("cell:user:service:", filterCalls.toString());
  193
+    }
  194
+
  195
+
119 196
     /**
120 197
      * Test an unclaimed coordinate and a path that is not complete.
121 198
      * Number of endpoints should not increase when inputting bad data.
@@ -244,7 +321,7 @@ public void endpointEvent(Event event, Endpoint endpoint) {
244 321
                 }
245 322
             }
246 323
         });
247  
-        assertTrue(latchWrapper.latch.await(2000, TimeUnit.MILLISECONDS));
  324
+        assertTrue(latchWrapper.latch.await(5000, TimeUnit.MILLISECONDS));
248 325
         assertEquals(1, endpointListNew.size());
249 326
         assertEquals("foo", endpointListNew.get(0).getName());
250 327
         assertEquals("1.service.user.cell", endpointListNew.get(0).getCoordinate().toString());
@@ -288,7 +365,7 @@ public void endpointEvent(Event event, Endpoint endpoint) {
288 365
             }
289 366
         };
290 367
         resolver.addResolverListener("foo.all.service.user.cell", resolverListener);
291  
-        assertTrue(latchWrapper.latch.await(2000, TimeUnit.MILLISECONDS));
  368
+        assertTrue(latchWrapper.latch.await(5000, TimeUnit.MILLISECONDS));
292 369
         assertEquals(1, endpointListNew.size());
293 370
         assertEquals("foo", endpointListNew.get(0).getName());
294 371
         assertEquals("1.service.user.cell", endpointListNew.get(0).getCoordinate().toString());
131  cn/src/test/java/org/cloudname/zk/ZkResolverTest.java
@@ -28,7 +28,6 @@
28 28
  * @author borud
29 29
  */
30 30
 public class ZkResolverTest {
31  
-    private ZooKeeper zk;
32 31
     private Resolver resolver;
33 32
 
34 33
     @Rule
@@ -42,56 +41,12 @@
42 41
      */
43 42
     @Before
44 43
     public void setup() throws Exception {
45  
-        // Speed up tests waiting for this event to happen.
46  
-        DynamicExpression.TIME_BETWEEN_NODE_SCANNING_MS = 200;
47  
-
48  
-        File rootDir = temp.newFolder("zk-test");
49  
-        final int zkport = Net.getFreePort();
50  
-
51  
-        // Set up and initialize the embedded ZooKeeper
52  
-        final EmbeddedZooKeeper ezk = new EmbeddedZooKeeper(rootDir, zkport);
53  
-        ezk.init();
54  
-
55  
-        // Set up a zookeeper client that we can use for inspection
56  
-        final CountDownLatch connectedLatch = new CountDownLatch(1);
57  
-        zk = new ZooKeeper("localhost:" + zkport, 1000, new Watcher() {
58  
-            public void process(WatchedEvent event) {
59  
-                if (event.getState() == Event.KeeperState.SyncConnected) {
60  
-                    connectedLatch.countDown();
61  
-                }
62  
-            }
63  
-        });
64  
-        connectedLatch.await();
65  
-        //Make 4 endpoints divided between 2 coordinates
66  
-        final Coordinate coordinateRunning = Coordinate.parse("1.service.user.cell");
67  
-        final Coordinate coordinateDraining = Coordinate.parse("0.service.user.cell");
68  
-
69  
-        Cloudname cn = new ZkCloudname.Builder().setConnectString("localhost:" + zkport).build().connect();
70  
-        cn.createCoordinate(coordinateRunning);
71  
-        cn.createCoordinate(coordinateDraining);
72  
-
73  
-        ServiceHandle handleRunning = cn.claim(coordinateRunning);
74  
-        assertTrue(handleRunning.waitForCoordinateOkSeconds(30));
75  
-
76  
-        handleRunning.putEndpoint(new Endpoint(coordinateRunning, "foo", "localhost", 1234, "http", "data"));
77  
-        handleRunning.putEndpoint(new Endpoint(coordinateRunning, "bar", "localhost", 1235, "http", null));
78  
-        ServiceStatus statusRunning = new ServiceStatus(ServiceState.RUNNING, "Running message");
79  
-        handleRunning.setStatus(statusRunning);
80  
-
81  
-        ServiceHandle handleDraining = cn.claim(coordinateDraining);
82  
-        assertTrue(handleDraining.waitForCoordinateOkSeconds(10));
83  
-        handleDraining.putEndpoint(new Endpoint(coordinateDraining, "foo", "localhost", 5555, "http", "data"));
84  
-        handleDraining.putEndpoint(new Endpoint(coordinateDraining, "bar", "localhost", 5556, "http", null));
85  
-
86  
-        ServiceStatus statusDraining = new ServiceStatus(ServiceState.DRAINING, "Draining message");
87  
-        handleDraining.setStatus(statusDraining);
88  
-        resolver = cn.getResolver();
  44
+        resolver = new ZkResolver.Builder()
  45
+                .addStrategy(new StrategyAll())
  46
+                .addStrategy(new StrategyAny())
  47
+                .build();
89 48
     }
90 49
 
91  
-    @After
92  
-    public void tearDown() throws Exception {
93  
-        zk.close();
94  
-    }
95 50
     // Valid endpoints.
96 51
     public static final String[] validEndpointPatterns = new String[] {
97 52
             "http.1.service.user.cell",
@@ -113,67 +68,6 @@ public void tearDown() throws Exception {
113 68
             "some-endpoint.somestrategy.service.user.cell",
114 69
     };
115 70
 
116  
-    @Test
117  
-    public void testBasicSyncResolving() throws Exception {
118  
-        List<Endpoint> endpoints = resolver.resolve("foo.1.service.user.cell");
119  
-        assertEquals(1, endpoints.size());
120  
-        assertEquals("foo", endpoints.get(0).getName());
121  
-        assertEquals("localhost", endpoints.get(0).getHost());
122  
-        assertEquals("1.service.user.cell", endpoints.get(0).getCoordinate().toString());
123  
-        assertEquals("data", endpoints.get(0).getEndpointData());
124  
-        assertEquals("http", endpoints.get(0).getProtocol());
125  
-    }
126  
-
127  
-    /**
128  
-     * Tests that all registered endpoints are returned.
129  
-     */
130  
-    @Test
131  
-    public void testGetCoordinateDataAll() throws Exception {
132  
-        Resolver.CoordinateDataFilter filter = new Resolver.CoordinateDataFilter();
133  
-        Set<Endpoint> endpoints = resolver.getEndpoints(filter);
134  
-        assertEquals(4, endpoints.size());
135  
-    }
136  
-
137  
-    /**
138  
-     * Tests that all methods of the filters are called and some basic filtering are functional.
139  
-     */
140  
-    @Test
141  
-    public void testGetCoordinateDataFilterOptions() throws Exception {
142  
-        final StringBuilder filterCalls = new StringBuilder();
143  
-
144  
-        Resolver.CoordinateDataFilter filter = new Resolver.CoordinateDataFilter() {
145  
-            @Override
146  
-            public boolean includeCell(final String datacenter) {
147  
-                filterCalls.append(datacenter).append(":");
148  
-                return true;
149  
-            }
150  
-            @Override
151  
-            public boolean includeUser(final String user) {
152  
-                filterCalls.append(user).append(":");
153  
-                return true;
154  
-            }
155  
-            @Override
156  
-            public boolean includeService(final String service) {
157  
-                filterCalls.append(service).append(":");
158  
-                return true;
159  
-            }
160  
-            @Override
161  
-            public boolean includeEndpointname(final String endpointName) {
162  
-                return endpointName.equals("foo");
163  
-            }
164  
-            @Override
165  
-            public boolean includeServiceState(final ServiceState state) {
166  
-                return state == ServiceState.RUNNING;
167  
-            }
168  
-        };
169  
-        Set<Endpoint> endpoints = resolver.getEndpoints(filter);
170  
-        assertEquals(1, endpoints.size());
171  
-        Endpoint selectedEndpoint = endpoints.iterator().next();
172  
-
173  
-        assertEquals("foo", selectedEndpoint.getName());
174  
-        assertEquals("cell:user:service:", filterCalls.toString());
175  
-    }
176  
-
177 71
     @Test(expected=IllegalArgumentException.class)
178 72
     public void testRegisterSameListenerTwice() throws Exception {
179 73
         Resolver.ResolverListener resolverListener = new Resolver.ResolverListener() {
@@ -187,23 +81,6 @@ public void endpointEvent(Event event, Endpoint endpoint) {
187 81
     }
188 82
 
189 83
     @Test
190  
-    public void testAnyResolving() throws Exception {
191  
-        List<Endpoint> endpoints = resolver.resolve("foo.any.service.user.cell");
192  
-        assertEquals(1, endpoints.size());
193  
-        assertEquals("foo", endpoints.get(0).getName());
194  
-        assertEquals("localhost", endpoints.get(0).getHost());
195  
-        assertEquals("1.service.user.cell", endpoints.get(0).getCoordinate().toString());
196  
-    }
197  
-
198  
-    @Test
199  
-    public void testAllResolving() throws Exception {
200  
-        List<Endpoint> endpoints = resolver.resolve("all.service.user.cell");
201  
-        assertEquals(2, endpoints.size());
202  
-        assertEquals("foo", endpoints.get(0).getName());
203  
-        assertEquals("bar", endpoints.get(1).getName());
204  
-    }
205  
-
206  
-    @Test
207 84
     public void testEndpointPatterns() throws Exception {
208 85
         // Test input that should match
209 86
         for (String s : validEndpointPatterns) {

0 notes on commit 57f3b10

Please sign in to comment.
Something went wrong with that request. Please try again.