Search in sources :

Example 1 with ServiceMessage

use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.

the class StreamingServiceTest method test_snapshot_completes.

@Test
public void test_snapshot_completes() {
    int batchSize = 1000;
    ServiceCall serviceCall = gateway.call();
    ServiceMessage message = ServiceMessage.builder().qualifier(QuoteService.NAME, "snapshot").data(batchSize).build();
    List<ServiceMessage> serviceMessages = serviceCall.requestMany(message).timeout(Duration.ofSeconds(5)).collectList().block();
    assertEquals(batchSize, serviceMessages.size());
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) Test(org.junit.jupiter.api.Test)

Example 2 with ServiceMessage

use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.

the class StreamingServiceTest method test_unknown_method.

@Test
public void test_unknown_method() {
    ServiceCall service = gateway.call();
    ServiceMessage scheduled = ServiceMessage.builder().qualifier(QuoteService.NAME, "unknonwn").build();
    try {
        service.requestMany(scheduled).blockFirst(Duration.ofSeconds(3));
        fail("Expected no-reachable-service-exception");
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("No reachable member with such service"));
    }
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) Test(org.junit.jupiter.api.Test)

Example 3 with ServiceMessage

use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.

the class StreamingServiceTest method test_call_quotes_snapshot.

@Test
public void test_call_quotes_snapshot() {
    int batchSize = 1000;
    ServiceCall serviceCall = gateway.call();
    ServiceMessage message = ServiceMessage.builder().qualifier(QuoteService.NAME, "snapshot").data(batchSize).build();
    List<ServiceMessage> serviceMessages = serviceCall.requestMany(message).take(Duration.ofSeconds(5)).collectList().block();
    assertEquals(batchSize, serviceMessages.size());
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) Test(org.junit.jupiter.api.Test)

Example 4 with ServiceMessage

use of io.scalecube.services.api.ServiceMessage 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 5 with ServiceMessage

use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.

the class ServiceCallLocalTest method test_local_async_no_params.

@Test
public void test_local_async_no_params() {
    ServiceCall serviceCall = provider.call().router(RoundRobinServiceRouter.class);
    // call the service.
    Publisher<ServiceMessage> future = serviceCall.requestOne(GREETING_NO_PARAMS_REQUEST);
    ServiceMessage message = Mono.from(future).block(Duration.ofSeconds(TIMEOUT));
    assertEquals(GREETING_NO_PARAMS_REQUEST.qualifier(), message.qualifier(), "Didn't get desired response");
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceMessage (io.scalecube.services.api.ServiceMessage)37 Test (org.junit.jupiter.api.Test)31 GreetingResponse (io.scalecube.services.sut.GreetingResponse)12 Mono (reactor.core.publisher.Mono)12 Map (java.util.Map)10 Flux (reactor.core.publisher.Flux)10 StepVerifier (reactor.test.StepVerifier)10 Authenticator (io.scalecube.services.auth.Authenticator)9 GreetingRequest (io.scalecube.services.sut.GreetingRequest)9 Method (java.lang.reflect.Method)9 Collections (java.util.Collections)9 DisplayName (org.junit.jupiter.api.DisplayName)9 CommunicationMode (io.scalecube.services.CommunicationMode)8 AUTH_CONTEXT_KEY (io.scalecube.services.auth.Authenticator.AUTH_CONTEXT_KEY)8 PrincipalMapper (io.scalecube.services.auth.PrincipalMapper)8 DefaultErrorMapper (io.scalecube.services.exceptions.DefaultErrorMapper)8 GreetingService (io.scalecube.services.sut.GreetingService)8 ServiceMessageDataDecoder (io.scalecube.services.transport.api.ServiceMessageDataDecoder)8 Assertions (org.junit.jupiter.api.Assertions)8 ArgumentMatchers (org.mockito.ArgumentMatchers)8