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()));
}
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);
}
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)));
}
}
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());
}
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();
}
Aggregations