use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.
the class ServiceMethodInvokerTest method testInvokeBidirectionalWhenReturnNull.
@Test
@DisplayName("invokeBidirectional should return empty response when service returns null")
void testInvokeBidirectionalWhenReturnNull() throws Exception {
final String methodName = "returnNull3";
final Class<? extends StubService> serviceClass = stubService.getClass();
final Method method = serviceClass.getMethod(methodName, Flux.class);
final MethodInfo methodInfo = new MethodInfo(serviceClass.getName(), methodName, method.getReturnType(), IS_RETURN_TYPE_SERVICE_MESSAGE, CommunicationMode.REQUEST_CHANNEL, 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.invokeBidirectional(Flux.just(message))).contextWrite(context -> context.put(AUTH_CONTEXT_KEY, AUTH_DATA))).verifyComplete();
}
use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.
the class ServiceMethodInvokerTest method testInvokeManyWhenThrowException.
@Test
@DisplayName("invokeMany should return error response when service throws exception")
void testInvokeManyWhenThrowException() throws Exception {
final String methodName = "throwException2";
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();
final Flux<ServiceMessage> invokeOne = Flux.deferContextual(context -> serviceMethodInvoker.invokeMany(message)).contextWrite(context -> context.put(AUTH_CONTEXT_KEY, AUTH_DATA));
StepVerifier.create(invokeOne).assertNext(serviceMessage -> Assertions.assertTrue(serviceMessage.isError())).verifyComplete();
}
use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.
the class ServiceMethodInvokerTest method testAuthMethodWhenThereIsContextAndNoAuthenticator.
@Test
@DisplayName("invocation of auth method should return empty response " + "if auth.context exists and no authenticator")
void testAuthMethodWhenThereIsContextAndNoAuthenticator() throws Exception {
final String methodName = "helloAuthContext";
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_RESPONSE, method.getParameterCount(), Void.TYPE, IS_REQUEST_TYPE_SERVICE_MESSAGE, AUTH);
serviceMethodInvoker = new ServiceMethodInvoker(method, stubService, methodInfo, DefaultErrorMapper.INSTANCE, dataDecoder, nullAuthenticator, principalMapper);
ServiceMessage message = ServiceMessage.builder().qualifier(qualifierPrefix + methodName).build();
StepVerifier.create(Mono.deferContextual(context -> serviceMethodInvoker.invokeOne(message)).contextWrite(context -> context.put(AUTH_CONTEXT_KEY, AUTH_DATA))).verifyComplete();
}
use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.
the class ServiceCallLocalTest method test_local_async_greeting_return_Message.
@Test
public void test_local_async_greeting_return_Message() {
ServiceMessage result = provider.call().requestOne(GREETING_REQUEST_REQ).block(timeout);
// print the greeting.
GreetingResponse responseData = result.data();
System.out.println("local_async_greeting_return_Message :" + responseData);
assertEquals(" hello to: joe", responseData.getResult());
}
use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.
the class StreamingServiceTest method test_scheduled_messages.
@Test
public void test_scheduled_messages() {
ServiceCall serviceCall = gateway.call();
ServiceMessage scheduled = ServiceMessage.builder().qualifier(QuoteService.NAME, "scheduled").data(1000).build();
int expected = 3;
List<ServiceMessage> list = serviceCall.requestMany(scheduled).take(Duration.ofSeconds(4)).collectList().block();
assertEquals(expected, list.size());
}
Aggregations