use of org.janusgraph.diskstorage.cql.CQLConfigOptions.HEARTBEAT_TIMEOUT in project janusgraph by JanusGraph.
the class CQLConfigTest method shouldGracefullyCloseGraphWhichLostAConnection.
@Test
public void shouldGracefullyCloseGraphWhichLostAConnection() {
WriteConfiguration wc = getConfiguration();
wc.set(ConfigElement.getPath(EXECUTOR_SERVICE_MAX_SHUTDOWN_WAIT_TIME), 60000);
wc.set(ConfigElement.getPath(PARALLEL_BACKEND_EXECUTOR_SERVICE_MAX_SHUTDOWN_WAIT_TIME), 60000);
wc.set(ConfigElement.getPath(IDS_RENEW_TIMEOUT), 10000);
wc.set(ConfigElement.getPath(CONNECTION_TIMEOUT), 10000);
wc.set(ConfigElement.getPath(HEARTBEAT_TIMEOUT), 10000);
if (graph != null && graph.isOpen()) {
graph.close();
}
Set<Thread> threadsFromPossibleOtherOpenedConnections = Thread.getAllStackTraces().keySet().stream().filter(thread -> {
String threadNameLowercase = thread.getName().toLowerCase();
return thread.isAlive() && (threadNameLowercase.startsWith("cql") || threadNameLowercase.startsWith("janusgraph"));
}).collect(Collectors.toSet());
boolean flakyTest = !threadsFromPossibleOtherOpenedConnections.isEmpty();
graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
assertDoesNotThrow(() -> {
graph.traversal().V().hasNext();
graph.tx().rollback();
});
Set<Thread> threadsToAwait = Thread.getAllStackTraces().keySet().stream().filter(thread -> {
String threadNameLowercase = thread.getName().toLowerCase();
return thread.isAlive() && !threadsFromPossibleOtherOpenedConnections.contains(thread) && (threadNameLowercase.startsWith("cql") || threadNameLowercase.startsWith("janusgraph"));
}).collect(Collectors.toSet());
cqlContainer.stop();
graph.close();
for (Thread thread : threadsToAwait) {
if (thread.isAlive()) {
if (flakyTest) {
log.warn("Test shouldGracefullyCloseGraphWhichLostAConnection is currently running in flaky mode " + "because there were open instances available before the test started. " + "Thus, we don't fail this test because we can't be sure that current thread {} " + "is leaked or were created by other JanusGraph instances.", thread.getName());
} else {
fail("Thread " + thread.getName() + " was alive but expected to be terminated");
}
}
}
}
Aggregations