Search in sources :

Example 46 with StandardJanusGraph

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

the class ConfigurationManagementGraphTest method shouldReindexIfPropertyKeyExists.

@Test
public void shouldReindexIfPropertyKeyExists() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
    final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
    final String propertyKeyName = "Created_Using_Template";
    final Class dataType = Boolean.class;
    JanusGraphManagement management = graph.openManagement();
    management.makePropertyKey(propertyKeyName).dataType(dataType).make();
    management.commit();
    // Instantiate the ConfigurationManagementGraph Singleton
    // This is purposefully done after a property key is created to ensure that a REDINDEX is initiated
    new ConfigurationManagementGraph(graph);
    management = graph.openManagement();
    final JanusGraphIndex index = management.getGraphIndex("Created_Using_Template_Index");
    final PropertyKey propertyKey = management.getPropertyKey("Created_Using_Template");
    assertNotNull(index);
    assertNotNull(propertyKey);
    assertEquals(ENABLED, index.getIndexStatus(propertyKey));
    management.commit();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 47 with StandardJanusGraph

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

the class ConfigurationManagementGraphTest method shouldCloseAllTxsIfIndexExists.

@Test
public void shouldCloseAllTxsIfIndexExists() {
    final StandardJanusGraph graph = (StandardJanusGraph) JanusGraphFactory.open("inmemory");
    // Emulate ConfigurationManagementGraph indices already exists
    JanusGraphManagement management = graph.openManagement();
    PropertyKey key = management.makePropertyKey("some_property").dataType(String.class).make();
    management.buildIndex("Created_Using_Template_Index", Vertex.class).addKey(key).buildCompositeIndex();
    management.buildIndex("Template_Index", Vertex.class).addKey(key).buildCompositeIndex();
    management.buildIndex("Graph_Name_Index", Vertex.class).addKey(key).buildCompositeIndex();
    management.commit();
    new ConfigurationManagementGraph(graph);
    assertEquals(0, graph.getOpenTransactions().size());
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 48 with StandardJanusGraph

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

the class EnsureCacheTest method NopTest.

@Test
public void NopTest() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
    final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
    graph.traversal().addV().iterate();
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) HashMap(java.util.HashMap) 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 49 with StandardJanusGraph

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

the class JanusGraphServerTest method testGremlinServerIsCorrectlyLoadedWithExpectedGraphs.

@Test
public void testGremlinServerIsCorrectlyLoadedWithExpectedGraphs() {
    final JanusGraphServer server = new JanusGraphServer("src/test/resources/janusgraph-server-with-serializers.yaml");
    CompletableFuture<Void> start = server.start();
    assertFalse(start.isCompletedExceptionally());
    GremlinServer gremlinServer = server.getGremlinServer();
    StandardJanusGraph graph = (StandardJanusGraph) gremlinServer.getServerGremlinExecutor().getGraphManager().getGraph("graph");
    assertNotNull(graph);
    CompletableFuture<Void> stop = server.stop();
    CompletableFuture.allOf(start, stop).join();
}
Also used : GremlinServer(org.apache.tinkerpop.gremlin.server.GremlinServer) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 50 with StandardJanusGraph

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

the class JanusGraphTest method testIndexUpdateSyncWithMultipleInstances.

@Tag(TestCategory.BRITTLE_TESTS)
@Test
public void testIndexUpdateSyncWithMultipleInstances() 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();
    try {
        mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX);
        // Open tx2 should not make this possible
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    finishSchema();
    // Release transaction and wait a little for registration which should make enabling possible
    tx2.commit();
    mgmt.rollback();
    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();
    tx2 = graph2.newTransaction();
    // Should be added to index but index not yet enabled
    tx2.addVertex("name", "v4");
    tx2.commit();
    newTx();
    evaluateQuery(tx.query().has("name", "v1"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("name", "v2"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("name", "v3"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("name", "v4"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    tx2 = graph2.newTransaction();
    evaluateQuery(tx2.query().has("name", "v1"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx2.query().has("name", "v2"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx2.query().has("name", "v3"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx2.query().has("name", "v4"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    tx2.commit();
    // Finally test retrieving and closing open instances
    Set<String> openInstances = mgmt.getOpenInstances();
    assertEquals(2, openInstances.size());
    assertTrue(openInstances.contains(graph.getConfiguration().getUniqueGraphId() + "(current)"));
    assertTrue(openInstances.contains(graph2.getConfiguration().getUniqueGraphId()));
    try {
        mgmt.forceCloseInstance(graph.getConfiguration().getUniqueGraphId());
        // Cannot close current instance
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    mgmt.forceCloseInstance(graph2.getConfiguration().getUniqueGraphId());
    graph2.close();
}
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)

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