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"))));
}
}
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"))));
}
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);
}
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);
}
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));
}
Aggregations