use of net.morimekta.test.providence.client.Request in project providence by morimekta.
the class HttpClientHandlerTest method testBadResponse.
@Test
@SuppressWarnings("unchecked")
public void testBadResponse() throws IOException, Failure {
TestService.Iface client = new TestService.Client(new HttpClientHandler(this::html));
try {
client.test(new Request("request"));
fail("no exception");
} catch (PApplicationException e) {
assertThat(e.getMessage(), is("Unknown content-type in response: text/html;charset=utf-8"));
assertThat(e.getId(), is(PApplicationExceptionType.INVALID_PROTOCOL));
}
client = new TestService.Client(new HttpClientHandler(this::response));
reply.set(new PServiceCall("foo", PServiceCallType.REPLY, 1, new TestServiceBypass().testResponse("foo")));
try {
client.test(new Request("request"));
fail("no exception");
} catch (SerializerException e) {
assertThat(e.getMessage(), is("No such method foo on client.TestService"));
assertThat(e.getExceptionType(), is(PApplicationExceptionType.UNKNOWN_METHOD));
assertThat(e.getMethodName(), is("foo"));
assertThat(e.getSequenceNo(), is(1));
}
reply.set(new PServiceCall("test", PServiceCallType.CALL, 2, new TestServiceBypass().testResponse("bar")));
try {
client.test(new Request("request"));
fail("no exception");
} catch (PApplicationException e) {
assertThat(e.getMessage(), is("Reply with invalid call type: CALL"));
assertThat(e.getId(), is(PApplicationExceptionType.INVALID_MESSAGE_TYPE));
}
reply.set(new PServiceCall("test", PServiceCallType.REPLY, 100, new TestServiceBypass().testResponse("baz")));
try {
client.test(new Request("request"));
fail("no exception");
} catch (PApplicationException e) {
assertThat(e.getMessage(), is("Reply sequence out of order: call = 2, reply = 100"));
assertThat(e.getId(), is(PApplicationExceptionType.BAD_SEQUENCE_ID));
}
reply.set(new PServiceCall("test", PServiceCallType.REPLY, 4, new PApplicationException("foo", PApplicationExceptionType.INTERNAL_ERROR)));
try {
client.test(new Request("request"));
fail("no exception");
} catch (SerializerException e) {
assertThat(e.getMessage(), is("Wrong type string(11) for client.TestService.test.response.fail, should be struct(12)"));
assertThat(e.getExceptionType(), is(PApplicationExceptionType.PROTOCOL_ERROR));
assertThat(e.getMethodName(), is("test"));
assertThat(e.getSequenceNo(), is(4));
}
}
use of net.morimekta.test.providence.client.Request in project providence by morimekta.
the class HttpClientHandlerTest method testSimpleRequest.
@Test
public void testSimpleRequest() throws IOException, TException, Failure {
TestService.Iface client = new TestService.Client(new HttpClientHandler(this::endpoint, factory(), provider, instrumentation));
when(impl.test(any(net.morimekta.test.thrift.client.Request.class))).thenReturn(new net.morimekta.test.thrift.client.Response("response"));
Response response = client.test(new Request("request"));
waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).until(() -> contentTypes.size() > 0);
verify(impl).test(any(net.morimekta.test.thrift.client.Request.class));
verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
verifyNoMoreInteractions(impl, instrumentation);
assertThat(response, is(equalToMessage(new Response("response"))));
assertThat(contentTypes, is(equalTo(ImmutableList.of("application/vnd.apache.thrift.binary"))));
}
use of net.morimekta.test.providence.client.Request in project providence by morimekta.
the class HttpClientHandlerTest method testSimpleRequest_exception.
@Test
public void testSimpleRequest_exception() throws IOException, Failure, TException {
TestService.Iface client = new TestService.Client(new HttpClientHandler(this::endpoint, factory(), provider, instrumentation));
when(impl.test(any(net.morimekta.test.thrift.client.Request.class))).thenThrow(new net.morimekta.test.thrift.client.Failure("failure"));
try {
client.test(new Request("request"));
fail("No exception");
} catch (Failure ex) {
assertThat(ex.getText(), is("failure"));
}
verify(impl).test(any(net.morimekta.test.thrift.client.Request.class));
verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
verifyNoMoreInteractions(impl, instrumentation);
}
use of net.morimekta.test.providence.client.Request in project providence by morimekta.
the class HttpClientHandlerNetworkTest method testSimpleRequest_connectionRefused_apacheHttpTransport.
@Test
public void testSimpleRequest_connectionRefused_apacheHttpTransport() throws IOException, Failure {
HttpRequestFactory factory = new ApacheHttpTransport().createRequestFactory();
GenericUrl url = new GenericUrl("http://localhost:" + (port - 10) + "/" + ENDPOINT);
TestService.Iface client = new TestService.Client(new HttpClientHandler(() -> url, factory, provider));
try {
client.test(new Request("request"));
fail("No exception");
} catch (HttpHostConnectException ex) {
assertThat(ex.getMessage(), allOf(startsWith("Connect to localhost:" + (port - 10) + " failed: "), containsString("Connection refused")));
}
}
use of net.morimekta.test.providence.client.Request in project providence by morimekta.
the class HttpClientHandlerTest method testSimple.
@Test
public void testSimple() throws IOException, TException, Failure {
TestService.Iface client = new TestService.Client(new HttpClientHandler(this::endpoint));
when(impl.test(any(net.morimekta.test.thrift.client.Request.class))).thenReturn(new net.morimekta.test.thrift.client.Response("response"));
Response response = client.test(new Request("request"));
waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).until(() -> contentTypes.size() > 0);
verify(impl).test(any(net.morimekta.test.thrift.client.Request.class));
verifyNoMoreInteractions(impl);
assertThat(response, is(equalToMessage(new Response("response"))));
assertThat(contentTypes, is(equalTo(ImmutableList.of("application/vnd.apache.thrift.binary"))));
}
Aggregations