Search in sources :

Example 1 with ServiceDiscovery

use of io.vertx.rxjava.servicediscovery.ServiceDiscovery in project georocket by georocket.

the class ServiceTest method broadcast.

/**
 * Test if a message can be sent to all consumers
 * @param context the test context
 */
@Test
public void broadcast(TestContext context) {
    Vertx vertx = new Vertx(rule.vertx());
    Async aC = context.async();
    Async bC = context.async();
    Async cC = context.async();
    Async dC = context.async();
    String data = "special data";
    vertx.eventBus().consumer("a", h -> {
        context.assertEquals(data, h.body());
        aC.complete();
    });
    vertx.eventBus().consumer("a", h -> {
        context.assertEquals(data, h.body());
        bC.complete();
    });
    vertx.eventBus().consumer("b", h -> {
        context.assertEquals(data, h.body());
        cC.complete();
    });
    vertx.eventBus().consumer("b", h -> {
        context.assertEquals(data, h.body());
        dC.complete();
    });
    ServiceDiscovery discovery = ServiceDiscovery.create(vertx);
    Service.publishOnce("A", "a", discovery, vertx).flatMap(v -> Service.publishOnce("A", "b", discovery, vertx)).flatMapObservable(v -> Service.discover("A", discovery, vertx)).doOnTerminate(discovery::close).subscribe(service -> {
        service.broadcast(data);
    }, context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) List(java.util.List) Rule(org.junit.Rule) RunWith(org.junit.runner.RunWith) ServiceDiscovery(io.vertx.rxjava.servicediscovery.ServiceDiscovery) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Record(io.vertx.servicediscovery.Record) Collectors(java.util.stream.Collectors) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Vertx(io.vertx.rxjava.core.Vertx) Async(io.vertx.ext.unit.Async) Vertx(io.vertx.rxjava.core.Vertx) ServiceDiscovery(io.vertx.rxjava.servicediscovery.ServiceDiscovery) Test(org.junit.Test)

Example 2 with ServiceDiscovery

use of io.vertx.rxjava.servicediscovery.ServiceDiscovery in project georocket by georocket.

the class ServiceTest method publishOnce.

/**
 * Test if a service is really published only once
 * @param context the test context
 */
@Test
public void publishOnce(TestContext context) {
    Vertx vertx = new Vertx(rule.vertx());
    Async async = context.async();
    ServiceDiscovery discovery = ServiceDiscovery.create(vertx);
    Service.publishOnce("A", "A", discovery, vertx).flatMap(v -> Service.publishOnce("A", "A", discovery, vertx)).flatMap(v -> Service.publishOnce("A", "B", discovery, vertx)).flatMap(v -> {
        return discovery.rxGetRecords(record -> true);
    }).doAfterTerminate(discovery::close).subscribe(recordList -> {
        List<Record> lA = recordList.stream().filter(r -> r.getName().equals("A")).collect(Collectors.toList());
        context.assertEquals(2, lA.size());
        async.complete();
    }, context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) List(java.util.List) Rule(org.junit.Rule) RunWith(org.junit.runner.RunWith) ServiceDiscovery(io.vertx.rxjava.servicediscovery.ServiceDiscovery) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Record(io.vertx.servicediscovery.Record) Collectors(java.util.stream.Collectors) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Vertx(io.vertx.rxjava.core.Vertx) Async(io.vertx.ext.unit.Async) Record(io.vertx.servicediscovery.Record) Vertx(io.vertx.rxjava.core.Vertx) ServiceDiscovery(io.vertx.rxjava.servicediscovery.ServiceDiscovery) Test(org.junit.Test)

Example 3 with ServiceDiscovery

use of io.vertx.rxjava.servicediscovery.ServiceDiscovery in project georocket by georocket.

the class ServiceTest method discover.

/**
 * Test if a service can be discovered
 * @param context the test context
 */
@Test
public void discover(TestContext context) {
    Vertx vertx = new Vertx(rule.vertx());
    Async async = context.async();
    ServiceDiscovery discovery = ServiceDiscovery.create(vertx);
    Service.publishOnce("A", "a", discovery, vertx).flatMap(v -> Service.publishOnce("A", "b", discovery, vertx)).flatMapObservable(v -> Service.discover("A", discovery, vertx)).count().doOnTerminate(discovery::close).subscribe(count -> {
        context.assertEquals(2, count);
        async.complete();
    }, context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) List(java.util.List) Rule(org.junit.Rule) RunWith(org.junit.runner.RunWith) ServiceDiscovery(io.vertx.rxjava.servicediscovery.ServiceDiscovery) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Record(io.vertx.servicediscovery.Record) Collectors(java.util.stream.Collectors) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Vertx(io.vertx.rxjava.core.Vertx) Async(io.vertx.ext.unit.Async) Vertx(io.vertx.rxjava.core.Vertx) ServiceDiscovery(io.vertx.rxjava.servicediscovery.ServiceDiscovery) Test(org.junit.Test)

Example 4 with ServiceDiscovery

use of io.vertx.rxjava.servicediscovery.ServiceDiscovery in project georocket by georocket.

the class ServiceTest method send.

/**
 * Test if a message can be sent and if a consumer receives the message.
 * This method does not test if the message can be sent to only one
 * consumer (instead of all, see {@link #broadcast(TestContext)}),
 * because it's not possible to check if a consumer will not receive a
 * message before the asynchronous test ends.
 * @param context the test context
 */
@Test
public void send(TestContext context) {
    Vertx vertx = new Vertx(rule.vertx());
    Async a = context.async();
    String data = "special data";
    vertx.eventBus().consumer("a", h -> {
        context.assertEquals(data, h.body());
        a.complete();
    });
    ServiceDiscovery discovery = ServiceDiscovery.create(vertx);
    Service.publishOnce("A", "a", discovery, vertx).flatMapObservable(v -> Service.discover("A", discovery, vertx)).doOnTerminate(discovery::close).subscribe(service -> {
        service.broadcast(data);
        service.send(data);
    }, context::fail);
}
Also used : Async(io.vertx.ext.unit.Async) Vertx(io.vertx.rxjava.core.Vertx) ServiceDiscovery(io.vertx.rxjava.servicediscovery.ServiceDiscovery) Test(org.junit.Test)

Example 5 with ServiceDiscovery

use of io.vertx.rxjava.servicediscovery.ServiceDiscovery in project georocket by georocket.

the class ServiceTest method unpublish.

/**
 * Test if a service can be published an unpublished again
 * @param context the test context
 */
@Test
public void unpublish(TestContext context) {
    Vertx vertx = new Vertx(rule.vertx());
    Async async = context.async();
    ServiceDiscovery discovery = ServiceDiscovery.create(vertx);
    Service.publishOnce("A", "a", discovery, vertx).flatMapObservable(v -> Service.discover("A", discovery, vertx)).count().doOnNext(count -> {
        context.assertEquals(1, count);
    }).flatMap(v -> Service.discover("A", discovery, vertx)).flatMapSingle(service -> service.unpublish(discovery)).flatMap(v -> Service.discover("A", discovery, vertx)).count().doOnTerminate(discovery::close).subscribe(count -> {
        context.assertEquals(0, count);
        async.complete();
    }, context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) List(java.util.List) Rule(org.junit.Rule) RunWith(org.junit.runner.RunWith) ServiceDiscovery(io.vertx.rxjava.servicediscovery.ServiceDiscovery) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Record(io.vertx.servicediscovery.Record) Collectors(java.util.stream.Collectors) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Vertx(io.vertx.rxjava.core.Vertx) Async(io.vertx.ext.unit.Async) Vertx(io.vertx.rxjava.core.Vertx) ServiceDiscovery(io.vertx.rxjava.servicediscovery.ServiceDiscovery) Test(org.junit.Test)

Aggregations

Async (io.vertx.ext.unit.Async)5 Vertx (io.vertx.rxjava.core.Vertx)5 ServiceDiscovery (io.vertx.rxjava.servicediscovery.ServiceDiscovery)5 Test (org.junit.Test)5 TestContext (io.vertx.ext.unit.TestContext)4 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)4 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)4 Record (io.vertx.servicediscovery.Record)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Rule (org.junit.Rule)4 RunWith (org.junit.runner.RunWith)4