Search in sources :

Example 11 with GreetingResponse

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

the class ServiceRemoteTest method test_remote_bidi_greeting_expect_GreetingResponse.

@Test
public void test_remote_bidi_greeting_expect_GreetingResponse() {
    // get a proxy to the service api.
    GreetingService service = createProxy();
    Sinks.Many<GreetingRequest> requests = Sinks.many().multicast().onBackpressureBuffer();
    // call the service.
    requests.emitNext(new GreetingRequest("joe-1"), FAIL_FAST);
    requests.emitNext(new GreetingRequest("joe-2"), FAIL_FAST);
    requests.emitNext(new GreetingRequest("joe-3"), FAIL_FAST);
    requests.emitComplete(FAIL_FAST);
    // call the service.
    Flux<GreetingResponse> responses = service.bidiGreeting(requests.asFlux().onBackpressureBuffer());
    StepVerifier.create(responses).expectNextMatches(resp -> resp.getResult().equals(" hello to: joe-1")).expectNextMatches(resp -> resp.getResult().equals(" hello to: joe-2")).expectNextMatches(resp -> resp.getResult().equals(" hello to: joe-3")).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) 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 12 with GreetingResponse

use of io.scalecube.services.sut.GreetingResponse 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 13 with GreetingResponse

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

the class ServiceLocalTest method test_local_bidi_greeting_message_expect_NotAuthorized.

@Test
public void test_local_bidi_greeting_message_expect_NotAuthorized() {
    // get a proxy to the service api.
    GreetingService service = createProxy(microservices);
    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) GreetingResponse(io.scalecube.services.sut.GreetingResponse) GreetingService(io.scalecube.services.sut.GreetingService) Test(org.junit.jupiter.api.Test)

Example 14 with GreetingResponse

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

the class ServiceRemoteTest method test_remote_greeting_message.

@Test
void test_remote_greeting_message() {
    GreetingService service = createProxy();
    ServiceMessage request = ServiceMessage.builder().data(new GreetingRequest("joe")).build();
    // using proxy
    StepVerifier.create(service.greetingMessage(request)).assertNext(message -> {
        assertEquals(GreetingResponse.class, message.data().getClass());
        GreetingResponse resp = message.data();
        assertEquals("1", resp.sender());
        assertEquals("hello to: joe", resp.getResult());
    }).expectComplete().verify(TIMEOUT);
    StepVerifier.create(service.greetingMessage2(request)).assertNext(resp -> {
        assertEquals("1", resp.sender());
        assertEquals("hello to: joe", resp.getResult());
    }).expectComplete().verify(TIMEOUT);
    // using serviceCall directly
    ServiceCall serviceCall = gateway.call();
    StepVerifier.create(serviceCall.requestOne(ServiceMessage.from(request).qualifier("v1/greetings/greetingMessage").build(), GreetingResponse.class)).assertNext(message -> {
        assertEquals(GreetingResponse.class, message.data().getClass());
        GreetingResponse resp = message.data();
        assertEquals("1", resp.sender());
        assertEquals("hello to: joe", resp.getResult());
    }).expectComplete().verify(TIMEOUT);
    StepVerifier.create(serviceCall.requestOne(ServiceMessage.from(request).qualifier("v1/greetings/greetingMessage2").build(), GreetingResponse.class)).assertNext(message -> {
        assertEquals(GreetingResponse.class, message.data().getClass());
        GreetingResponse resp = message.data();
        assertEquals("1", resp.sender());
        assertEquals("hello to: joe", resp.getResult());
    }).expectComplete().verify(TIMEOUT);
}
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 15 with GreetingResponse

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

the class ServiceRemoteTest method test_remote_greeting_request_timeout_expires.

@Test
public void test_remote_greeting_request_timeout_expires() {
    // get a proxy to the service api.
    GreetingService service = createProxy();
    // call the service.
    Publisher<GreetingResponse> result = service.greetingRequestTimeout(new GreetingRequest("joe", Duration.ofSeconds(4)));
    Mono.from(result).doOnError(success -> {
        // print the greeting.
        System.out.println("remote_greeting_request_timeout_expires : " + success);
        assertTrue(success instanceof TimeoutException);
    });
}
Also used : 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) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Aggregations

GreetingResponse (io.scalecube.services.sut.GreetingResponse)28 Test (org.junit.jupiter.api.Test)28 GreetingRequest (io.scalecube.services.sut.GreetingRequest)23 GreetingService (io.scalecube.services.sut.GreetingService)22 ServiceMessage (io.scalecube.services.api.ServiceMessage)15 EmptyGreetingResponse (io.scalecube.services.sut.EmptyGreetingResponse)14 EmptyGreetingRequest (io.scalecube.services.sut.EmptyGreetingRequest)11 Sinks (reactor.core.publisher.Sinks)10 Duration (java.time.Duration)7 GreetingServiceImpl (io.scalecube.services.sut.GreetingServiceImpl)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)6 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)6 Flux (reactor.core.publisher.Flux)6 Mono (reactor.core.publisher.Mono)6 FAIL_FAST (reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST)6 StepVerifier (reactor.test.StepVerifier)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 AfterEach (org.junit.jupiter.api.AfterEach)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4