Search in sources :

Example 1 with Request

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")));
    }
}
Also used : SocketException(java.net.SocketException) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) TestService(net.morimekta.test.providence.client.TestService) Request(net.morimekta.test.providence.client.Request) ApacheHttpTransport(com.google.api.client.http.apache.ApacheHttpTransport) Test(org.junit.Test)

Example 2 with Request

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")));
    }
}
Also used : HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) TestService(net.morimekta.test.providence.client.TestService) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) Request(net.morimekta.test.providence.client.Request) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) GenericUrl(com.google.api.client.http.GenericUrl) Test(org.junit.Test)

Example 3 with Request

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"));
    }
}
Also used : HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) TestService(net.morimekta.test.providence.client.TestService) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) Request(net.morimekta.test.providence.client.Request) HttpResponseException(com.google.api.client.http.HttpResponseException) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with Request

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);
}
Also used : TestService(net.morimekta.test.providence.client.TestService) PServiceCall(net.morimekta.providence.PServiceCall) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(net.morimekta.test.providence.client.Request) HttpResponseException(com.google.api.client.http.HttpResponseException) Test(org.junit.Test)

Example 5 with Request

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);
}
Also used : TestService(net.morimekta.test.providence.client.TestService) PServiceCall(net.morimekta.providence.PServiceCall) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(net.morimekta.test.providence.client.Request) HttpResponseException(com.google.api.client.http.HttpResponseException) GenericUrl(com.google.api.client.http.GenericUrl) Test(org.junit.Test)

Aggregations

Request (net.morimekta.test.providence.client.Request)10 TestService (net.morimekta.test.providence.client.TestService)10 Test (org.junit.Test)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 PServiceCall (net.morimekta.providence.PServiceCall)5 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)4 GenericUrl (com.google.api.client.http.GenericUrl)3 HttpResponseException (com.google.api.client.http.HttpResponseException)3 ApacheHttpTransport (com.google.api.client.http.apache.ApacheHttpTransport)2 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Response (net.morimekta.test.providence.client.Response)2 HttpHostConnectException (org.apache.http.conn.HttpHostConnectException)2 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 PApplicationException (net.morimekta.providence.PApplicationException)1 SerializerException (net.morimekta.providence.serializer.SerializerException)1 Failure (net.morimekta.test.providence.client.Failure)1