Search in sources :

Example 1 with Failure

use of net.morimekta.test.providence.service.Failure in project providence by morimekta.

the class ProvidenceServletTest method testSimpleRequest_exception.

@Test
public void testSimpleRequest_exception() throws IOException, Failure {
    AtomicBoolean called = new AtomicBoolean();
    when(impl.test(any(Request.class))).thenAnswer(i -> {
        called.set(true);
        throw Failure.builder().setText("failure").build();
    });
    TestService.Iface client = new TestService.Client(new HttpClientHandler(this::endpoint, factory(), provider));
    try {
        client.test(new Request("request"));
        fail("No exception");
    } catch (Failure ex) {
        assertEquals("failure", ex.getText());
    }
    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(instrumentation);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestService(net.morimekta.test.providence.service.TestService) PServiceCall(net.morimekta.providence.PServiceCall) HttpRequest(com.google.api.client.http.HttpRequest) Request(net.morimekta.test.providence.service.Request) HttpClientHandler(net.morimekta.providence.client.HttpClientHandler) Failure(net.morimekta.test.providence.service.Failure) Test(org.junit.Test)

Example 2 with Failure

use of net.morimekta.test.providence.service.Failure in project providence by morimekta.

the class ProvidenceServlet_ThriftClientTest method testThriftClient_failure.

@Test
public void testThriftClient_failure() throws TException, IOException, Failure {
    ApacheHttpTransport transport = new ApacheHttpTransport();
    THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
    TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
    net.morimekta.test.thrift.service.TestService.Iface client = new net.morimekta.test.thrift.service.TestService.Client(protocol);
    AtomicBoolean called = new AtomicBoolean();
    doAnswer(i -> {
        called.set(true);
        throw new Failure("test");
    }).when(impl).voidMethod(55);
    try {
        client.voidMethod(55);
    } catch (net.morimekta.test.thrift.service.Failure e) {
        assertEquals("test", e.getText());
    }
    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
    verify(impl).voidMethod(55);
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(impl, instrumentation);
}
Also used : TestService(net.morimekta.test.providence.service.TestService) THttpClient(org.apache.thrift.transport.THttpClient) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) PServiceCall(net.morimekta.providence.PServiceCall) ApacheHttpTransport(com.google.api.client.http.apache.ApacheHttpTransport) THttpClient(org.apache.thrift.transport.THttpClient) Failure(net.morimekta.test.providence.service.Failure) Test(org.junit.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 PServiceCall (net.morimekta.providence.PServiceCall)2 Failure (net.morimekta.test.providence.service.Failure)2 TestService (net.morimekta.test.providence.service.TestService)2 Test (org.junit.Test)2 HttpRequest (com.google.api.client.http.HttpRequest)1 ApacheHttpTransport (com.google.api.client.http.apache.ApacheHttpTransport)1 HttpClientHandler (net.morimekta.providence.client.HttpClientHandler)1 Request (net.morimekta.test.providence.service.Request)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 THttpClient (org.apache.thrift.transport.THttpClient)1