Search in sources :

Example 26 with ServiceMessage

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

the class ServiceCallRemoteTest method test_many_stream_block_first.

@Disabled("https://github.com/scalecube/scalecube-services/issues/742")
public void test_many_stream_block_first() {
    ServiceCall call = gateway.call();
    ServiceMessage request = TestRequests.GREETING_MANY_STREAM_30;
    for (int i = 0; i < 100; i++) {
        // noinspection ConstantConditions
        long first = call.requestMany(request, Long.class).map(ServiceMessage::<Long>data).filter(k -> k != 0).take(1).blockFirst();
        assertEquals(1, first);
    }
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) Disabled(org.junit.jupiter.api.Disabled)

Example 27 with ServiceMessage

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

the class ServiceCallRemoteTest method test_remote_async_greeting_return_string.

@Test
public void test_remote_async_greeting_return_string() {
    Publisher<ServiceMessage> resultFuture = gateway.call().requestOne(GREETING_REQ, String.class);
    // Then
    ServiceMessage result = Mono.from(resultFuture).block(TIMEOUT);
    assertNotNull(result);
    assertEquals(GREETING_REQ.qualifier(), result.qualifier());
    assertEquals(" hello to: joe", result.data());
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) Test(org.junit.jupiter.api.Test)

Example 28 with ServiceMessage

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

the class ServiceCallRemoteTest method test_remote_async_greeting_return_GreetingResponse.

@Test
public void test_remote_async_greeting_return_GreetingResponse() {
    // When
    Publisher<ServiceMessage> result = gateway.call().requestOne(GREETING_REQUEST_REQ, GreetingResponse.class);
    // Then
    GreetingResponse greeting = Mono.from(result).block(TIMEOUT).data();
    assertEquals(" hello to: joe", greeting.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 29 with ServiceMessage

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

the class ServiceLocalTest method test_local_greeting_message.

@Test
void test_local_greeting_message() {
    GreetingService service = createProxy(microservices);
    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 = microservices.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) GreetingResponse(io.scalecube.services.sut.GreetingResponse) GreetingService(io.scalecube.services.sut.GreetingService) Test(org.junit.jupiter.api.Test)

Example 30 with ServiceMessage

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

the class ServiceMethodInvokerTest method testInvokeManyWhenReturnNull.

@Test
@DisplayName("invokeMany should return empty response when service returns null")
void testInvokeManyWhenReturnNull() throws Exception {
    final String methodName = "returnNull2";
    final Class<? extends StubService> serviceClass = stubService.getClass();
    final Method method = serviceClass.getMethod(methodName);
    final MethodInfo methodInfo = new MethodInfo(serviceClass.getName(), methodName, method.getReturnType(), IS_RETURN_TYPE_SERVICE_MESSAGE, CommunicationMode.REQUEST_STREAM, method.getParameterCount(), Void.TYPE, IS_REQUEST_TYPE_SERVICE_MESSAGE, AUTH);
    serviceMethodInvoker = new ServiceMethodInvoker(method, stubService, methodInfo, DefaultErrorMapper.INSTANCE, dataDecoder, nullAuthenticator, nullPrincipalMapper);
    ServiceMessage message = ServiceMessage.builder().qualifier(qualifierPrefix + methodName).build();
    StepVerifier.create(Flux.deferContextual(context -> serviceMethodInvoker.invokeMany(message)).contextWrite(context -> context.put(AUTH_CONTEXT_KEY, AUTH_DATA))).verifyComplete();
}
Also used : ArgumentMatchers(org.mockito.ArgumentMatchers) StepVerifier(reactor.test.StepVerifier) Mono(reactor.core.publisher.Mono) AUTH_CONTEXT_KEY(io.scalecube.services.auth.Authenticator.AUTH_CONTEXT_KEY) CommunicationMode(io.scalecube.services.CommunicationMode) Authenticator(io.scalecube.services.auth.Authenticator) DefaultErrorMapper(io.scalecube.services.exceptions.DefaultErrorMapper) DisplayName(org.junit.jupiter.api.DisplayName) PrincipalMapper(io.scalecube.services.auth.PrincipalMapper) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Flux(reactor.core.publisher.Flux) ServiceMessageDataDecoder(io.scalecube.services.transport.api.ServiceMessageDataDecoder) Map(java.util.Map) Assertions(org.junit.jupiter.api.Assertions) ServiceMessage(io.scalecube.services.api.ServiceMessage) Method(java.lang.reflect.Method) Collections(java.util.Collections) ServiceMessage(io.scalecube.services.api.ServiceMessage) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

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