Search in sources :

Example 1 with Request

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

the class SocketClientHandlerTest method testSimpleRequest_exception.

@Test
public void testSimpleRequest_exception() throws IOException, TException {
    when(impl.test(any(net.morimekta.test.thrift.thrift.service.Request.class))).thenThrow(new net.morimekta.test.thrift.thrift.service.Failure("failure"));
    MyService.Iface client = new MyService.Client(new SocketClientHandler(serializer, address));
    try {
        client.test(new Request(null));
        fail("no exception");
    } catch (Failure f) {
        assertThat(f, is(equalToMessage(new Failure("failure"))));
    }
}
Also used : Iface(net.morimekta.test.thrift.thrift.service.MyService.Iface) MyService(net.morimekta.test.providence.thrift.service.MyService) Request(net.morimekta.test.providence.thrift.service.Request) Failure(net.morimekta.test.providence.thrift.service.Failure) Test(org.junit.Test)

Example 2 with Request

use of net.morimekta.test.providence.thrift.service.Request 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 3 with Request

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

the class SocketClientHandlerTest method testSimpleRequest_cannotConnect.

@Test
public void testSimpleRequest_cannotConnect() throws IOException, Failure, InterruptedException {
    Serializer serializer = new BinarySerializer();
    InetSocketAddress address = new InetSocketAddress("localhost", port - 10);
    MyService.Iface client = new MyService.Client(new SocketClientHandler(serializer, address));
    try {
        client.test(new Request(null));
        fail("no exception");
    } catch (ConnectException e) {
        assertThat(e.getMessage(), containsString("Connection refused"));
    }
    Thread.sleep(10L);
    verifyZeroInteractions(impl);
}
Also used : Iface(net.morimekta.test.thrift.thrift.service.MyService.Iface) InetSocketAddress(java.net.InetSocketAddress) MyService(net.morimekta.test.providence.thrift.service.MyService) Request(net.morimekta.test.providence.thrift.service.Request) BinarySerializer(net.morimekta.providence.serializer.BinarySerializer) BinarySerializer(net.morimekta.providence.serializer.BinarySerializer) Serializer(net.morimekta.providence.serializer.Serializer) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 4 with Request

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

the class SocketClientHandlerTest method testSimpleRequest_wrongMethod.

@Test
public void testSimpleRequest_wrongMethod() throws IOException, TException, Failure, InterruptedException {
    when(impl.test(any(net.morimekta.test.thrift.thrift.service.Request.class))).thenThrow(new net.morimekta.test.thrift.thrift.service.Failure("failure"));
    MyService2.Iface client = new MyService2.Client(new SocketClientHandler(serializer, address));
    try {
        client.testing(new Request(null));
        fail("no exception");
    } catch (PApplicationException e) {
        assertThat(e.getId(), is(UNKNOWN_METHOD));
        assertThat(e.getMessage(), is(equalTo("Invalid method name: 'testing'")));
    }
    Thread.sleep(10L);
    verifyZeroInteractions(impl);
}
Also used : MyService2(net.morimekta.test.providence.thrift.service.MyService2) PApplicationException(net.morimekta.providence.PApplicationException) Request(net.morimekta.test.providence.thrift.service.Request) Test(org.junit.Test)

Example 5 with Request

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

the class BinarySerializerCompatibilityTest method testProvidenceToThrift_simple.

@Test
public void testProvidenceToThrift_simple() throws IOException {
    Request request = new Request("test");
    // Providence client talks to thrift service.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    providence.serialize(baos, request);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    Request out = thrift.deserialize(bais, Request.kDescriptor);
    assertThat(out, equalToMessage(request));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Request(net.morimekta.test.providence.thrift.service.Request) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

Request (net.morimekta.test.providence.thrift.service.Request)7 Test (org.junit.Test)7 MyService (net.morimekta.test.providence.thrift.service.MyService)3 Iface (net.morimekta.test.thrift.thrift.service.MyService.Iface)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PApplicationException (net.morimekta.providence.PApplicationException)2 MyService2 (net.morimekta.test.providence.thrift.service.MyService2)2 ConnectException (java.net.ConnectException)1 InetSocketAddress (java.net.InetSocketAddress)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BinarySerializer (net.morimekta.providence.serializer.BinarySerializer)1 Serializer (net.morimekta.providence.serializer.Serializer)1 Failure (net.morimekta.test.providence.thrift.service.Failure)1 Response (net.morimekta.test.providence.thrift.service.Response)1