Search in sources :

Example 1 with GreetingRequest

use of io.scalecube.services.sut.GreetingRequest in project scalecube by scalecube.

the class RoutersTest method test_service_tags.

@Test
public void test_service_tags() throws Exception {
    TimeUnit.SECONDS.sleep(3);
    ServiceCall service = gateway.call().router(WeightedRandomRouter.class);
    ServiceMessage req = ServiceMessage.builder().qualifier(Reflect.serviceName(CanaryService.class), "greeting").data(new GreetingRequest("joe")).build();
    AtomicInteger serviceBCount = new AtomicInteger(0);
    int n = (int) 1e3;
    for (int i = 0; i < n; i++) {
        ServiceMessage message = service.requestOne(req, GreetingResponse.class).block(TIMEOUT);
        if (message.data().toString().contains("SERVICE_B_TALKING")) {
            serviceBCount.incrementAndGet();
        }
    }
    System.out.println("Service B was called: " + serviceBCount.get() + " times out of " + n);
    assertTrue((serviceBCount.doubleValue() / n) > 0.5, "Service B's Weight=0.9; at least more than half " + "of invocations have to be routed to Service B");
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) ServiceCall(io.scalecube.services.ServiceCall) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GreetingRequest(io.scalecube.services.sut.GreetingRequest) CanaryService(io.scalecube.services.routings.sut.CanaryService) GreetingResponse(io.scalecube.services.sut.GreetingResponse) Test(org.junit.jupiter.api.Test) BaseTest(io.scalecube.services.BaseTest)

Example 2 with GreetingRequest

use of io.scalecube.services.sut.GreetingRequest in project scalecube by scalecube.

the class RoutersTest method test_remote_service_tags.

@Test
public void test_remote_service_tags() throws Exception {
    CanaryService service = gateway.call().router(Routers.getRouter(WeightedRandomRouter.class)).api(CanaryService.class);
    Thread.sleep(1000);
    AtomicInteger serviceBCount = new AtomicInteger(0);
    int n = (int) 1e3;
    Flux.range(0, n).flatMap(i -> service.greeting(new GreetingRequest("joe"))).filter(response -> response.getResult().contains("SERVICE_B_TALKING")).doOnNext(response -> serviceBCount.incrementAndGet()).blockLast(Duration.ofSeconds(3));
    System.out.println("Service B was called: " + serviceBCount.get() + " times out of " + n);
    assertTrue((serviceBCount.doubleValue() / n) > 0.5, "Service B's Weight=0.9; more than half of invocations have to be routed to Service B");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) GreetingServiceImplB(io.scalecube.services.routings.sut.GreetingServiceImplB) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) GreetingServiceImplA(io.scalecube.services.routings.sut.GreetingServiceImplA) DummyRouter(io.scalecube.services.routings.sut.DummyRouter) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) GreetingResponse(io.scalecube.services.sut.GreetingResponse) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) RandomServiceRouter(io.scalecube.services.routing.RandomServiceRouter) GREETING_REQUEST_REQ2(io.scalecube.services.TestRequests.GREETING_REQUEST_REQ2) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) ServiceCall(io.scalecube.services.ServiceCall) Duration(java.time.Duration) Map(java.util.Map) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) GreetingRequest(io.scalecube.services.sut.GreetingRequest) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Address(io.scalecube.net.Address) ServiceReference(io.scalecube.services.ServiceReference) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) CanaryService(io.scalecube.services.routings.sut.CanaryService) ServiceInfo(io.scalecube.services.ServiceInfo) Mono(reactor.core.publisher.Mono) TagService(io.scalecube.services.routings.sut.TagService) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Routers(io.scalecube.services.routing.Routers) Flux(reactor.core.publisher.Flux) Microservices(io.scalecube.services.Microservices) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Reflect(io.scalecube.services.Reflect) GREETING_REQUEST_REQ(io.scalecube.services.TestRequests.GREETING_REQUEST_REQ) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) Optional(java.util.Optional) ServiceMessage(io.scalecube.services.api.ServiceMessage) BaseTest(io.scalecube.services.BaseTest) WeightedRandomRouter(io.scalecube.services.routings.sut.WeightedRandomRouter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GreetingRequest(io.scalecube.services.sut.GreetingRequest) CanaryService(io.scalecube.services.routings.sut.CanaryService) Test(org.junit.jupiter.api.Test) BaseTest(io.scalecube.services.BaseTest)

Example 3 with GreetingRequest

use of io.scalecube.services.sut.GreetingRequest in project scalecube by scalecube.

the class ServiceLocalTest method test_local_async_greeting_return_Message.

@Test
public void test_local_async_greeting_return_Message() {
    // get a proxy to the service api.
    GreetingService service = createProxy(microservices);
    // call the service.
    Mono<GreetingResponse> future = Mono.from(service.greetingRequest(new GreetingRequest("joe")));
    future.doOnNext(result -> {
        assertEquals(" hello to: joe", result.getResult());
        // print the greeting.
        System.out.println("9. local_async_greeting_return_Message :" + result);
    }).doOnError(System.out::println).block(Duration.ofSeconds(1));
}
Also used : GreetingRequest(io.scalecube.services.sut.GreetingRequest) GreetingResponse(io.scalecube.services.sut.GreetingResponse) GreetingService(io.scalecube.services.sut.GreetingService) Test(org.junit.jupiter.api.Test)

Example 4 with GreetingRequest

use of io.scalecube.services.sut.GreetingRequest in project scalecube by scalecube.

the class ServiceLocalTest method test_local_bidi_greeting_expect_IllegalArgumentException.

@Test
public void test_local_bidi_greeting_expect_IllegalArgumentException() {
    // get a proxy to the service api.
    GreetingService service = createProxy(microservices);
    // call the service. bidiThrowingGreeting
    Flux<GreetingResponse> responses = service.bidiGreetingIllegalArgumentException(Mono.just(new GreetingRequest("IllegalArgumentException")));
    // call the service.
    StepVerifier.create(responses).expectErrorMessage("IllegalArgumentException").verify(Duration.ofSeconds(3));
}
Also used : GreetingRequest(io.scalecube.services.sut.GreetingRequest) GreetingResponse(io.scalecube.services.sut.GreetingResponse) GreetingService(io.scalecube.services.sut.GreetingService) Test(org.junit.jupiter.api.Test)

Example 5 with GreetingRequest

use of io.scalecube.services.sut.GreetingRequest in project scalecube by scalecube.

the class ServiceLocalTest method test_local_greeting_request_timeout_expires.

@Test
public void test_local_greeting_request_timeout_expires() {
    GreetingService service = createProxy(microservices);
    // call the service.
    Throwable exception = assertThrows(RuntimeException.class, () -> Mono.from(service.greetingRequestTimeout(new GreetingRequest("joe", timeout))).timeout(Duration.ofSeconds(1)).block());
    assertTrue(exception.getCause().getMessage().contains("Did not observe any item or terminal signal"));
}
Also used : GreetingRequest(io.scalecube.services.sut.GreetingRequest) GreetingService(io.scalecube.services.sut.GreetingService) Test(org.junit.jupiter.api.Test)

Aggregations

GreetingRequest (io.scalecube.services.sut.GreetingRequest)36 Test (org.junit.jupiter.api.Test)35 GreetingService (io.scalecube.services.sut.GreetingService)32 GreetingResponse (io.scalecube.services.sut.GreetingResponse)26 EmptyGreetingRequest (io.scalecube.services.sut.EmptyGreetingRequest)16 ServiceMessage (io.scalecube.services.api.ServiceMessage)15 EmptyGreetingResponse (io.scalecube.services.sut.EmptyGreetingResponse)13 Duration (java.time.Duration)9 Mono (reactor.core.publisher.Mono)9 Sinks (reactor.core.publisher.Sinks)9 GreetingServiceImpl (io.scalecube.services.sut.GreetingServiceImpl)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)8 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)8 StepVerifier (reactor.test.StepVerifier)7 ScalecubeServiceDiscovery (io.scalecube.services.discovery.ScalecubeServiceDiscovery)6 RSocketServiceTransport (io.scalecube.services.transport.rsocket.RSocketServiceTransport)6 WebsocketTransportFactory (io.scalecube.transport.netty.websocket.WebsocketTransportFactory)6 Flux (reactor.core.publisher.Flux)6 AfterAll (org.junit.jupiter.api.AfterAll)5