reference.release();
/** * Releases the reference. Once released, the consumer must not use the reference anymore. * This method must be idempotent and defensive, as multiple call may happen. */ public void release() { delegate.release(); }
/** * Releases the reference. Once released, the consumer must not use the reference anymore. * This method must be idempotent and defensive, as multiple call may happen. */ public void release() { delegate.release(); }
@Override public boolean release(ServiceReference reference) { boolean removed = bindings.remove(reference); reference.release(); sendUnbindEvent(reference); return removed; }
@Override public boolean release(ServiceReference reference) { boolean removed = bindings.remove(reference); reference.release(); sendUnbindEvent(reference); return removed; }
@Test public void test() throws InterruptedException { Record record = MongoDataSource.createRecord("some-mongo-db", new JsonObject().put("connection_string", "mongodb://localhost:12345"), new JsonObject().put("database", "some-raw-data")); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "some-mongo-db"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); ServiceReference service = discovery.getReference(found.get()); MongoClient client = service.get(); AtomicBoolean success = new AtomicBoolean(); client.getCollections(ar -> { success.set(ar.succeeded()); }); await().untilAtomic(success, is(true)); service.release(); // Just there to be sure we can call it twice service.release(); }
@Test public void test() throws InterruptedException { JsonObject conf = new JsonObject() .put("driverclass", "org.hsqldb.jdbcDriver"); Record record = JDBCDataSource.createRecord("some-hsql-db", new JsonObject().put("url", "jdbc:hsqldb:file:target/dumb-db;shutdown=true"), new JsonObject().put("database", "some-raw-data")); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "some-hsql-db"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); ServiceReference service = discovery.getReferenceWithConfiguration(found.get(), conf); JDBCClient client = service.get(); AtomicBoolean success = new AtomicBoolean(); client.getConnection(ar -> { if (ar.succeeded()) { ar.result().close(); } success.set(ar.succeeded()); }); await().untilAtomic(success, is(true)); service.release(); // Just there to be sure we can call it twice service.release(); }
@Test public void test() throws InterruptedException { Record record = MongoDataSource.createRecord("some-mongo-db", new JsonObject().put("connection_string", "mongodb://localhost:12345"), new JsonObject().put("database", "some-raw-data")); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "some-mongo-db"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); ServiceReference service = discovery.getReference(found.get()); MongoClient client = service.get(); AtomicBoolean success = new AtomicBoolean(); client.getCollections(ar -> { success.set(ar.succeeded()); }); await().untilAtomic(success, is(true)); service.release(); // Just there to be sure we can call it twice service.release(); }
@Test public void test() throws InterruptedException { JsonObject conf = new JsonObject() .put("driverclass", "org.hsqldb.jdbcDriver"); Record record = JDBCDataSource.createRecord("some-hsql-db", new JsonObject().put("url", "jdbc:hsqldb:file:target/dumb-db;shutdown=true"), new JsonObject().put("database", "some-raw-data")); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "some-hsql-db"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); ServiceReference service = discovery.getReferenceWithConfiguration(found.get(), conf); JDBCClient client = service.get(); AtomicBoolean success = new AtomicBoolean(); client.getConnection(ar -> { if (ar.succeeded()) { ar.result().close(); } success.set(ar.succeeded()); }); await().untilAtomic(success, is(true)); service.release(); // Just there to be sure we can call it twice service.release(); }
@Test public void test() throws InterruptedException { Record record = RedisDataSource.createRecord("some-redis-data-source", new JsonObject().put("url", "localhost"), new JsonObject().put("database", "some-raw-data")); discovery.publish(record, r -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "some-redis-data-source"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); ServiceReference service = discovery.getReference(found.get()); RedisClient client = service.get(); AtomicBoolean success = new AtomicBoolean(); client.ping(ar -> { if (ar.succeeded()) { client.close(ar2 -> success.set(ar2.succeeded())); } }); await().untilAtomic(success, is(true)); service.release(); // Just there to be sure we can call it twice service.release(); }
@Test public void test() throws InterruptedException { Record record = RedisDataSource.createRecord("some-redis-data-source", new JsonObject().put("url", "localhost"), new JsonObject().put("database", "some-raw-data")); discovery.publish(record, r -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "some-redis-data-source"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); ServiceReference service = discovery.getReference(found.get()); RedisClient client = service.get(); AtomicBoolean success = new AtomicBoolean(); client.ping(ar -> { if (ar.succeeded()) { client.close(ar2 -> success.set(ar2.succeeded())); } }); await().untilAtomic(success, is(true)); service.release(); // Just there to be sure we can call it twice service.release(); }
@Test public void test() { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = EventBusService.createRecord("Hello", "address", HelloService.class); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "Hello"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); assertThat(found.get().getLocation().getString("endpoint")).isEqualTo("address"); ServiceReference service = discovery.getReference(found.get()); HelloService hello = service.get(); AtomicReference<String> result = new AtomicReference<>(); hello.hello(name, ar -> result.set(ar.result())); await().untilAtomic(result, not(nullValue())); service.release(); }
@Test public void test() { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = EventBusService.createRecord("Hello", "address", HelloService.class); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "Hello"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); assertThat(found.get().getLocation().getString("endpoint")).isEqualTo("address"); ServiceReference service = discovery.getReference(found.get()); HelloService hello = service.get(); AtomicReference<String> result = new AtomicReference<>(); hello.hello(name, ar -> result.set(ar.result())); await().untilAtomic(result, not(nullValue())); service.release(); }
@Test public void testSeveralCallsToRelease() { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = EventBusService.createRecord("Hello", "address", HelloService.class); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "Hello"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); ServiceReference service = discovery.getReference(found.get()); HelloService hello = service.get(); AtomicReference<String> result = new AtomicReference<>(); hello.hello(name, ar -> result.set(ar.result())); await().untilAtomic(result, not(nullValue())); service.release(); service.release(); }
@Test public void testSeveralCallsToRelease() { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = EventBusService.createRecord("Hello", "address", HelloService.class); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<Record> found = new AtomicReference<>(); discovery.getRecord(new JsonObject().put("name", "Hello"), ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); ServiceReference service = discovery.getReference(found.get()); HelloService hello = service.get(); AtomicReference<String> result = new AtomicReference<>(); hello.hello(name, ar -> result.set(ar.result())); await().untilAtomic(result, not(nullValue())); service.release(); service.release(); }
context.assertEquals(resp.statusCode(), 200); context.assertEquals(resp.body().toString(), "hello"); reference.release();
context.assertEquals(resp.statusCode(), 200); context.assertEquals(resp.body().toString(), "hello"); reference.release();
@Test public void testPublicationAndConsumption(TestContext context) { Async async = context.async(); // Publish the service Record record = HttpEndpoint.createRecord("hello-service", "localhost", 8080, "/foo"); discovery.publish(record, rec -> { Record published = rec.result(); discovery.getRecord(new JsonObject().put("name", "hello-service"), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); Record match = found.result(); ServiceReference reference = discovery.getReference(match); context.assertEquals(reference.record().getLocation().getString("endpoint"), "http://localhost:8080/foo"); context.assertFalse(reference.record().getLocation().getBoolean("ssl")); HttpClient client = reference.get(); HttpClient client2 = reference.get(); context.assertTrue(client == client2); client.getNow("/foo", response -> { context.assertEquals(response.statusCode(), 200); response.bodyHandler(body -> { context.assertEquals(body.toString(), "hello"); reference.release(); discovery.unpublish(published.getRegistration(), v -> { async.complete(); }); }); }); }); }); }
@Test public void testPublicationAndConsumption(TestContext context) { Async async = context.async(); // Publish the service Record record = HttpEndpoint.createRecord("hello-service", "localhost", 8080, "/foo"); discovery.publish(record, rec -> { Record published = rec.result(); discovery.getRecord(new JsonObject().put("name", "hello-service"), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); Record match = found.result(); ServiceReference reference = discovery.getReference(match); context.assertEquals(reference.record().getLocation().getString("endpoint"), "http://localhost:8080/foo"); context.assertFalse(reference.record().getLocation().getBoolean("ssl")); HttpClient client = reference.get(); HttpClient client2 = reference.get(); context.assertTrue(client == client2); client.getNow("/foo", context.asyncAssertSuccess(response -> { context.assertEquals(response.statusCode(), 200); response.bodyHandler(body -> { context.assertEquals(body.toString(), "hello"); reference.release(); discovery.unpublish(published.getRegistration(), v -> { async.complete(); }); }); })); }); }); }