Search in sources :

Example 1 with Message

use of io.scalecube.transport.Message in project scalecube by scalecube.

the class ServiceCallTest method test_async_greeting_return_string_service_not_found_error_case.

@Test
public void test_async_greeting_return_string_service_not_found_error_case() throws InterruptedException, ExecutionException {
    Microservices gateway = createSeed();
    // Create microservices instance cluster.
    Microservices provider1 = createProvider(gateway);
    ServiceCall service = provider1.dispatcher().create();
    CountDownLatch timeLatch = new CountDownLatch(1);
    try {
        // call the service.
        CompletableFuture<Message> future = service.invoke(Messages.builder().request(SERVICE_NAME, "unknown").data(Message.builder().data("joe").build()).build());
    } catch (Exception ex) {
        assertTrue(ex.getMessage().equals("No reachable member with such service: unknown"));
        timeLatch.countDown();
    }
    await(timeLatch, 1, TimeUnit.SECONDS);
    gateway.shutdown().get();
    provider1.shutdown().get();
}
Also used : Message(io.scalecube.transport.Message) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 2 with Message

use of io.scalecube.transport.Message in project scalecube by scalecube.

the class ServiceCallTest method test_remote_async_greeting_return_GreetingResponse.

@Test
public void test_remote_async_greeting_return_GreetingResponse() throws InterruptedException, ExecutionException {
    // Create microservices cluster.
    Microservices provider = Microservices.builder().port(port.incrementAndGet()).services(new GreetingServiceImpl()).build();
    // Create microservices cluster.
    Microservices consumer = Microservices.builder().port(port.incrementAndGet()).seeds(provider.cluster().address()).build();
    ServiceCall service = consumer.dispatcher().create();
    // call the service.
    CompletableFuture<Message> future = service.invoke(Messages.builder().request(SERVICE_NAME, "greetingRequest").data(new GreetingRequest("joe")).build());
    CountDownLatch timeLatch = new CountDownLatch(1);
    future.whenComplete((result, ex) -> {
        if (ex == null) {
            // print the greeting.
            System.out.println("test_remote_async_greeting_return_GreetingResponse :" + result);
            GreetingResponse data = result.data();
            assertTrue(data.getResult().equals(" hello to: joe"));
        } else {
            // print the greeting.
            System.out.println(ex);
        }
        timeLatch.countDown();
    });
    await(timeLatch, 1, TimeUnit.SECONDS);
    provider.shutdown().get();
    consumer.shutdown().get();
}
Also used : Message(io.scalecube.transport.Message) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 3 with Message

use of io.scalecube.transport.Message in project scalecube by scalecube.

the class ServiceCallTest method test_local_async_no_params.

@Test
public void test_local_async_no_params() throws InterruptedException, ExecutionException {
    // Create microservices cluster.
    Microservices microservices = Microservices.builder().port(port.incrementAndGet()).services(new GreetingServiceImpl()).build();
    ServiceCall service = microservices.dispatcher().create();
    // call the service.
    CompletableFuture<Message> future = service.invoke(Messages.builder().request(SERVICE_NAME, "greetingNoParams").build());
    CountDownLatch timeLatch = new CountDownLatch(1);
    future.whenComplete((message, ex) -> {
        if (ex == null) {
            System.out.println(message);
            String result = message.data();
            assertTrue(result.equals("hello unknown"));
            // print the greeting.
            System.out.println("test_local_async_no_params :" + result);
        } else {
            // print the greeting.
            System.out.println(ex);
        }
        timeLatch.countDown();
    });
    await(timeLatch, 1, TimeUnit.SECONDS);
    microservices.shutdown().get();
}
Also used : Message(io.scalecube.transport.Message) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 4 with Message

use of io.scalecube.transport.Message in project scalecube by scalecube.

the class ServiceCallTest method test_local_async_greeting_return_GreetingResponse.

@Test
public void test_local_async_greeting_return_GreetingResponse() throws InterruptedException, ExecutionException {
    // Create microservices cluster.
    Microservices microservices = Microservices.builder().port(port.incrementAndGet()).services(new GreetingServiceImpl()).build();
    ServiceCall service = microservices.dispatcher().create();
    // call the service.
    CompletableFuture<Message> future = service.invoke(Messages.builder().request(SERVICE_NAME, "greetingRequest").data(new GreetingRequest("joe")).build());
    CountDownLatch timeLatch = new CountDownLatch(1);
    future.whenComplete((result, ex) -> {
        if (ex == null) {
            // print the greeting.
            System.out.println("test_local_async_greeting_return_GreetingResponse :" + result);
            GreetingResponse data = result.data();
            assertTrue(data.getResult().equals(" hello to: joe"));
        } else {
            // print the greeting.
            System.out.println(ex);
        }
        timeLatch.countDown();
    });
    await(timeLatch, 3, TimeUnit.SECONDS);
    microservices.shutdown().get();
}
Also used : Message(io.scalecube.transport.Message) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 5 with Message

use of io.scalecube.transport.Message in project scalecube by scalecube.

the class ServiceCallTest method test_remote_async_greeting_return_Message.

@Test
public void test_remote_async_greeting_return_Message() throws InterruptedException, ExecutionException {
    // Create microservices cluster.
    Microservices provider = Microservices.builder().port(port.incrementAndGet()).services(new GreetingServiceImpl()).build();
    // Create microservices cluster.
    Microservices consumer = Microservices.builder().port(port.incrementAndGet()).seeds(provider.cluster().address()).build();
    ServiceCall service = consumer.dispatcher().create();
    // call the service.
    CompletableFuture<Message> future = service.invoke(Messages.builder().request(SERVICE_NAME, "greetingMessage").data(Message.builder().data("joe").build()).build());
    CountDownLatch timeLatch = new CountDownLatch(1);
    future.whenComplete((result, ex) -> {
        if (ex == null) {
            // print the greeting.
            System.out.println("10. remote_async_greeting_return_Message :" + result.data());
            // print the greeting.
            assertTrue(result.data().equals(" hello to: joe"));
        } else {
            // print the greeting.
            System.out.println("10 failed: " + ex);
            assertTrue(result.data().equals(" hello to: joe"));
        }
        timeLatch.countDown();
    });
    await(timeLatch, 20, TimeUnit.SECONDS);
    consumer.shutdown().get();
    provider.shutdown().get();
}
Also used : Message(io.scalecube.transport.Message) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Aggregations

Message (io.scalecube.transport.Message)51 BaseTest (io.scalecube.testlib.BaseTest)31 Test (org.junit.Test)31 CountDownLatch (java.util.concurrent.CountDownLatch)28 Observable (rx.Observable)10 Member (io.scalecube.cluster.Member)8 Microservices (io.scalecube.services.Microservices)6 TimeUnit (java.util.concurrent.TimeUnit)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 ServiceCall (io.scalecube.services.ServiceCall)5 Collections (java.util.Collections)5 Executors (java.util.concurrent.Executors)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 Schedulers (rx.schedulers.Schedulers)5 List (java.util.List)4 Subscription (rx.Subscription)4 PublishSubject (rx.subjects.PublishSubject)4 Subject (rx.subjects.Subject)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3