use of net.morimekta.test.providence.client.Request in project providence by morimekta.
the class HttpClientHandlerNetworkTest method testBrokenPipe_ApacheHttpTransport.
@Test
public void testBrokenPipe_ApacheHttpTransport() throws IOException, Failure {
HttpRequestFactory factory = new ApacheHttpTransport().createRequestFactory();
TestService.Iface client = new TestService.Client(new HttpClientHandler(this::endpoint, factory, provider));
try {
// The request must be larger than the socket read buffer, to force it to fail the write to socket.
client.test(new Request(Strings.times("request ", 1024 * 1024)));
fail("No exception");
} catch (SocketException ex) {
// TODO: This should be a HttpResponseException
assertThat(ex.getMessage().toLowerCase(Locale.US), anyOf(containsString("broken pipe"), containsString("write error"), containsString("write failed"), containsString("connection reset")));
}
}
use of net.morimekta.test.providence.client.Request in project providence by morimekta.
the class HttpClientHandlerNetworkTest method testSimpleRequest_connectionRefused_netHttpTransport.
@Test
public void testSimpleRequest_connectionRefused_netHttpTransport() throws IOException, Failure {
HttpRequestFactory factory = new NetHttpTransport().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 HttpClientHandlerNetworkTest method testBrokenPipe_NetHttpTransport.
@Test
public void testBrokenPipe_NetHttpTransport() throws Failure {
HttpRequestFactory factory = new NetHttpTransport().createRequestFactory();
TestService.Iface client = new TestService.Client(new HttpClientHandler(this::endpoint, factory, provider));
try {
// The request must be larger than the socket read buffer, to force it to fail the write to socket.
client.test(new Request(Strings.times("request ", 1024 * 1024)));
fail("No exception");
} catch (HttpResponseException e) {
fail("When did this become a HttpResponseException?");
} catch (IOException ex) {
// TODO: This should be a HttpResponseException
assertThat(ex.getMessage(), is("Error writing request body to server"));
}
}
use of net.morimekta.test.providence.client.Request in project providence by morimekta.
the class HttpClientHandlerTest method testSimpleRequest_404_notFound.
@Test
public void testSimpleRequest_404_notFound() throws IOException, Failure, TException {
TestService.Iface client = new TestService.Client(new HttpClientHandler(this::notfound, factory(), provider, instrumentation));
try {
client.test(new Request("request"));
fail("No exception");
} catch (HttpResponseException ex) {
assertThat(ex.getStatusCode(), is(404));
assertThat(ex.getStatusMessage(), is("Not Found"));
}
verify(instrumentation).onTransportException(any(HttpResponseException.class), anyDouble(), any(PServiceCall.class), isNull());
verifyNoMoreInteractions(impl, instrumentation);
}
use of net.morimekta.test.providence.client.Request in project providence by morimekta.
the class HttpClientHandlerTest method testSimpleRequest_405_notSupported.
@Test
public void testSimpleRequest_405_notSupported() throws IOException, Failure, TException {
GenericUrl url = endpoint();
url.setRawPath("/does_not_exists");
TestService.Iface client = new TestService.Client(new HttpClientHandler(() -> url, factory(), provider, instrumentation));
try {
client.test(new Request("request"));
fail("No exception");
} catch (HttpResponseException ex) {
assertThat(ex.getStatusCode(), is(405));
assertThat(ex.getStatusMessage(), is("HTTP method POST is not supported by this URL"));
}
verify(instrumentation).onTransportException(any(HttpResponseException.class), anyDouble(), any(PServiceCall.class), isNull());
verifyNoMoreInteractions(impl, instrumentation);
}
Aggregations