use of io.scalecube.services.sut.GreetingRequest in project scalecube by scalecube.
the class RoutersTest method test_service_tags.
@Test
public void test_service_tags() throws Exception {
TimeUnit.SECONDS.sleep(3);
ServiceCall service = gateway.call().router(WeightedRandomRouter.class);
ServiceMessage req = ServiceMessage.builder().qualifier(Reflect.serviceName(CanaryService.class), "greeting").data(new GreetingRequest("joe")).build();
AtomicInteger serviceBCount = new AtomicInteger(0);
int n = (int) 1e3;
for (int i = 0; i < n; i++) {
ServiceMessage message = service.requestOne(req, GreetingResponse.class).block(TIMEOUT);
if (message.data().toString().contains("SERVICE_B_TALKING")) {
serviceBCount.incrementAndGet();
}
}
System.out.println("Service B was called: " + serviceBCount.get() + " times out of " + n);
assertTrue((serviceBCount.doubleValue() / n) > 0.5, "Service B's Weight=0.9; at least more than half " + "of invocations have to be routed to Service B");
}
use of io.scalecube.services.sut.GreetingRequest in project scalecube by scalecube.
the class RoutersTest method test_remote_service_tags.
@Test
public void test_remote_service_tags() throws Exception {
CanaryService service = gateway.call().router(Routers.getRouter(WeightedRandomRouter.class)).api(CanaryService.class);
Thread.sleep(1000);
AtomicInteger serviceBCount = new AtomicInteger(0);
int n = (int) 1e3;
Flux.range(0, n).flatMap(i -> service.greeting(new GreetingRequest("joe"))).filter(response -> response.getResult().contains("SERVICE_B_TALKING")).doOnNext(response -> serviceBCount.incrementAndGet()).blockLast(Duration.ofSeconds(3));
System.out.println("Service B was called: " + serviceBCount.get() + " times out of " + n);
assertTrue((serviceBCount.doubleValue() / n) > 0.5, "Service B's Weight=0.9; more than half of invocations have to be routed to Service B");
}
use of io.scalecube.services.sut.GreetingRequest in project scalecube by scalecube.
the class ServiceLocalTest method test_local_async_greeting_return_Message.
@Test
public void test_local_async_greeting_return_Message() {
// get a proxy to the service api.
GreetingService service = createProxy(microservices);
// call the service.
Mono<GreetingResponse> future = Mono.from(service.greetingRequest(new GreetingRequest("joe")));
future.doOnNext(result -> {
assertEquals(" hello to: joe", result.getResult());
// print the greeting.
System.out.println("9. local_async_greeting_return_Message :" + result);
}).doOnError(System.out::println).block(Duration.ofSeconds(1));
}
use of io.scalecube.services.sut.GreetingRequest in project scalecube by scalecube.
the class ServiceLocalTest method test_local_bidi_greeting_expect_IllegalArgumentException.
@Test
public void test_local_bidi_greeting_expect_IllegalArgumentException() {
// get a proxy to the service api.
GreetingService service = createProxy(microservices);
// call the service. bidiThrowingGreeting
Flux<GreetingResponse> responses = service.bidiGreetingIllegalArgumentException(Mono.just(new GreetingRequest("IllegalArgumentException")));
// call the service.
StepVerifier.create(responses).expectErrorMessage("IllegalArgumentException").verify(Duration.ofSeconds(3));
}
use of io.scalecube.services.sut.GreetingRequest in project scalecube by scalecube.
the class ServiceLocalTest method test_local_greeting_request_timeout_expires.
@Test
public void test_local_greeting_request_timeout_expires() {
GreetingService service = createProxy(microservices);
// call the service.
Throwable exception = assertThrows(RuntimeException.class, () -> Mono.from(service.greetingRequestTimeout(new GreetingRequest("joe", timeout))).timeout(Duration.ofSeconds(1)).block());
assertTrue(exception.getCause().getMessage().contains("Did not observe any item or terminal signal"));
}
Aggregations