Search in sources :

Example 1 with GreetingServiceImplB

use of io.scalecube.services.a.b.testing.GreetingServiceImplB 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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CanaryService(io.scalecube.services.a.b.testing.CanaryService) CountDownLatch(java.util.concurrent.CountDownLatch) GreetingServiceImplA(io.scalecube.services.a.b.testing.GreetingServiceImplA) GreetingServiceImplB(io.scalecube.services.a.b.testing.GreetingServiceImplB) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 2 with GreetingServiceImplB

use of io.scalecube.services.a.b.testing.GreetingServiceImplB in project scalecube by scalecube.

the class ServiceCallTest method test_service_tags.

@Ignore("https://api.travis-ci.org/v3/job/346827972/log.txt")
@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();
    System.out.println(gateway.cluster().members());
    sleep(1000);
    ServiceCall service = gateway.dispatcher().router(CanaryTestingRouter.class).create();
    AtomicInteger count = new AtomicInteger(0);
    AtomicInteger responses = new AtomicInteger(0);
    CountDownLatch timeLatch = new CountDownLatch(1);
    for (int i = 0; i < 100; i++) {
        // call the service.
        CompletableFuture<Message> future = service.invoke(Messages.builder().request(CanaryService.class, "greeting").data("joe").build());
        future.whenComplete((success, error) -> {
            responses.incrementAndGet();
            if (success.data().toString().startsWith("B")) {
                count.incrementAndGet();
                if ((responses.get() == 100) && (60 < count.get() && count.get() < 80)) {
                    timeLatch.countDown();
                }
            }
        });
    }
    await(timeLatch, 5, TimeUnit.SECONDS);
    System.out.println("responses: " + responses.get());
    System.out.println("count: " + count.get());
    System.out.println("Service B was called: " + count.get() + " times.");
    assertTrue((responses.get() == 100) && (60 < count.get() && count.get() < 80));
    services1.shutdown().get();
    services2.shutdown().get();
    gateway.shutdown().get();
}
Also used : Message(io.scalecube.transport.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CanaryTestingRouter(io.scalecube.services.a.b.testing.CanaryTestingRouter) CanaryService(io.scalecube.services.a.b.testing.CanaryService) CountDownLatch(java.util.concurrent.CountDownLatch) GreetingServiceImplA(io.scalecube.services.a.b.testing.GreetingServiceImplA) GreetingServiceImplB(io.scalecube.services.a.b.testing.GreetingServiceImplB) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Aggregations

CanaryService (io.scalecube.services.a.b.testing.CanaryService)2 GreetingServiceImplA (io.scalecube.services.a.b.testing.GreetingServiceImplA)2 GreetingServiceImplB (io.scalecube.services.a.b.testing.GreetingServiceImplB)2 BaseTest (io.scalecube.testlib.BaseTest)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 CanaryTestingRouter (io.scalecube.services.a.b.testing.CanaryTestingRouter)1 Message (io.scalecube.transport.Message)1 Ignore (org.junit.Ignore)1