@Test public void testCreateOfConfig() throws Exception { // This test first the config is missing and then created ApplicationId appId = new ApplicationId("n1", "a1"); final ProgramId programId = appId.service("testCreateOfConfig"); try (final RouteStore writeRouteStore = new ZKRouteStore(zkClientService)) { try (final RouteStore readRouteStore = new ZKRouteStore(zkClientService)) { // First it should be no route Assert.assertTrue(readRouteStore.fetch(programId).getRoutes().isEmpty()); // Write a new route config writeRouteStore.store(programId, new RouteConfig(TEST_ROUTE_CONFIG)); // Fetch it again and it should has the changes Tasks.waitFor(TEST_ROUTE_CONFIG, new Callable<Map<String, Integer>>() { @Override public Map<String, Integer> call() throws Exception { return readRouteStore.fetch(programId).getRoutes(); } }, 5L, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } } }
@Test public void testChangeConfig() throws Exception { ApplicationId appId = new ApplicationId("n1", "a1"); final ProgramId s1 = appId.service("testChangeConfig"); // Create two RouteStore, one for writing, one for reading try (RouteStore writingRouteStore = new ZKRouteStore(zkClientService)) { try (final RouteStore readingRouteStore = new ZKRouteStore(zkClientService)) { writingRouteStore.store(s1, new RouteConfig(TEST_ROUTE_CONFIG)); Assert.assertEquals(TEST_ROUTE_CONFIG, readingRouteStore.fetch(s1).getRoutes()); writingRouteStore.store(s1, new RouteConfig(TEST_ROUTE_CONFIG2)); Tasks.waitFor(TEST_ROUTE_CONFIG2, new Callable<Map<String, Integer>>() { @Override public Map<String, Integer> call() throws Exception { return readingRouteStore.fetch(s1).getRoutes(); } }, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } } } }
@Test public void testAbsenceOfConfig() throws Exception { ApplicationId appId = new ApplicationId("n1", "a1"); final ProgramId programId = appId.service("testAbsenceOfConfig"); try (final RouteStore routeStore = new ZKRouteStore(zkClientService)) { Assert.assertNotNull(routeStore.fetch(programId)); Assert.assertTrue(routeStore.fetch(programId).getRoutes().isEmpty()); routeStore.store(programId, new RouteConfig(TEST_ROUTE_CONFIG)); Tasks.waitFor(false, new Callable<Boolean>() { @Override public Boolean call() throws Exception { return routeStore.fetch(programId).getRoutes().isEmpty(); } }, 5, TimeUnit.SECONDS); Assert.assertEquals(TEST_ROUTE_CONFIG, routeStore.fetch(programId).getRoutes()); } }
@Test public void testStore() throws Exception { ApplicationId appId = new ApplicationId("n1", "a1"); final ProgramId s1 = appId.service("testStore"); try (final RouteStore routeStore = new ZKRouteStore(zkClientService)) { routeStore.store(s1, new RouteConfig(TEST_ROUTE_CONFIG)); Assert.assertEquals(TEST_ROUTE_CONFIG, routeStore.fetch(s1).getRoutes()); routeStore.delete(s1); Tasks.waitFor(true, new Callable<Boolean>() { @Override public Boolean call() throws Exception { return routeStore.fetch(s1).getRoutes().isEmpty(); } }, 5L, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } }