Search in sources :

Example 1 with GreetingResponse

use of io.scalecube.services.sut.GreetingResponse in project scalecube by scalecube.

the class RoutersTest method test_round_robin.

@Test
public void test_round_robin() {
    ServiceCall service = gateway.call();
    // call the service.
    GreetingResponse result1 = Mono.from(service.requestOne(GREETING_REQUEST_REQ, GreetingResponse.class)).timeout(TIMEOUT).block().data();
    GreetingResponse result2 = Mono.from(service.requestOne(GREETING_REQUEST_REQ, GreetingResponse.class)).timeout(TIMEOUT).block().data();
    assertNotEquals(result1.sender(), result2.sender());
}
Also used : ServiceCall(io.scalecube.services.ServiceCall) GreetingResponse(io.scalecube.services.sut.GreetingResponse) Test(org.junit.jupiter.api.Test) BaseTest(io.scalecube.services.BaseTest)

Example 2 with GreetingResponse

use of io.scalecube.services.sut.GreetingResponse in project scalecube by scalecube.

the class RoutersTest method test_tag_selection_logic.

@Test
public void test_tag_selection_logic() {
    ServiceCall service = gateway.call().router((reg, msg) -> reg.listServiceReferences().stream().filter(ref -> "2".equals(ref.tags().get("SENDER"))).findFirst());
    // call the service.
    for (int i = 0; i < 1e3; i++) {
        GreetingResponse result = Mono.from(service.requestOne(GREETING_REQUEST_REQ, GreetingResponse.class)).timeout(TIMEOUT).block().data();
        assertEquals("2", result.sender());
    }
}
Also used : ServiceCall(io.scalecube.services.ServiceCall) GreetingResponse(io.scalecube.services.sut.GreetingResponse) Test(org.junit.jupiter.api.Test) BaseTest(io.scalecube.services.BaseTest)

Example 3 with GreetingResponse

use of io.scalecube.services.sut.GreetingResponse 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));
}
Also used : GreetingRequest(io.scalecube.services.sut.GreetingRequest) GreetingResponse(io.scalecube.services.sut.GreetingResponse) GreetingService(io.scalecube.services.sut.GreetingService) Test(org.junit.jupiter.api.Test)

Example 4 with GreetingResponse

use of io.scalecube.services.sut.GreetingResponse 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));
}
Also used : GreetingRequest(io.scalecube.services.sut.GreetingRequest) GreetingResponse(io.scalecube.services.sut.GreetingResponse) GreetingService(io.scalecube.services.sut.GreetingService) Test(org.junit.jupiter.api.Test)

Example 5 with GreetingResponse

use of io.scalecube.services.sut.GreetingResponse in project scalecube by scalecube.

the class ServiceLocalTest method test_local_async_greeting_return_GreetingResponse.

@Test
public void test_local_async_greeting_return_GreetingResponse() {
    // get a proxy to the service api.
    GreetingService service = createProxy(microservices);
    // call the service.
    Mono<GreetingResponse> future = Mono.from(service.greetingRequest(new GreetingRequest("joe")));
    AtomicReference<GreetingResponse> result = new AtomicReference<>();
    future.doOnNext(onNext -> {
        result.set(onNext);
        System.out.println("remote_async_greeting_return_GreetingResponse :" + onNext);
    }).block(Duration.ofSeconds(1));
    assertEquals(" hello to: joe", result.get().getResult());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Sinks(reactor.core.publisher.Sinks) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) GreetingResponse(io.scalecube.services.sut.GreetingResponse) Mono(reactor.core.publisher.Mono) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) FAIL_FAST(reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) GreetingService(io.scalecube.services.sut.GreetingService) Duration(java.time.Duration) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) ServiceMessage(io.scalecube.services.api.ServiceMessage) GreetingRequest(io.scalecube.services.sut.GreetingRequest) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) GreetingRequest(io.scalecube.services.sut.GreetingRequest) GreetingResponse(io.scalecube.services.sut.GreetingResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) GreetingService(io.scalecube.services.sut.GreetingService) Test(org.junit.jupiter.api.Test)

Aggregations

GreetingResponse (io.scalecube.services.sut.GreetingResponse)28 Test (org.junit.jupiter.api.Test)28 GreetingRequest (io.scalecube.services.sut.GreetingRequest)23 GreetingService (io.scalecube.services.sut.GreetingService)22 ServiceMessage (io.scalecube.services.api.ServiceMessage)15 EmptyGreetingResponse (io.scalecube.services.sut.EmptyGreetingResponse)14 EmptyGreetingRequest (io.scalecube.services.sut.EmptyGreetingRequest)11 Sinks (reactor.core.publisher.Sinks)10 Duration (java.time.Duration)7 GreetingServiceImpl (io.scalecube.services.sut.GreetingServiceImpl)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)6 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)6 Flux (reactor.core.publisher.Flux)6 Mono (reactor.core.publisher.Mono)6 FAIL_FAST (reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST)6 StepVerifier (reactor.test.StepVerifier)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 AfterEach (org.junit.jupiter.api.AfterEach)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4