Search in sources :

Example 61 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationInstanceIdTest method graphShouldNotOpenWithSameInstanceId.

@Disabled("Not working anymore. The bug is tracked here: https://github.com/JanusGraph/janusgraph/issues/2696")
@Test
public void graphShouldNotOpenWithSameInstanceId() {
    final Map<String, Object> map = getStorageConfiguration();
    map.put(UNIQUE_INSTANCE_ID.toStringWithoutRoot(), NON_UNIQUE_INSTANCE_ID);
    final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
    final StandardJanusGraph graph1 = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
    assertEquals(1, graph1.openManagement().getOpenInstances().size());
    assertEquals(NON_UNIQUE_CURRENT_INSTANCE_ID, graph1.openManagement().getOpenInstances().iterator().next());
    JanusGraphException janusGraphException = assertThrows(JanusGraphException.class, () -> {
        final StandardJanusGraph graph2 = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
        graph1.close();
    });
    assertEquals("A JanusGraph graph with the same instance id [" + NON_UNIQUE_INSTANCE_ID + "] is already open. Might required forced shutdown.", janusGraphException.getMessage());
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) JanusGraphException(org.janusgraph.core.JanusGraphException) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 62 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class StandardJanusGraphTxTest method createTxWithMockedInternals.

private StandardJanusGraphTx createTxWithMockedInternals() throws BackendException {
    StandardJanusGraph mockGraph = createMock(StandardJanusGraph.class);
    TransactionConfiguration txConfig = createMock(TransactionConfiguration.class);
    GraphDatabaseConfiguration gdbConfig = createMock(GraphDatabaseConfiguration.class);
    BackendTransaction txHandle = createMock(BackendTransaction.class);
    TimestampProvider tsProvider = createMock(TimestampProvider.class);
    Serializer mockSerializer = createMock(Serializer.class);
    EdgeSerializer mockEdgeSerializer = createMock(EdgeSerializer.class);
    IndexSerializer mockIndexSerializer = createMock(IndexSerializer.class);
    RelationType relationType = createMock(RelationType.class);
    IDManager idManager = createMock(IDManager.class);
    PropertyKey propertyKey = createMock(PropertyKey.class);
    DefaultSchemaMaker defaultSchemaMaker = createMock(DefaultSchemaMaker.class);
    IndexSelectionStrategy indexSelectionStrategy = createMock(ThresholdBasedIndexSelectionStrategy.class);
    expect(mockGraph.getConfiguration()).andReturn(gdbConfig);
    expect(mockGraph.isOpen()).andReturn(true).anyTimes();
    expect(mockGraph.getDataSerializer()).andReturn(mockSerializer);
    expect(mockGraph.getEdgeSerializer()).andReturn(mockEdgeSerializer);
    expect(mockGraph.getIndexSerializer()).andReturn(mockIndexSerializer);
    expect(mockGraph.getIDManager()).andReturn(idManager);
    expect(mockGraph.getIndexSelector()).andReturn(indexSelectionStrategy);
    mockGraph.closeTransaction(isA(StandardJanusGraphTx.class));
    EasyMock.expectLastCall().anyTimes();
    expect(gdbConfig.getTimestampProvider()).andReturn(tsProvider);
    expect(txConfig.isSingleThreaded()).andReturn(true);
    expect(txConfig.hasPreloadedData()).andReturn(false);
    expect(txConfig.hasVerifyExternalVertexExistence()).andReturn(false);
    expect(txConfig.hasVerifyInternalVertexExistence()).andReturn(false);
    expect(txConfig.getVertexCacheSize()).andReturn(6);
    expect(txConfig.isReadOnly()).andReturn(true);
    expect(txConfig.getDirtyVertexSize()).andReturn(2);
    expect(txConfig.getIndexCacheWeight()).andReturn(2L);
    expect(txConfig.getGroupName()).andReturn(null).anyTimes();
    expect(txConfig.getAutoSchemaMaker()).andReturn(defaultSchemaMaker);
    expect(defaultSchemaMaker.makePropertyKey(isA(PropertyKeyMaker.class), notNull())).andReturn(propertyKey);
    expect(relationType.isPropertyKey()).andReturn(false);
    expect(propertyKey.isPropertyKey()).andReturn(true);
    txHandle.rollback();
    EasyMock.expectLastCall().anyTimes();
    replayAll();
    StandardJanusGraphTx partialMock = createMockBuilder(StandardJanusGraphTx.class).withConstructor(mockGraph, txConfig).addMockedMethod("getRelationType").createMock();
    partialMock.setBackendTransaction(txHandle);
    expect(partialMock.getRelationType("Foo")).andReturn(null);
    expect(partialMock.getRelationType("Qux")).andReturn(propertyKey);
    expect(partialMock.getRelationType("Baz")).andReturn(relationType);
    replay(partialMock);
    return partialMock;
}
Also used : IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) IDManager(org.janusgraph.graphdb.idmanagement.IDManager) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) ThresholdBasedIndexSelectionStrategy(org.janusgraph.graphdb.query.index.ThresholdBasedIndexSelectionStrategy) IndexSelectionStrategy(org.janusgraph.graphdb.query.index.IndexSelectionStrategy) PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) DefaultSchemaMaker(org.janusgraph.core.schema.DefaultSchemaMaker) RelationType(org.janusgraph.core.RelationType) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) BackendTransaction(org.janusgraph.diskstorage.BackendTransaction) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) Serializer(org.janusgraph.graphdb.database.serialize.Serializer)

Example 63 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class StandardVertexTest method modifiedVertexShouldNotEvictedFromCache.

@Test
public void modifiedVertexShouldNotEvictedFromCache() {
    for (int i = 0; i < 50; i++) {
        try (StandardJanusGraph g = (StandardJanusGraph) JanusGraphFactory.build().set("storage.backend", "inmemory").set("cache.tx-cache-size", 0).open()) {
            Vertex v1 = g.traversal().addV().next();
            Vertex v2 = g.traversal().addV().next();
            v1.addEdge("E", v2);
            g.tx().commit();
            g.tx().close();
            for (int k = 0; k < 120; k++) {
                g.traversal().addV().next();
            }
            g.tx().commit();
            g.tx().close();
            g.traversal().E().drop().iterate();
            g.traversal().E().drop().iterate();
        }
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) RepeatedIfExceptionsTest(io.github.artsok.RepeatedIfExceptionsTest) Test(org.junit.jupiter.api.Test)

Example 64 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph 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)

Example 65 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class CQLConfigTest method shouldFailDueToSmallTimeout.

@Test
public void shouldFailDueToSmallTimeout() {
    try {
        WriteConfiguration wc = getConfiguration();
        wc.set(ConfigElement.getPath(REQUEST_TIMEOUT), 1);
        wc.set(ConfigElement.getPath(NETTY_TIMER_TICK_DURATION), 1);
        try (StandardJanusGraph graph = (StandardJanusGraph) JanusGraphFactory.open(wc)) {
            GraphTraversalSource graphTraversalSource = graph.traversal();
            for (int i = 0; i < 200; i++) {
                graphTraversalSource.addV().property("name", "world").property("age", 123).property("id", i);
            }
            graphTraversalSource.tx().commit();
            graphTraversalSource.V().has("id", P.lte(195)).valueMap().with(WithOptions.tokens, WithOptions.ids).toList();
            graphTraversalSource.tx().rollback();
        }
    // This test should fail, but it is very flaky, thus, we don't fail it even if we reached this point.
    // fail()
    } catch (Throwable throwable) {
    // the throwable is expected
    }
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)68 Test (org.junit.jupiter.api.Test)38 MapConfiguration (org.apache.commons.configuration2.MapConfiguration)25 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)18 GraphDatabaseConfigurationBuilder (org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder)18 HashMap (java.util.HashMap)13 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)9 Test (org.junit.Test)9 MapConfiguration (org.apache.commons.configuration.MapConfiguration)8 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)8 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)6 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)6 PropertyKey (org.janusgraph.core.PropertyKey)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Graph (org.apache.tinkerpop.gremlin.structure.Graph)4 Backend (org.janusgraph.diskstorage.Backend)4 WriteConfiguration (org.janusgraph.diskstorage.configuration.WriteConfiguration)4 TimestampProvider (org.janusgraph.diskstorage.util.time.TimestampProvider)4 StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)4 JanusGraph (org.janusgraph.core.JanusGraph)3