Search in sources :

Example 11 with Microservices

use of io.scalecube.services.Microservices in project scalecube by scalecube.

the class TestStreamingService method test_remote_quotes_service.

@Test
public void test_remote_quotes_service() throws InterruptedException {
    Microservices gateway = Microservices.builder().build();
    Microservices node = Microservices.builder().seeds(gateway.cluster().address()).services(new SimpleQuoteService()).build();
    QuoteService service = gateway.proxy().api(QuoteService.class).create();
    CountDownLatch latch1 = new CountDownLatch(3);
    CountDownLatch latch2 = new CountDownLatch(3);
    Subscription sub1 = service.quotes(2).subscribe(onNext -> {
        System.out.println("test_remote_quotes_service-2: " + onNext);
        latch1.countDown();
    });
    Subscription sub2 = service.quotes(10).subscribe(onNext -> {
        System.out.println("test_remote_quotes_service-10: " + onNext);
        latch2.countDown();
    });
    latch1.await(1, TimeUnit.SECONDS);
    latch2.await(1, TimeUnit.SECONDS);
    sub1.unsubscribe();
    sub2.unsubscribe();
    assertTrue(latch1.getCount() == 0);
    assertTrue(latch2.getCount() == 0);
    gateway.shutdown();
    node.shutdown();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(rx.Subscription) Microservices(io.scalecube.services.Microservices) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 12 with Microservices

use of io.scalecube.services.Microservices in project scalecube by scalecube.

the class TestStreamingService method test_quotes_snapshot.

@Test
public void test_quotes_snapshot() throws InterruptedException {
    int batchSize = 500_000;
    Microservices gateway = Microservices.builder().build();
    Microservices node = Microservices.builder().seeds(gateway.cluster().address()).services(new SimpleQuoteService()).metrics(registry).build();
    QuoteService service = gateway.proxy().api(QuoteService.class).create();
    CountDownLatch latch1 = new CountDownLatch(batchSize);
    Subscription sub1 = service.snapshoot(batchSize).subscribeOn(Schedulers.from(Executors.newCachedThreadPool())).serialize().subscribe(onNext -> latch1.countDown());
    long start = System.currentTimeMillis();
    latch1.await(batchSize / 20_000, TimeUnit.SECONDS);
    long end = (System.currentTimeMillis() - start);
    System.out.println("TIME IS UP! - recived batch (size: " + (batchSize - latch1.getCount()) + "/" + batchSize + ") in " + (System.currentTimeMillis() - start) + "ms: " + "rate of :" + batchSize / (end / 1000) + " events/sec ");
    System.out.println(registry.getMeters());
    assertTrue(latch1.getCount() == 0);
    sub1.unsubscribe();
    gateway.shutdown();
    node.shutdown();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(rx.Subscription) Microservices(io.scalecube.services.Microservices) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 13 with Microservices

use of io.scalecube.services.Microservices in project scalecube by scalecube.

the class SimpleStressTest method test_naive_proxy_stress.

@Test
public void test_naive_proxy_stress() throws InterruptedException, ExecutionException {
    // Create microservices cluster member.
    Microservices provider = Microservices.builder().port(port.incrementAndGet()).services(new GreetingServiceImpl()).metrics(registry).build();
    // Create microservices cluster member.
    Microservices consumer = Microservices.builder().port(port.incrementAndGet()).seeds(provider.cluster().address()).metrics(registry).build();
    reporter.start(10, TimeUnit.SECONDS);
    // Get a proxy to the service api.
    GreetingService service = consumer.proxy().api(// create proxy for GreetingService API
    GreetingService.class).timeout(Duration.ofSeconds(30)).create();
    // Measure
    CountDownLatch countLatch = new CountDownLatch(count);
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        CompletableFuture<Message> future = service.greetingMessage(Message.fromData("naive_stress_test"));
        future.whenComplete((success, error) -> {
            if (error == null) {
                countLatch.countDown();
            } else {
                System.out.println("failed: " + error);
                fail("test_naive_stress_not_breaking_the_system failed: " + error);
            }
        });
    }
    System.out.println("Finished sending " + count + " messages in " + (System.currentTimeMillis() - startTime));
    countLatch.await(60, TimeUnit.SECONDS);
    System.out.println("Finished receiving " + (count - countLatch.getCount()) + " messages in " + (System.currentTimeMillis() - startTime));
    System.out.println("Rate: " + ((count - countLatch.getCount()) / ((System.currentTimeMillis() - startTime) / 1000)) + " round-trips/sec");
    reporter.stop();
    assertTrue(countLatch.getCount() == 0);
    provider.shutdown().get();
    consumer.shutdown().get();
}
Also used : Message(io.scalecube.transport.Message) CountDownLatch(java.util.concurrent.CountDownLatch) Microservices(io.scalecube.services.Microservices) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 14 with Microservices

use of io.scalecube.services.Microservices in project scalecube by scalecube.

the class TestStreamingService method test_local_quotes_service.

@Test
public void test_local_quotes_service() throws InterruptedException {
    Microservices node = Microservices.builder().services(new SimpleQuoteService()).build();
    QuoteService service = node.proxy().api(QuoteService.class).create();
    CountDownLatch latch = new CountDownLatch(3);
    Observable<String> obs = service.quotes(2);
    Subscription sub = obs.subscribe(onNext -> {
        latch.countDown();
    });
    latch.await(1, TimeUnit.SECONDS);
    sub.unsubscribe();
    assertTrue(latch.getCount() <= 0);
    node.shutdown();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(rx.Subscription) Microservices(io.scalecube.services.Microservices) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Aggregations

Microservices (io.scalecube.services.Microservices)14 BaseTest (io.scalecube.testlib.BaseTest)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 Test (org.junit.Test)11 Subscription (rx.Subscription)8 ServiceCall (io.scalecube.services.ServiceCall)7 Message (io.scalecube.transport.Message)7 MetricRegistry (com.codahale.metrics.MetricRegistry)4 Messages (io.scalecube.services.Messages)4 Executors (java.util.concurrent.Executors)4 TimeUnit (java.util.concurrent.TimeUnit)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Observable (rx.Observable)4 Schedulers (rx.schedulers.Schedulers)4