Search in sources :

Example 21 with ServiceMessage

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

the class StreamingServiceTest method test_just_one_message.

@Test
public void test_just_one_message() {
    ServiceCall service = gateway.call();
    ServiceMessage justOne = ServiceMessage.builder().qualifier(QuoteService.NAME, "justOne").build();
    ServiceMessage message = service.requestOne(justOne, String.class).timeout(Duration.ofSeconds(3)).block();
    assertNotNull(message);
    assertEquals("1", message.<String>data());
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) Test(org.junit.jupiter.api.Test)

Example 22 with ServiceMessage

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

the class ServiceRemoteTest method test_remote_bidi_greeting_message_expect_NotAuthorized.

@Test
public void test_remote_bidi_greeting_message_expect_NotAuthorized() {
    // get a proxy to the service api.
    GreetingService service = createProxy();
    Sinks.Many<GreetingRequest> requests = Sinks.many().multicast().directBestEffort();
    // call the service.
    Flux<GreetingResponse> responses = service.bidiGreetingNotAuthorizedMessage(requests.asFlux().onBackpressureBuffer().map(request -> ServiceMessage.builder().data(request).build())).map(ServiceMessage::data);
    StepVerifier.create(responses).then(() -> requests.emitNext(new GreetingRequest("joe-1"), FAIL_FAST)).expectErrorMessage("Not authorized").verify(Duration.ofSeconds(3));
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) Sinks(reactor.core.publisher.Sinks) GreetingRequest(io.scalecube.services.sut.GreetingRequest) EmptyGreetingRequest(io.scalecube.services.sut.EmptyGreetingRequest) GreetingResponse(io.scalecube.services.sut.GreetingResponse) EmptyGreetingResponse(io.scalecube.services.sut.EmptyGreetingResponse) GreetingService(io.scalecube.services.sut.GreetingService) Test(org.junit.jupiter.api.Test)

Example 23 with ServiceMessage

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

the class ServiceLocalTest method test_local_bidi_greeting_message_expect_IllegalArgumentException.

@Test
public void test_local_bidi_greeting_message_expect_IllegalArgumentException() {
    // get a proxy to the service api.
    GreetingService service = createProxy(microservices);
    // call the service. bidiThrowingGreeting
    Flux<GreetingResponse> responses = service.bidiGreetingIllegalArgumentExceptionMessage(Mono.just(ServiceMessage.builder().data(new GreetingRequest("IllegalArgumentException")).build())).map(ServiceMessage::data);
    // call the service.
    StepVerifier.create(responses).expectErrorMessage("IllegalArgumentException").verify(Duration.ofSeconds(3));
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) 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 24 with ServiceMessage

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

the class ServiceCallRemoteTest method test_remote_dispatcher_remote_greeting_request_completes_before_timeout.

@Test
public void test_remote_dispatcher_remote_greeting_request_completes_before_timeout() {
    Publisher<ServiceMessage> result = gateway.call().requestOne(GREETING_REQUEST_REQ, GreetingResponse.class);
    GreetingResponse greetings = Mono.from(result).block(TIMEOUT).data();
    System.out.println("greeting_request_completes_before_timeout : " + greetings.getResult());
    assertEquals(" hello to: joe", greetings.getResult());
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) GreetingResponse(io.scalecube.services.sut.GreetingResponse) EmptyGreetingResponse(io.scalecube.services.sut.EmptyGreetingResponse) Test(org.junit.jupiter.api.Test)

Example 25 with ServiceMessage

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

the class ServiceCallRemoteTest method test_remote_async_greeting_no_params.

@Test
public void test_remote_async_greeting_no_params() {
    ServiceCall serviceCall = gateway.call();
    // call the service.
    Publisher<ServiceMessage> future = serviceCall.requestOne(GREETING_NO_PARAMS_REQUEST, GreetingResponse.class);
    ServiceMessage message = Mono.from(future).block(TIMEOUT);
    assertEquals("hello unknown", ((GreetingResponse) message.data()).getResult());
}
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