Search in sources :

Example 1 with Response

use of net.morimekta.test.providence.thrift.service.Response in project providence by morimekta.

the class SocketClientHandlerTest method testSimpleRequest.

@Test
public void testSimpleRequest() throws IOException, TException, Failure {
    AtomicBoolean called = new AtomicBoolean();
    when(impl.test(new net.morimekta.test.thrift.thrift.service.Request("test"))).thenAnswer(i -> {
        called.set(true);
        return new net.morimekta.test.thrift.thrift.service.Response("response");
    });
    MyService.Iface client = new MyService.Client(new SocketClientHandler(serializer, address));
    Response response = client.test(new Request("test"));
    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
    verify(impl).test(any(net.morimekta.test.thrift.thrift.service.Request.class));
    assertThat(response, is(equalToMessage(new Response("response"))));
}
Also used : Iface(net.morimekta.test.thrift.thrift.service.MyService.Iface) Request(net.morimekta.test.providence.thrift.service.Request) Response(net.morimekta.test.providence.thrift.service.Response) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MyService(net.morimekta.test.providence.thrift.service.MyService) Test(org.junit.Test)

Example 2 with Response

use of net.morimekta.test.providence.thrift.service.Response in project providence by morimekta.

the class NonblockingSocketClientHandlerTest method testSimpleRequest.

@Test
public void testSimpleRequest() throws IOException, TException, net.morimekta.test.providence.thrift.service.Failure {
    when(impl.test(new net.morimekta.test.thrift.thrift.service.Request("test"))).thenReturn(new net.morimekta.test.thrift.thrift.service.Response("response"));
    try (NonblockingSocketClientHandler handler = new NonblockingSocketClientHandler(serializer, address)) {
        MyService.Iface client = new MyService.Client(handler);
        Response response = client.test(Request.builder().setText("test").build());
        verify(impl).test(any(net.morimekta.test.thrift.thrift.service.Request.class));
        assertThat(response, is(equalToMessage(new Response("response"))));
    }
}
Also used : Iface(net.morimekta.test.thrift.thrift.service.MyService.Iface) Request(net.morimekta.test.providence.thrift.service.Request) Response(net.morimekta.test.providence.thrift.service.Response) MyService(net.morimekta.test.providence.thrift.service.MyService) Test(org.junit.Test)

Example 3 with Response

use of net.morimekta.test.providence.thrift.service.Response in project providence by morimekta.

the class NonblockingSocketClientHandlerTest method testMultipleRequests.

@Test
public void testMultipleRequests() throws IOException, TException, net.morimekta.test.providence.thrift.service.Failure {
    when(impl.test(new net.morimekta.test.thrift.thrift.service.Request("test"))).thenReturn(new net.morimekta.test.thrift.thrift.service.Response("response"));
    when(impl.test(new net.morimekta.test.thrift.thrift.service.Request("test2"))).thenReturn(new net.morimekta.test.thrift.thrift.service.Response("response2"));
    try (NonblockingSocketClientHandler handler = new NonblockingSocketClientHandler(serializer, address)) {
        MyService.Iface client = new MyService.Client(handler);
        Response response = client.test(Request.builder().setText("test").build());
        Response response2 = client.test(Request.builder().setText("test2").build());
        verify(impl).test(eq(new net.morimekta.test.thrift.thrift.service.Request("test")));
        verify(impl).test(eq(new net.morimekta.test.thrift.thrift.service.Request("test2")));
        verifyNoMoreInteractions(impl);
        assertThat(response, is(equalToMessage(new Response("response"))));
        assertThat(response2, is(equalToMessage(new Response("response2"))));
    }
}
Also used : Iface(net.morimekta.test.thrift.thrift.service.MyService.Iface) Request(net.morimekta.test.providence.thrift.service.Request) Response(net.morimekta.test.providence.thrift.service.Response) MyService(net.morimekta.test.providence.thrift.service.MyService) Test(org.junit.Test)

Aggregations

MyService (net.morimekta.test.providence.thrift.service.MyService)3 Request (net.morimekta.test.providence.thrift.service.Request)3 Response (net.morimekta.test.providence.thrift.service.Response)3 Iface (net.morimekta.test.thrift.thrift.service.MyService.Iface)3 Test (org.junit.Test)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1