Search in sources :

Example 31 with SafeRuntimeException

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

the class AllNodesDisabledNamespacesUpdaterTest method handlesNodesBecomingUnreachableDuringReEnable.

@Test
public void handlesNodesBecomingUnreachableDuringReEnable() {
    when(remote1.reenable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.reenable(any(), any())).thenThrow(new SafeRuntimeException("unreachable"));
    when(localUpdater.reEnable(any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    ReenableNamespacesRequest request = ReenableNamespacesRequest.of(BOTH_NAMESPACES, LOCK_ID);
    ReenableNamespacesResponse response = updater.reEnableOnAllNodes(AUTH_HEADER, request);
    assertThat(response).isEqualTo(partiallyLocked(ImmutableSet.of()));
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) UnsuccessfulReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulReenableNamespacesResponse) SuccessfulReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulReenableNamespacesResponse) ReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.ReenableNamespacesResponse) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) Test(org.junit.Test)

Example 32 with SafeRuntimeException

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

the class AllNodesDisabledNamespacesUpdaterTest method handlesNodesBecomingUnreachableDuringDisable.

@Test
public void handlesNodesBecomingUnreachableDuringDisable() {
    when(remote1.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote1.reenable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.disable(any(), any())).thenThrow(new SafeRuntimeException("unreachable"));
    when(remote2.reenable(any(), any())).thenThrow(new SafeRuntimeException("unreachable"));
    when(localUpdater.getNamespacesLockedWithDifferentLockId(any(), any())).thenReturn(ImmutableMap.of());
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(BOTH_NAMESPACES));
    // We don't know if the request succeeded or failed on remote2, so we should try our best to roll back
    verify(remote2).reenable(any(), any());
    verify(remote1).reenable(any(), any());
    // No known bad namespaces
    assertThat(response).isEqualTo(DISABLE_FAILED_SUCCESSFULLY);
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) Test(org.junit.Test)

Example 33 with SafeRuntimeException

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

the class CassandraClientFactory method destroyObject.

@Override
public void destroyObject(PooledObject<CassandraClient> client) {
    if (log.isDebugEnabled()) {
        log.debug("Attempting to close transport for client {} of host {}", UnsafeArg.of("client", client), SafeArg.of("cassandraClient", CassandraLogHelper.host(addr)));
    }
    try {
        TaskContext<Void> taskContext = TaskContext.createRunnable(() -> client.getObject().close(), () -> {
        });
        timedRunner.run(taskContext);
    } catch (Throwable t) {
        if (log.isDebugEnabled()) {
            log.debug("Failed to close transport for client {} of host {}", UnsafeArg.of("client", client), SafeArg.of("cassandraClient", CassandraLogHelper.host(addr)), t);
        }
        throw new SafeRuntimeException("Threw while attempting to close transport for client", t);
    }
    if (log.isDebugEnabled()) {
        log.debug("Closed transport for client {} of host {}", UnsafeArg.of("client", client), SafeArg.of("cassandraClient", CassandraLogHelper.host(addr)));
    }
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException)

Example 34 with SafeRuntimeException

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

the class InstrumentationTest method testThrowingHandler_failure_single.

@Test
@SuppressWarnings("unchecked")
void testThrowingHandler_failure_single() {
    InvocationEventHandler<InvocationContext> handler = Mockito.mock(InvocationEventHandler.class);
    when(handler.isEnabled()).thenReturn(true);
    when(handler.preInvocation(any(), any(), any())).thenThrow(new RuntimeException());
    Runnable wrapped = Instrumentation.builder(Runnable.class, () -> {
        throw new SafeRuntimeException("expected");
    }).withHandler(handler).build();
    assertThatCode(wrapped::run).isExactlyInstanceOf(SafeRuntimeException.class).hasMessage("expected");
    verify(handler).isEnabled();
    verify(handler).preInvocation(any(), any(), any());
    verify(handler).onFailure(isNull(), any());
}
Also used : SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) InvocationContext(com.palantir.tritium.event.InvocationContext) DefaultInvocationContext(com.palantir.tritium.event.DefaultInvocationContext) Test(org.junit.jupiter.api.Test)

Example 35 with SafeRuntimeException

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

the class DefaultCas method getTrustedCertificates.

private static Map<String, X509Certificate> getTrustedCertificates() {
    ImmutableMap.Builder<String, X509Certificate> certificateMap = ImmutableMap.builder();
    try {
        List<X509Certificate> caCertificates = KeyStores.readX509Certificates(new ByteArrayInputStream(Resources.toByteArray(Resources.getResource(CA_CERTIFICATES_CRT)))).stream().map(cert -> (X509Certificate) cert).collect(Collectors.toList());
        int index = 0;
        for (X509Certificate cert : caCertificates) {
            String certificateCommonName = cert.getSubjectX500Principal().getName().toLowerCase(Locale.ENGLISH);
            certificateMap.put(certificateCommonName, cert);
            log.debug("Adding CA certificate", SafeArg.of("certificateIndex", index), SafeArg.of("certificateCount", caCertificates.size()), SafeArg.of("certificateCommonName", certificateCommonName), SafeArg.of("expiry", cert.getNotAfter()), SafeArg.of("sha256Fingerprint", Hashing.sha256().hashBytes(cert.getEncoded()).toString()));
            index++;
        }
    } catch (CertificateException | IOException e) {
        throw new SafeRuntimeException("Could not read file as an X.509 certificate", e);
    }
    return certificateMap.build();
}
Also used : X509Certificate(java.security.cert.X509Certificate) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) ImmutableMap(com.google.common.collect.ImmutableMap) Resources(com.google.common.io.Resources) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) Hashing(com.google.common.hash.Hashing) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) SafeLogger(com.palantir.logsafe.logger.SafeLogger) SafeArg(com.palantir.logsafe.SafeArg) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) Map(java.util.Map) Suppliers(com.google.common.base.Suppliers) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) X509Certificate(java.security.cert.X509Certificate)

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