Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved more tests

And fixed some timing issues induced by me
  • Loading branch information...
commit 57f3b106a6faab8c8f96b847ad91aaff856d43ef 1 parent 94d9408
@mads-b mads-b authored
View
6 cn/src/integrationtest/java/org/cloudname/zk/ZkCloudnameIntegrationTest.java
@@ -311,9 +311,9 @@ public void testCoordinateListenerConnectionDiesReconnectAfterTimeout() throws
log.info("Connection down.");
- Thread.sleep(900);
+ Thread.sleep(9000);
log.info("Recreating connection soon" + forwarderPort + "->" + zkport);
- Thread.sleep(200);
+ Thread.sleep(1000);
assertEquals(CoordinateListener.Event.NO_CONNECTION_TO_STORAGE,
listener.events.get(listener.events.size() -1 ));
forwarder = new PortForwarder(forwarderPort, "127.0.0.1", zkport);
@@ -326,7 +326,7 @@ public void testCoordinateListenerConnectionDiesReconnectAfterTimeout() throws
}
Thread.sleep(300);
}
- Thread.sleep(450);
+ Thread.sleep(4500);
assertEquals(CoordinateListener.Event.COORDINATE_OK, listener.events.get(listener.events.size() -1 ));
forwarder.terminate();
View
87 cn/src/integrationtest/java/org/cloudname/zk/ZkResolverIntegrationTest.java
@@ -40,9 +40,6 @@
* directory. The setup procedure also allocates a port that is
* free for the ZooKeeper server so that you should be able to run
* multiple instances of this test.
- * TODO: This exact same method is in ZkResolverTest.
- * Should there even be an integration test for ZkResolver? All tests only depend on ZK.
- * Maybe merge this class with ZkResolverTest yet again?
*/
@Before
public void setup() throws Exception {
@@ -116,6 +113,86 @@ public void testStatus() throws Exception {
assertEquals("Running message", status.getMessage());
}
+ @Test
+ public void testBasicSyncResolving() throws Exception {
+ List<Endpoint> endpoints = cn.getResolver().resolve("foo.1.service.user.cell");
+ assertEquals(1, endpoints.size());
+ assertEquals("foo", endpoints.get(0).getName());
+ assertEquals("localhost", endpoints.get(0).getHost());
+ assertEquals("1.service.user.cell", endpoints.get(0).getCoordinate().toString());
+ assertEquals("data", endpoints.get(0).getEndpointData());
+ assertEquals("http", endpoints.get(0).getProtocol());
+ }
+
+
+ @Test
+ public void testAnyResolving() throws Exception {
+ List<Endpoint> endpoints = cn.getResolver().resolve("foo.any.service.user.cell");
+ assertEquals(1, endpoints.size());
+ assertEquals("foo", endpoints.get(0).getName());
+ assertEquals("localhost", endpoints.get(0).getHost());
+ assertEquals("1.service.user.cell", endpoints.get(0).getCoordinate().toString());
+ }
+
+ @Test
+ public void testAllResolving() throws Exception {
+ List<Endpoint> endpoints = cn.getResolver().resolve("all.service.user.cell");
+ assertEquals(2, endpoints.size());
+ assertEquals("foo", endpoints.get(0).getName());
+ assertEquals("bar", endpoints.get(1).getName());
+ }
+
+ /**
+ * Tests that all registered endpoints are returned.
+ */
+ @Test
+ public void testGetCoordinateDataAll() throws Exception {
+ Resolver.CoordinateDataFilter filter = new Resolver.CoordinateDataFilter();
+ Set<Endpoint> endpoints = cn.getResolver().getEndpoints(filter);
+ assertEquals(4, endpoints.size());
+ }
+
+ /**
+ * Tests that all methods of the filters are called and some basic filtering are functional.
+ */
+ @Test
+ public void testGetCoordinateDataFilterOptions() throws Exception {
+ final StringBuilder filterCalls = new StringBuilder();
+
+ Resolver.CoordinateDataFilter filter = new Resolver.CoordinateDataFilter() {
+ @Override
+ public boolean includeCell(final String datacenter) {
+ filterCalls.append(datacenter).append(":");
+ return true;
+ }
+ @Override
+ public boolean includeUser(final String user) {
+ filterCalls.append(user).append(":");
+ return true;
+ }
+ @Override
+ public boolean includeService(final String service) {
+ filterCalls.append(service).append(":");
+ return true;
+ }
+ @Override
+ public boolean includeEndpointname(final String endpointName) {
+ return endpointName.equals("foo");
+ }
+ @Override
+ public boolean includeServiceState(final ServiceState state) {
+ return state == ServiceState.RUNNING;
+ }
+ };
+ Set<Endpoint> endpoints = cn.getResolver().getEndpoints(filter);
+ assertEquals(1, endpoints.size());
+ Endpoint selectedEndpoint = endpoints.iterator().next();
+
+ assertEquals("foo", selectedEndpoint.getName());
+ assertEquals("cell:user:service:", filterCalls.toString());
+ }
+
+
/**
* Test an unclaimed coordinate and a path that is not complete.
* Number of endpoints should not increase when inputting bad data.
@@ -244,7 +321,7 @@ public void endpointEvent(Event event, Endpoint endpoint) {
}
}
});
- assertTrue(latchWrapper.latch.await(2000, TimeUnit.MILLISECONDS));
+ assertTrue(latchWrapper.latch.await(5000, TimeUnit.MILLISECONDS));
assertEquals(1, endpointListNew.size());
assertEquals("foo", endpointListNew.get(0).getName());
assertEquals("1.service.user.cell", endpointListNew.get(0).getCoordinate().toString());
@@ -288,7 +365,7 @@ public void endpointEvent(Event event, Endpoint endpoint) {
}
};
resolver.addResolverListener("foo.all.service.user.cell", resolverListener);
- assertTrue(latchWrapper.latch.await(2000, TimeUnit.MILLISECONDS));
+ assertTrue(latchWrapper.latch.await(5000, TimeUnit.MILLISECONDS));
assertEquals(1, endpointListNew.size());
assertEquals("foo", endpointListNew.get(0).getName());
assertEquals("1.service.user.cell", endpointListNew.get(0).getCoordinate().toString());
View
131 cn/src/test/java/org/cloudname/zk/ZkResolverTest.java
@@ -28,7 +28,6 @@
* @author borud
*/
public class ZkResolverTest {
- private ZooKeeper zk;
private Resolver resolver;
@Rule
@@ -42,56 +41,12 @@
*/
@Before
public void setup() throws Exception {
- // Speed up tests waiting for this event to happen.
- DynamicExpression.TIME_BETWEEN_NODE_SCANNING_MS = 200;
-
- File rootDir = temp.newFolder("zk-test");
- final int zkport = Net.getFreePort();
-
- // Set up and initialize the embedded ZooKeeper
- final EmbeddedZooKeeper ezk = new EmbeddedZooKeeper(rootDir, zkport);
- ezk.init();
-
- // Set up a zookeeper client that we can use for inspection
- final CountDownLatch connectedLatch = new CountDownLatch(1);
- zk = new ZooKeeper("localhost:" + zkport, 1000, new Watcher() {
- public void process(WatchedEvent event) {
- if (event.getState() == Event.KeeperState.SyncConnected) {
- connectedLatch.countDown();
- }
- }
- });
- connectedLatch.await();
- //Make 4 endpoints divided between 2 coordinates
- final Coordinate coordinateRunning = Coordinate.parse("1.service.user.cell");
- final Coordinate coordinateDraining = Coordinate.parse("0.service.user.cell");
-
- Cloudname cn = new ZkCloudname.Builder().setConnectString("localhost:" + zkport).build().connect();
- cn.createCoordinate(coordinateRunning);
- cn.createCoordinate(coordinateDraining);
-
- ServiceHandle handleRunning = cn.claim(coordinateRunning);
- assertTrue(handleRunning.waitForCoordinateOkSeconds(30));
-
- handleRunning.putEndpoint(new Endpoint(coordinateRunning, "foo", "localhost", 1234, "http", "data"));
- handleRunning.putEndpoint(new Endpoint(coordinateRunning, "bar", "localhost", 1235, "http", null));
- ServiceStatus statusRunning = new ServiceStatus(ServiceState.RUNNING, "Running message");
- handleRunning.setStatus(statusRunning);
-
- ServiceHandle handleDraining = cn.claim(coordinateDraining);
- assertTrue(handleDraining.waitForCoordinateOkSeconds(10));
- handleDraining.putEndpoint(new Endpoint(coordinateDraining, "foo", "localhost", 5555, "http", "data"));
- handleDraining.putEndpoint(new Endpoint(coordinateDraining, "bar", "localhost", 5556, "http", null));
-
- ServiceStatus statusDraining = new ServiceStatus(ServiceState.DRAINING, "Draining message");
- handleDraining.setStatus(statusDraining);
- resolver = cn.getResolver();
+ resolver = new ZkResolver.Builder()
+ .addStrategy(new StrategyAll())
+ .addStrategy(new StrategyAny())
+ .build();
}
- @After
- public void tearDown() throws Exception {
- zk.close();
- }
// Valid endpoints.
public static final String[] validEndpointPatterns = new String[] {
"http.1.service.user.cell",
@@ -113,67 +68,6 @@ public void tearDown() throws Exception {
"some-endpoint.somestrategy.service.user.cell",
};
- @Test
- public void testBasicSyncResolving() throws Exception {
- List<Endpoint> endpoints = resolver.resolve("foo.1.service.user.cell");
- assertEquals(1, endpoints.size());
- assertEquals("foo", endpoints.get(0).getName());
- assertEquals("localhost", endpoints.get(0).getHost());
- assertEquals("1.service.user.cell", endpoints.get(0).getCoordinate().toString());
- assertEquals("data", endpoints.get(0).getEndpointData());
- assertEquals("http", endpoints.get(0).getProtocol());
- }
-
- /**
- * Tests that all registered endpoints are returned.
- */
- @Test
- public void testGetCoordinateDataAll() throws Exception {
- Resolver.CoordinateDataFilter filter = new Resolver.CoordinateDataFilter();
- Set<Endpoint> endpoints = resolver.getEndpoints(filter);
- assertEquals(4, endpoints.size());
- }
-
- /**
- * Tests that all methods of the filters are called and some basic filtering are functional.
- */
- @Test
- public void testGetCoordinateDataFilterOptions() throws Exception {
- final StringBuilder filterCalls = new StringBuilder();
-
- Resolver.CoordinateDataFilter filter = new Resolver.CoordinateDataFilter() {
- @Override
- public boolean includeCell(final String datacenter) {
- filterCalls.append(datacenter).append(":");
- return true;
- }
- @Override
- public boolean includeUser(final String user) {
- filterCalls.append(user).append(":");
- return true;
- }
- @Override
- public boolean includeService(final String service) {
- filterCalls.append(service).append(":");
- return true;
- }
- @Override
- public boolean includeEndpointname(final String endpointName) {
- return endpointName.equals("foo");
- }
- @Override
- public boolean includeServiceState(final ServiceState state) {
- return state == ServiceState.RUNNING;
- }
- };
- Set<Endpoint> endpoints = resolver.getEndpoints(filter);
- assertEquals(1, endpoints.size());
- Endpoint selectedEndpoint = endpoints.iterator().next();
-
- assertEquals("foo", selectedEndpoint.getName());
- assertEquals("cell:user:service:", filterCalls.toString());
- }
-
@Test(expected=IllegalArgumentException.class)
public void testRegisterSameListenerTwice() throws Exception {
Resolver.ResolverListener resolverListener = new Resolver.ResolverListener() {
@@ -187,23 +81,6 @@ public void endpointEvent(Event event, Endpoint endpoint) {
}
@Test
- public void testAnyResolving() throws Exception {
- List<Endpoint> endpoints = resolver.resolve("foo.any.service.user.cell");
- assertEquals(1, endpoints.size());
- assertEquals("foo", endpoints.get(0).getName());
- assertEquals("localhost", endpoints.get(0).getHost());
- assertEquals("1.service.user.cell", endpoints.get(0).getCoordinate().toString());
- }
-
- @Test
- public void testAllResolving() throws Exception {
- List<Endpoint> endpoints = resolver.resolve("all.service.user.cell");
- assertEquals(2, endpoints.size());
- assertEquals("foo", endpoints.get(0).getName());
- assertEquals("bar", endpoints.get(1).getName());
- }
-
- @Test
public void testEndpointPatterns() throws Exception {
// Test input that should match
for (String s : validEndpointPatterns) {
Please sign in to comment.
Something went wrong with that request. Please try again.