use of io.scalecube.services.a.b.testing.CanaryService in project scalecube by scalecube.
the class ServiceTest method test_service_tags.
@Test
public void test_service_tags() throws InterruptedException, ExecutionException {
Microservices gateway = Microservices.builder().port(port.incrementAndGet()).build();
Microservices services1 = Microservices.builder().port(port.incrementAndGet()).seeds(gateway.cluster().address()).services().service(new GreetingServiceImplA()).tag("Weight", "0.3").add().build().build();
Microservices services2 = Microservices.builder().port(port.incrementAndGet()).seeds(gateway.cluster().address()).services().service(new GreetingServiceImplB()).tag("Weight", "0.7").add().build().build();
CanaryService service = gateway.proxy().router(CanaryTestingRouter.class).api(CanaryService.class).create();
Util.sleep(1000);
AtomicInteger count = new AtomicInteger(0);
AtomicInteger responses = new AtomicInteger(0);
CountDownLatch timeLatch = new CountDownLatch(1);
for (int i = 0; i < 100; i++) {
service.greeting("joe").whenComplete((success, error) -> {
responses.incrementAndGet();
if (success.startsWith("B")) {
count.incrementAndGet();
if ((responses.get() == 100) && (60 < count.get() && count.get() < 80)) {
timeLatch.countDown();
}
}
});
}
services2.shutdown().get();
services1.shutdown().get();
gateway.shutdown().get();
}
Aggregations