Search in sources :

Example 36 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.

the class DialogueRequestAnnotationsProcessorTest method assertContentsMatch.

private void assertContentsMatch(JavaFileObject javaFileObject, String generatedClassFile) {
    try {
        Path output = RESOURCES_BASE_DIR.resolve(generatedClassFile + ".generated");
        String generatedContents = readJavaFileObject(javaFileObject);
        if (DEV_MODE) {
            Files.deleteIfExists(output);
            Files.write(output, generatedContents.getBytes(StandardCharsets.UTF_8));
        }
        assertThat(generatedContents).isEqualTo(readFromFile(output));
    } catch (IOException e) {
        throw new SafeRuntimeException(e);
    }
}
Also used : UnparseableHttpPath(com.palantir.myservice.service.UnparseableHttpPath) Path(java.nio.file.Path) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) IOException(java.io.IOException)

Example 37 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project foundry-athena-query-federation-connector by palantir.

the class S3Spiller method makeSpillLocation.

private S3SpillLocation makeSpillLocation() {
    S3SpillLocation splitSpillLocation = (S3SpillLocation) spillConfig.getSpillLocation();
    if (!splitSpillLocation.isDirectory()) {
        throw new SafeRuntimeException("Split's SpillLocation must be a directory because multiple blocks may be spilled.");
    }
    String blockKey = splitSpillLocation.getKey() + "." + spillNumber.getAndIncrement();
    return new S3SpillLocation(splitSpillLocation.getBucket(), blockKey, false);
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) S3SpillLocation(com.amazonaws.athena.connector.lambda.domain.spill.S3SpillLocation)

Example 38 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project tracing-java by palantir.

the class TracersTest method testWrapFuture_throws.

@Test
public void testWrapFuture_throws() {
    List<Span> observed = new ArrayList<>();
    Tracer.subscribe("futureTest", observed::add);
    try {
        String operationName = "testOperation";
        assertThatThrownBy(() -> Tracers.wrapListenableFuture(operationName, () -> {
            // wild so we must handle them properly.
            throw new SafeRuntimeException("initial operation failure");
        })).isInstanceOf(SafeRuntimeException.class).hasMessage("initial operation failure");
        assertThat(observed).hasSize(1);
        assertThat(observed.get(0)).extracting(Span::getOperation).isEqualTo(operationName);
        assertThat(observed).allSatisfy(span -> assertThat(span).extracting(Span::getTraceId).isEqualTo("defaultTraceId"));
    } finally {
        Tracer.unsubscribe("futureTest");
    }
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) OpenSpan(com.palantir.tracing.api.OpenSpan) Span(com.palantir.tracing.api.Span) Test(org.junit.Test)

Example 39 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project conjure-java-runtime-api by palantir.

the class ServiceExceptionTest method testErrorIdsAreInheritedFromServiceExceptions.

@Test
public void testErrorIdsAreInheritedFromServiceExceptions() {
    ServiceException rootCause = new ServiceException(ERROR);
    SafeRuntimeException intermediate = new SafeRuntimeException("Handled an exception", rootCause);
    ServiceException parent = new ServiceException(ERROR, intermediate);
    assertThat(parent.getErrorInstanceId()).isEqualTo(rootCause.getErrorInstanceId());
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) Test(org.junit.jupiter.api.Test)

Example 40 with SafeRuntimeException

use of com.palantir.logsafe.exceptions.SafeRuntimeException in project dialogue by palantir.

the class RetryingChannelTest method doesNotRetryRuntimeException.

@Test
public void doesNotRetryRuntimeException() {
    when(channel.execute(any())).thenReturn(Futures.immediateFailedFuture(new SafeRuntimeException("bug"))).thenReturn(SUCCESS);
    EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 1, Duration.ZERO, ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
    ListenableFuture<Response> response = retryer.execute(REQUEST);
    assertThatThrownBy(response::get).hasRootCauseExactlyInstanceOf(SafeRuntimeException.class).hasRootCauseMessage("bug");
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) EndpointChannel(com.palantir.dialogue.EndpointChannel) Test(org.junit.jupiter.api.Test)

Aggregations

SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)43 IOException (java.io.IOException)13 Test (org.junit.jupiter.api.Test)7 Path (java.nio.file.Path)6 Response (com.palantir.dialogue.Response)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 TestResponse (com.palantir.dialogue.TestResponse)3 DefaultInvocationContext (com.palantir.tritium.event.DefaultInvocationContext)3 InvocationContext (com.palantir.tritium.event.InvocationContext)3 File (java.io.File)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Value (com.palantir.atlasdb.keyvalue.api.Value)2 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)2 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)2 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)2 Channel (com.palantir.dialogue.Channel)2