Search in sources :

Example 31 with StandardJanusGraph

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

the class GraphDatabaseConfigurationInstanceExecutorServiceTest method shouldCreateCustomBackendExecutorServiceWithoutExecutorServiceConfigurationConstructor.

@Test
public void shouldCreateCustomBackendExecutorServiceWithoutExecutorServiceConfigurationConstructor() {
    final Map<String, Object> map = getStorageConfiguration();
    map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true);
    map.put(PARALLEL_BACKEND_OPS.toStringWithoutRoot(), true);
    map.put(PARALLEL_BACKEND_EXECUTOR_SERVICE_CLASS.toStringWithoutRoot(), CustomParameterlessExecutorServiceImplementation.class.getName());
    final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
    assertDoesNotThrow(() -> {
        final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
        graph.traversal().V().hasNext();
        graph.close();
    });
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 32 with StandardJanusGraph

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

the class GraphDatabaseConfigurationInstanceExecutorServiceTest method shouldCreateCustomBackendExecutorServiceWithoutBothExecutorServiceConfigurationConstructors.

@Test
public void shouldCreateCustomBackendExecutorServiceWithoutBothExecutorServiceConfigurationConstructors() {
    final Map<String, Object> map = getStorageConfiguration();
    map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true);
    map.put(PARALLEL_BACKEND_OPS.toStringWithoutRoot(), true);
    map.put(PARALLEL_BACKEND_EXECUTOR_SERVICE_CORE_POOL_SIZE.toStringWithoutRoot(), 15);
    map.put(PARALLEL_BACKEND_EXECUTOR_SERVICE_CLASS.toStringWithoutRoot(), CustomExecutorServiceWithBothConstructorsImplementation.class.getName());
    final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
    assertDoesNotThrow(() -> {
        final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
        graph.traversal().V().hasNext();
        graph.close();
    });
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 33 with StandardJanusGraph

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

the class JanusGraphTest method testIndexShouldRegisterWhenWeRemoveAnInstance.

@Tag(TestCategory.BRITTLE_TESTS)
@Test
public void testIndexShouldRegisterWhenWeRemoveAnInstance() throws InterruptedException {
    clopen(option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250));
    StandardJanusGraph graph2 = (StandardJanusGraph) JanusGraphFactory.open(config);
    JanusGraphTransaction tx2;
    mgmt.makePropertyKey("name").dataType(String.class).make();
    finishSchema();
    tx.addVertex("name", "v1");
    newTx();
    evaluateQuery(tx.query().has("name", "v1"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
    tx2 = graph2.newTransaction();
    evaluateQuery(tx2.query().has("name", "v1"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
    // Leave tx2 open to delay acknowledgement
    mgmt.buildIndex("theIndex", Vertex.class).addKey(mgmt.getPropertyKey("name")).buildCompositeIndex();
    mgmt.commit();
    JanusGraphTransaction tx3 = graph2.newTransaction();
    tx3.addVertex("name", "v2");
    tx3.commit();
    newTx();
    tx.addVertex("name", "v3");
    tx.commit();
    finishSchema();
    assertThrows(IllegalArgumentException.class, () -> mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX));
    finishSchema();
    // close second graph instance, so index can move to REGISTERED
    Set<String> openInstances = mgmt.getOpenInstances();
    assertEquals(2, openInstances.size());
    assertTrue(openInstances.contains(graph.getConfiguration().getUniqueGraphId() + "(current)"));
    assertTrue(openInstances.contains(graph2.getConfiguration().getUniqueGraphId()));
    assertThrows(IllegalArgumentException.class, () -> mgmt.forceCloseInstance(graph.getConfiguration().getUniqueGraphId()));
    mgmt.forceCloseInstance(graph2.getConfiguration().getUniqueGraphId());
    mgmt.commit();
    assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "theIndex").status(SchemaStatus.REGISTERED).timeout(TestGraphConfigs.getSchemaConvergenceTime(ChronoUnit.SECONDS), ChronoUnit.SECONDS).call().getSucceeded());
    finishSchema();
    mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX);
    finishSchema();
}
Also used : JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 34 with StandardJanusGraph

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

the class ConfiguredGraphFactoryTest method shouldCreateTwoGraphsUsingSameTemplateConfiguration.

@Test
public void shouldCreateTwoGraphsUsingSameTemplateConfiguration() throws Exception {
    try {
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph1 = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
        final StandardJanusGraph graph2 = (StandardJanusGraph) ConfiguredGraphFactory.create("graph2");
        assertNotNull(graph1);
        assertNotNull(graph2);
        assertEquals("graph1", graph1.getConfiguration().getConfiguration().get(GRAPH_NAME));
        assertEquals("graph2", graph2.getConfiguration().getConfiguration().get(GRAPH_NAME));
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.removeConfiguration("graph2");
        ConfiguredGraphFactory.close("graph1");
        ConfiguredGraphFactory.close("graph2");
    }
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 35 with StandardJanusGraph

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

the class ConfiguredGraphFactoryTest method updateConfigurationShouldRemoveGraphFromCache.

@Test
public void updateConfigurationShouldRemoveGraphFromCache() throws Exception {
    try {
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        map.put(GRAPH_NAME.toStringWithoutRoot(), "graph1");
        ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
        assertNotNull(graph);
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "bogusBackend");
        ConfiguredGraphFactory.updateConfiguration("graph1", new MapConfiguration(map));
        assertNull(gm.getGraph("graph1"));
        // we should throw an error since the config has been updated and we are attempting
        // to open a bogus backend
        thrown.expect(IllegalArgumentException.class);
        thrown.expectMessage(equalTo("Could not find implementation class: bogusBackend"));
        final StandardJanusGraph graph2 = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

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