Java Code Examples for com.linecorp.armeria.common.util.Exceptions#clearTrace()

The following examples show how to use com.linecorp.armeria.common.util.Exceptions#clearTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThriftServiceTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@ArgumentsSource(SerializationFormatProvider.class)
void testSync_FileService_create_exception(SerializationFormat defaultSerializationFormat)
        throws Exception {
    final FileService.Client client = new FileService.Client.Factory().getClient(
            inProto(defaultSerializationFormat), outProto(defaultSerializationFormat));
    client.send_create(BAZ);
    assertThat(out.length()).isGreaterThan(0);

    final RuntimeException exception = Exceptions.clearTrace(new RuntimeException());
    final THttpService service = THttpService.of((FileService.Iface) path -> {
        throw exception;
    }, defaultSerializationFormat);

    invoke(service);

    try {
        client.recv_create();
        fail(TApplicationException.class.getSimpleName() + " not raised.");
    } catch (TApplicationException e) {
        assertThat(e.getType()).isEqualTo(TApplicationException.INTERNAL_ERROR);
        assertThat(e.getMessage()).contains(exception.toString());
    }
}
 
Example 2
Source File: ThriftServiceTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@ArgumentsSource(SerializationFormatProvider.class)
void testAsync_FileService_create_exception(SerializationFormat defaultSerializationFormat)
        throws Exception {
    final FileService.Client client = new FileService.Client.Factory().getClient(
            inProto(defaultSerializationFormat), outProto(defaultSerializationFormat));
    client.send_create(BAZ);
    assertThat(out.length()).isGreaterThan(0);

    final RuntimeException exception = Exceptions.clearTrace(new RuntimeException());
    final THttpService service = THttpService.of(
            (FileService.AsyncIface) (path, resultHandler) ->
                    resultHandler.onError(exception), defaultSerializationFormat);

    invoke(service);

    try {
        client.recv_create();
        fail(TApplicationException.class.getSimpleName() + " not raised.");
    } catch (TApplicationException e) {
        assertThat(e.getType()).isEqualTo(TApplicationException.INTERNAL_ERROR);
        assertThat(e.getMessage()).contains(exception.toString());
    }
}
 
Example 3
Source File: ThriftServiceTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@ArgumentsSource(SerializationFormatProvider.class)
void testIdentity_FileService_create_exception(SerializationFormat defaultSerializationFormat)
        throws Exception {
    final FileService.Client client = new FileService.Client.Factory().getClient(
            inProto(defaultSerializationFormat), outProto(defaultSerializationFormat));
    client.send_create(BAZ);
    assertThat(out.length()).isGreaterThan(0);

    final RuntimeException exception = Exceptions.clearTrace(new RuntimeException());
    final THttpService syncService = THttpService.of((FileService.Iface) path -> {
        throw exception;
    }, defaultSerializationFormat);

    final THttpService asyncService = THttpService.of(
            (FileService.AsyncIface) (path, resultHandler) ->
                    resultHandler.onError(exception), defaultSerializationFormat);

    invokeTwice(syncService, asyncService);

    assertThat(promise.get()).isEqualTo(promise2.get());
}
 
Example 4
Source File: GrpcStatusCauseTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
public void unaryCall(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
    final IllegalStateException e1 = new IllegalStateException("Exception 1");
    final IllegalArgumentException e2 = new IllegalArgumentException();
    final AssertionError e3 = new AssertionError("Exception 3");
    Exceptions.clearTrace(e3);
    final RuntimeException e4 = new RuntimeException("Exception 4");

    e1.initCause(e2);
    e2.initCause(e3);
    e3.initCause(e4);

    final Status status = Status.ABORTED.withCause(e1);
    responseObserver.onError(status.asRuntimeException());
}
 
Example 5
Source File: CircuitBreakerRpcClientTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Test
void testDelegateIfFailToGetCircuitBreaker() throws Exception {
    final RpcClient delegate = mock(RpcClient.class);
    when(delegate.execute(any(), any())).thenReturn(successRes);

    final CircuitBreakerMapping mapping = (ctx, req) -> {
        throw Exceptions.clearTrace(new AnticipatedException("bug!"));
    };
    final CircuitBreakerRpcClient stub = new CircuitBreakerRpcClient(delegate, mapping, rule());

    stub.execute(ctxA, reqA);

    // make sure that remote service is invoked even if cb mapping is failed
    verify(delegate, times(1)).execute(eq(ctxA), eq(reqA));
}
 
Example 6
Source File: ThriftServiceTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static FileServiceException newFileServiceException() {
    // Remove the stack trace so we do not pollute the build log.
    return Exceptions.clearTrace(new FileServiceException());
}