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);
}
}
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());
}
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());
}
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);
}
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();
}
Aggregations