use of io.pravega.common.io.filesystem.FileModificationPollingMonitor in project pravega by pravega.
the class PravegaConnectionListenerTest method testUsesPollingMonitorForSymbolicLinks.
@Test
public void testUsesPollingMonitorForSymbolicLinks() {
String pathToCertificateFile = "../../../config/" + SecurityConfigDefaults.TLS_SERVER_CERT_FILE_NAME;
String pathToKeyFile = "../../../config/" + SecurityConfigDefaults.TLS_SERVER_PRIVATE_KEY_FILE_NAME;
@Cleanup PravegaConnectionListener listener = new PravegaConnectionListener(true, true, "whatever", -1, mock(StreamSegmentStore.class), mock(TableStore.class), SegmentStatsRecorder.noOp(), TableSegmentStatsRecorder.noOp(), new PassingTokenVerifier(), "dummy-tls-certificate-path", "dummy-tls-key-path", true, NoOpScheduledExecutor.get(), SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
AtomicReference<SslContext> dummySslCtx = new AtomicReference<>(null);
FileModificationMonitor monitor = listener.prepareCertificateMonitor(true, pathToCertificateFile, pathToKeyFile, dummySslCtx);
assertTrue("Unexpected type of FileModificationMonitor", monitor instanceof FileModificationPollingMonitor);
}
use of io.pravega.common.io.filesystem.FileModificationPollingMonitor in project pravega by pravega.
the class AbstractConnectionListener method prepareCertificateMonitor.
@VisibleForTesting
FileModificationMonitor prepareCertificateMonitor(boolean isTLSCertPathSymLink, String tlsCertificatePath, String tlsKeyPath, AtomicReference<SslContext> sslCtx) {
FileModificationMonitor result;
try {
if (isTLSCertPathSymLink) {
// For symbolic links, the event-based watcher doesn't work, so we use a polling monitor.
log.info("The path to certificate file [{}] was found to be a symbolic link, " + " so using [{}] to monitor for certificate changes", tlsCertificatePath, FileModificationPollingMonitor.class.getSimpleName());
result = new FileModificationPollingMonitor(Paths.get(tlsCertificatePath), new TLSConfigChangeFileConsumer(sslCtx, tlsCertificatePath, tlsKeyPath, tlsProtocolVersion));
} else {
// For non symbolic links we'll use the event-based watcher, which is more efficient than a
// polling-based monitor.
result = new FileModificationEventWatcher(Paths.get(tlsCertificatePath), new TLSConfigChangeEventConsumer(sslCtx, tlsCertificatePath, tlsKeyPath, tlsProtocolVersion));
}
return result;
} catch (FileNotFoundException e) {
log.error("Failed to prepare a monitor for the certificate at path [{}]", tlsCertificatePath, e);
throw new RuntimeException(e);
}
}
Aggregations