Search in sources :

Example 6 with ServiceMessage

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

the class ServiceCallLocalTest method test_local_async_greeting_return_GreetingResponse.

@Test
public void test_local_async_greeting_return_GreetingResponse() {
    // When
    Publisher<ServiceMessage> resultFuture = provider.call().requestOne(GREETING_REQUEST_REQ);
    // Then
    ServiceMessage result = Mono.from(resultFuture).block(Duration.ofSeconds(TIMEOUT));
    assertNotNull(result);
    assertEquals(GREETING_REQUEST_REQ.qualifier(), result.qualifier());
    assertEquals(" hello to: joe", ((GreetingResponse) result.data()).getResult());
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) Test(org.junit.jupiter.api.Test)

Example 7 with ServiceMessage

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

the class ServiceLocalTest method test_local_bidi_greeting_expect_message_GreetingResponse.

@Test
public void test_local_bidi_greeting_expect_message_GreetingResponse() {
    // get a proxy to the service api.
    GreetingService service = createProxy(microservices);
    Sinks.Many<GreetingRequest> requests = Sinks.many().unicast().onBackpressureBuffer();
    // call the service.
    Flux<GreetingResponse> responses = service.bidiGreetingMessage(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)).expectNextMatches(resp -> resp.getResult().equals(" hello to: joe-1")).then(() -> requests.emitNext(new GreetingRequest("joe-2"), FAIL_FAST)).expectNextMatches(resp -> resp.getResult().equals(" hello to: joe-2")).then(() -> requests.emitNext(new GreetingRequest("joe-3"), FAIL_FAST)).expectNextMatches(resp -> resp.getResult().equals(" hello to: joe-3")).then(() -> requests.emitComplete(FAIL_FAST)).expectComplete().verify(Duration.ofSeconds(3));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Sinks(reactor.core.publisher.Sinks) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) GreetingResponse(io.scalecube.services.sut.GreetingResponse) Mono(reactor.core.publisher.Mono) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) FAIL_FAST(reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) GreetingService(io.scalecube.services.sut.GreetingService) Duration(java.time.Duration) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) ServiceMessage(io.scalecube.services.api.ServiceMessage) GreetingRequest(io.scalecube.services.sut.GreetingRequest) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ServiceMessage(io.scalecube.services.api.ServiceMessage) Sinks(reactor.core.publisher.Sinks) 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 8 with ServiceMessage

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

the class ServiceRemoteTest method test_remote_bidi_greeting_message_expect_IllegalArgumentException.

@Test
public void test_remote_bidi_greeting_message_expect_IllegalArgumentException() {
    // get a proxy to the service api.
    GreetingService service = createProxy();
    // 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) 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 9 with ServiceMessage

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

the class ServiceRemoteTest method test_remote_bidi_greeting_message_expect_GreetingResponse.

@Test
public void test_remote_bidi_greeting_message_expect_GreetingResponse() {
    // get a proxy to the service api.
    GreetingService service = createProxy();
    Sinks.Many<GreetingRequest> requests = Sinks.many().unicast().onBackpressureBuffer();
    // call the service.
    Flux<GreetingResponse> responses = service.bidiGreetingMessage(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)).expectNextMatches(resp -> resp.getResult().equals(" hello to: joe-1")).then(() -> requests.emitNext(new GreetingRequest("joe-2"), FAIL_FAST)).expectNextMatches(resp -> resp.getResult().equals(" hello to: joe-2")).then(() -> requests.emitNext(new GreetingRequest("joe-3"), FAIL_FAST)).expectNextMatches(resp -> resp.getResult().equals(" hello to: joe-3")).then(() -> requests.emitComplete(FAIL_FAST)).expectComplete().verify(Duration.ofSeconds(3));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Sinks(reactor.core.publisher.Sinks) StepVerifier(reactor.test.StepVerifier) CoarseGrainedServiceImpl(io.scalecube.services.sut.CoarseGrainedServiceImpl) TimeoutException(java.util.concurrent.TimeoutException) Hooks(reactor.core.publisher.Hooks) GreetingResponse(io.scalecube.services.sut.GreetingResponse) HashMap(java.util.HashMap) Disabled(org.junit.jupiter.api.Disabled) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) CoarseGrainedService(io.scalecube.services.sut.CoarseGrainedService) 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) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) EmptyGreetingResponse(io.scalecube.services.sut.EmptyGreetingResponse) InternalServiceException(io.scalecube.services.exceptions.InternalServiceException) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) ServiceDiscovery(io.scalecube.services.discovery.api.ServiceDiscovery) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) FAIL_FAST(reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) GreetingService(io.scalecube.services.sut.GreetingService) EmptyGreetingRequest(io.scalecube.services.sut.EmptyGreetingRequest) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) ServiceMessage(io.scalecube.services.api.ServiceMessage) 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 10 with ServiceMessage

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

the class ServiceCallRemoteTest method test_service_address_lookup_occur_only_after_subscription.

@Test
public void test_service_address_lookup_occur_only_after_subscription() {
    Flux<ServiceMessage> quotes = gateway.call().requestMany(ServiceMessage.builder().qualifier(QuoteService.NAME, "onlyOneAndThenNever").data(null).build());
    // Add service to cluster AFTER creating a call object.
    // (prove address lookup occur only after subscription)
    Microservices quotesService = serviceProvider(new SimpleQuoteService());
    StepVerifier.create(quotes.take(1)).expectNextCount(1).expectComplete().verify(TIMEOUT);
    try {
        quotesService.shutdown();
    } catch (Exception ignored) {
    // no-op
    }
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) SimpleQuoteService(io.scalecube.services.sut.SimpleQuoteService) ServiceException(io.scalecube.services.exceptions.ServiceException) 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