private KubernetesResource getUpdatedHttpService() { Service service = getHttpService(); service.getMetadata().getLabels().put("foo", "bar"); return service; }
private Service getUpdatedService96() { return getService96(); } }
@Before public void setUp(TestContext tc) throws MalformedURLException { vertx = Vertx.vertx(); vertx.exceptionHandler(tc.exceptionHandler()); Service svc1 = getSimpleService(); Service svc2 = getHttpService(); Service svc3 = getSimpleService(); svc3.getMetadata().setName("service3"); svc3.getMetadata().setUid("uid-3"); server = getServer(); server.expect().get().withPath("/api/v1/namespaces/default/services").andReturn(200, new ServiceListBuilder() .addToItems(svc1, svc2).withNewMetadata("1234", "/self").build()).always(); server.expect().get().withPath("/api/v1/namespaces/default/services?watch=true&resourceVersion=1234") .andReturnChunked(200, new WatchEvent(svc3, "ADDED"), "\n", new WatchEvent(svc1, "DELETED"), "\n", new WatchEvent(getUpdatedHttpService(), "MODIFIED"), "\n").once(); Service svc96 = getService96(); server.expect().get().withPath("/api/v1/namespaces/issue96/services").andReturn(200, new ServiceListBuilder() .addToItems(svc96) .withNewMetadata("1235", "/self").build()).always(); server.expect().get().withPath("/api/v1/namespaces/issue96/services?watch=true&resourceVersion=1235") .andReturnChunked(200, new WatchEvent(getUpdatedService96(), "MODIFIED"), "\n", new WatchEvent(getUpdatedService96(), "DELETED"), "\n").once(); server.init(); client = server.createClient(); port = new URL(client.getConfiguration().getMasterUrl()).getPort(); }
@Test public void testWatch() { AtomicBoolean done = new AtomicBoolean(); ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setAutoRegistrationOfImporters(false)); discovery.registerServiceImporter(new KubernetesServiceImporter(), config().copy().put("namespace", "default"), ar -> done.set(ar.succeeded())); await().untilAtomic(done, is(true)); await().until(() -> { List<Record> records = getRecordsBlocking(discovery); try { assertThatListContains(records, "service3"); assertThatListDoesNotContain(records, "my-service"); assertThatListContains(records, "my-http-service"); return true; } catch (Throwable e) { return false; } }); }
/** * Reproduce issue https://github.com/vert-x3/vertx-service-discovery/issues/96. */ @Test public void testWatchWithDeletion() { AtomicBoolean done = new AtomicBoolean(); ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setAutoRegistrationOfImporters(false)); discovery.registerServiceImporter(new KubernetesServiceImporter(), config().copy().put("namespace", "issue96"), ar -> done.set(ar.succeeded())); await().untilAtomic(done, is(true)); await().until(() -> { List<Record> records = getRecordsBlocking(discovery); try { assertThatListDoesNotContain(records, "hello-minikube"); return true; } catch (Throwable e) { return false; } }); }
@Test public void testInitialRetrieval(TestContext tc) { Async async = tc.async(); ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setAutoRegistrationOfImporters(false)); discovery.registerServiceImporter(new KubernetesServiceImporter(), config().copy().put("namespace", "default"), ar -> { if (ar.failed()) { tc.fail(ar.cause()); } else { discovery.getRecords(s -> true, res -> { if (res.failed()) { tc.fail(res.cause()); } else { tc.assertEquals(2, res.result().size()); async.complete(); } }); } }); }
@Before public void setUp(TestContext tc) throws MalformedURLException { vertx = Vertx.vertx(); vertx.exceptionHandler(tc.exceptionHandler()); Service svc1 = getSimpleService(); Service svc2 = getHttpService(); Service svc3 = getSimpleService(); svc3.getMetadata().setName("service3"); svc3.getMetadata().setUid("uid-3"); server = getServer(); server.expect().get().withPath("/api/v1/namespaces/default/services").andReturn(200, new ServiceListBuilder() .addToItems(svc1, svc2).withNewMetadata("1234", "/self").build()).always(); server.expect().get().withPath("/api/v1/namespaces/default/services?watch=true&resourceVersion=1234") .andReturnChunked(200, new WatchEvent(svc3, "ADDED"), "\n", new WatchEvent(svc1, "DELETED"), "\n", new WatchEvent(getUpdatedHttpService(), "MODIFIED"), "\n").once(); Service svc96 = getService96(); server.expect().get().withPath("/api/v1/namespaces/issue96/services").andReturn(200, new ServiceListBuilder() .addToItems(svc96) .withNewMetadata("1235", "/self").build()).always(); server.expect().get().withPath("/api/v1/namespaces/issue96/services?watch=true&resourceVersion=1235") .andReturnChunked(200, new WatchEvent(getUpdatedService96(), "MODIFIED"), "\n", new WatchEvent(getUpdatedService96(), "DELETED"), "\n").once(); server.init(); client = server.createClient(); port = new URL(client.getConfiguration().getMasterUrl()).getPort(); }
@Test public void testWatch() { AtomicBoolean done = new AtomicBoolean(); ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setAutoRegistrationOfImporters(false)); discovery.registerServiceImporter(new KubernetesServiceImporter(), config().copy().put("namespace", "default"), ar -> done.set(ar.succeeded())); await().untilAtomic(done, is(true)); await().until(() -> { List<Record> records = getRecordsBlocking(discovery); try { assertThatListContains(records, "service3"); assertThatListDoesNotContain(records, "my-service"); assertThatListContains(records, "my-http-service"); return true; } catch (Throwable e) { return false; } }); }
/** * Reproduce issue https://github.com/vert-x3/vertx-service-discovery/issues/96. */ @Test public void testWatchWithDeletion() { AtomicBoolean done = new AtomicBoolean(); ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setAutoRegistrationOfImporters(false)); discovery.registerServiceImporter(new KubernetesServiceImporter(), config().copy().put("namespace", "issue96"), ar -> done.set(ar.succeeded())); await().untilAtomic(done, is(true)); await().until(() -> { List<Record> records = getRecordsBlocking(discovery); try { assertThatListDoesNotContain(records, "hello-minikube"); return true; } catch (Throwable e) { return false; } }); }
@Test public void testInitialRetrieval(TestContext tc) { Async async = tc.async(); ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setAutoRegistrationOfImporters(false)); discovery.registerServiceImporter(new KubernetesServiceImporter(), config().copy().put("namespace", "default"), ar -> { if (ar.failed()) { tc.fail(ar.cause()); } else { discovery.getRecords(s -> true, res -> { if (res.failed()) { tc.fail(res.cause()); } else { tc.assertEquals(2, res.result().size()); async.complete(); } }); } }); }
private KubernetesResource getUpdatedHttpService() { Service service = getHttpService(); service.getMetadata().getLabels().put("foo", "bar"); return service; }
private Service getUpdatedService96() { return getService96(); } }