Search in sources :

Example 1 with CONNECTION_TIMEOUT

use of org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CONNECTION_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");
            }
        }
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) JanusGraphConstants(org.janusgraph.graphdb.configuration.JanusGraphConstants) NETTY_TIMER_TICK_DURATION(org.janusgraph.diskstorage.cql.CQLConfigOptions.NETTY_TIMER_TICK_DURATION) METADATA_TOKEN_MAP_ENABLED(org.janusgraph.diskstorage.cql.CQLConfigOptions.METADATA_TOKEN_MAP_ENABLED) ROOT_NS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ROOT_NS) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) REQUEST_TRACKER_CLASS(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_TRACKER_CLASS) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Duration(java.time.Duration) EXECUTOR_SERVICE_CLASS(org.janusgraph.diskstorage.cql.CQLConfigOptions.EXECUTOR_SERVICE_CLASS) REQUEST_TIMEOUT(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_TIMEOUT) P(org.apache.tinkerpop.gremlin.process.traversal.P) MethodSource(org.junit.jupiter.params.provider.MethodSource) KEYSPACE(org.janusgraph.diskstorage.cql.CQLConfigOptions.KEYSPACE) RESOURCE_CONFIGURATION(org.janusgraph.diskstorage.cql.CQLConfigOptions.RESOURCE_CONFIGURATION) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) READ_CONSISTENCY(org.janusgraph.diskstorage.cql.CQLConfigOptions.READ_CONSISTENCY) STRING_CONFIGURATION(org.janusgraph.diskstorage.cql.CQLConfigOptions.STRING_CONFIGURATION) Set(java.util.Set) REQUEST_LOGGER_SHOW_STACK_TRACES(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_LOGGER_SHOW_STACK_TRACES) SESSION_LEAK_THRESHOLD(org.janusgraph.diskstorage.cql.CQLConfigOptions.SESSION_LEAK_THRESHOLD) WithOptions(org.apache.tinkerpop.gremlin.process.traversal.step.util.WithOptions) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) REQUEST_LOGGER_SUCCESS_ENABLED(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_LOGGER_SUCCESS_ENABLED) Stream(java.util.stream.Stream) CONNECTION_TIMEOUT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CONNECTION_TIMEOUT) PARALLEL_BACKEND_EXECUTOR_SERVICE_MAX_SHUTDOWN_WAIT_TIME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.PARALLEL_BACKEND_EXECUTOR_SERVICE_MAX_SHUTDOWN_WAIT_TIME) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) EXECUTOR_SERVICE_MAX_SHUTDOWN_WAIT_TIME(org.janusgraph.diskstorage.cql.CQLConfigOptions.EXECUTOR_SERVICE_MAX_SHUTDOWN_WAIT_TIME) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) BASE_PROGRAMMATIC_CONFIGURATION_ENABLED(org.janusgraph.diskstorage.cql.CQLConfigOptions.BASE_PROGRAMMATIC_CONFIGURATION_ENABLED) RequestLogger(com.datastax.oss.driver.internal.core.tracker.RequestLogger) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) REQUEST_LOGGER_SLOW_ENABLED(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_LOGGER_SLOW_ENABLED) STORAGE_PORT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_PORT) INITIAL_STORAGE_VERSION(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INITIAL_STORAGE_VERSION) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) REQUEST_LOGGER_SHOW_VALUES(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_LOGGER_SHOW_VALUES) ExecutorServiceBuilder(org.janusgraph.diskstorage.configuration.ExecutorServiceBuilder) REQUEST_LOGGER_MAX_QUERY_LENGTH(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_LOGGER_MAX_QUERY_LENGTH) METADATA_SCHEMA_ENABLED(org.janusgraph.diskstorage.cql.CQLConfigOptions.METADATA_SCHEMA_ENABLED) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) Charset(java.nio.charset.Charset) FILE_CONFIGURATION(org.janusgraph.diskstorage.cql.CQLConfigOptions.FILE_CONFIGURATION) STORAGE_HOSTS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_HOSTS) WRITE_CONSISTENCY(org.janusgraph.diskstorage.cql.CQLConfigOptions.WRITE_CONSISTENCY) URL_CONFIGURATION(org.janusgraph.diskstorage.cql.CQLConfigOptions.URL_CONFIGURATION) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JanusGraphCassandraContainer(org.janusgraph.JanusGraphCassandraContainer) Container(org.testcontainers.junit.jupiter.Container) REQUEST_LOGGER_MAX_VALUE_LENGTH(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_LOGGER_MAX_VALUE_LENGTH) Logger(org.slf4j.Logger) REQUEST_LOGGER_SLOW_THRESHOLD(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_LOGGER_SLOW_THRESHOLD) Configuration(org.janusgraph.diskstorage.configuration.Configuration) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) LOCAL_DATACENTER(org.janusgraph.diskstorage.cql.CQLConfigOptions.LOCAL_DATACENTER) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) REQUEST_LOGGER_ERROR_ENABLED(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_LOGGER_ERROR_ENABLED) REQUEST_LOGGER_MAX_VALUES(org.janusgraph.diskstorage.cql.CQLConfigOptions.REQUEST_LOGGER_MAX_VALUES) CQLProgrammaticConfigurationLoaderBuilder(org.janusgraph.diskstorage.cql.builder.CQLProgrammaticConfigurationLoaderBuilder) File(java.io.File) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ChronoUnit(java.time.temporal.ChronoUnit) PARTITIONER_NAME(org.janusgraph.diskstorage.cql.CQLConfigOptions.PARTITIONER_NAME) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) IDS_RENEW_TIMEOUT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.IDS_RENEW_TIMEOUT) Collections(java.util.Collections) HEARTBEAT_TIMEOUT(org.janusgraph.diskstorage.cql.CQLConfigOptions.HEARTBEAT_TIMEOUT) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)1 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)1 RequestLogger (com.datastax.oss.driver.internal.core.tracker.RequestLogger)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Charset (java.nio.charset.Charset)1 Duration (java.time.Duration)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Collections (java.util.Collections)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 FileUtils (org.apache.commons.io.FileUtils)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)1 WithOptions (org.apache.tinkerpop.gremlin.process.traversal.step.util.WithOptions)1 JanusGraphCassandraContainer (org.janusgraph.JanusGraphCassandraContainer)1 JanusGraphFactory (org.janusgraph.core.JanusGraphFactory)1 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)1