Search in sources :

Example 1 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project grakn by graknlabs.

the class TxFactoryJanusTest method testSingleton.

@Test
public void testSingleton() {
    when(session.keyspace()).thenReturn(Keyspace.of("anothertest"));
    TxFactoryJanus factory = new TxFactoryJanus(session);
    GraknTxJanus mg1 = factory.open(GraknTxType.BATCH);
    JanusGraph tinkerGraphMg1 = mg1.getTinkerPopGraph();
    mg1.close();
    GraknTxJanus mg2 = factory.open(GraknTxType.WRITE);
    JanusGraph tinkerGraphMg2 = mg2.getTinkerPopGraph();
    mg2.close();
    GraknTxJanus mg3 = factory.open(GraknTxType.BATCH);
    assertEquals(mg1, mg3);
    assertEquals(tinkerGraphMg1, mg3.getTinkerPopGraph());
    assertTrue(mg1.isBatchTx());
    assertFalse(mg2.isBatchTx());
    assertNotEquals(mg1, mg2);
    assertNotEquals(tinkerGraphMg1, tinkerGraphMg2);
    StandardJanusGraph standardJanusGraph1 = (StandardJanusGraph) tinkerGraphMg1;
    StandardJanusGraph standardJanusGraph2 = (StandardJanusGraph) tinkerGraphMg2;
    assertTrue(standardJanusGraph1.getConfiguration().isBatchLoading());
    assertFalse(standardJanusGraph2.getConfiguration().isBatchLoading());
}
Also used : GraknTxJanus(ai.grakn.kb.internal.GraknTxJanus) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraph(org.janusgraph.core.JanusGraph) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 2 with StandardJanusGraph

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

the class JanusGraphStepStrategyTest method generateTestParameters.

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> generateTestParameters() {
    final StandardJanusGraph graph = (StandardJanusGraph) StorageSetup.getInMemoryGraph();
    final GraphTraversalSource g = graph.traversal();
    // create a basic schema so that order pushdown can be tested as this optimization requires a JanusGraph
    // transaction registered against a non-EmptyGraph
    final JanusGraphManagement mgmt = graph.openManagement();
    mgmt.makePropertyKey("name").dataType(String.class).make();
    mgmt.makePropertyKey("lang").dataType(String.class).make();
    mgmt.commit();
    return Arrays.asList(new Object[][] { { g.V().out(), g_V().out(), Collections.emptyList() }, { g.V().has("name", "marko").out(), g_V("name", eq("marko")).out(), Collections.emptyList() }, { g.V().has("name", "marko").has("age", gt(31).and(lt(10))).out(), g_V("name", eq("marko"), "age", gt(31), "age", lt(10)).out(), Collections.emptyList() }, { g.V().has("name", "marko").or(has("age"), has("age", gt(32))).has("lang", "java"), g_V("name", eq("marko"), "lang", eq("java")).or(has("age"), has("age", gt(32))), Collections.singletonList(FilterRankingStrategy.instance()) }, { g.V().has("name", "marko").as("a").or(has("age"), has("age", gt(32))).has("lang", "java"), g_V("name", eq("marko")).as("a").or(has("age"), has("age", gt(32))).has("lang", "java"), Collections.emptyList() }, { g.V().has("name", "marko").as("a").or(has("age"), has("age", gt(32))).has("lang", "java"), g_V("name", eq("marko"), "lang", eq("java")).or(has("age"), has("age", gt(32))).as("a"), Collections.singletonList(FilterRankingStrategy.instance()) }, { g.V().dedup().has("name", "marko").or(has("age"), has("age", gt(32))).has("lang", "java"), g_V("name", eq("marko"), "lang", eq("java")).or(has("age"), has("age", gt(32))).dedup(), Collections.singletonList(FilterRankingStrategy.instance()) }, { g.V().as("a").dedup().has("name", "marko").or(has("age"), has("age", gt(32))).has("lang", "java"), g_V("name", eq("marko"), "lang", eq("java")).or(has("age"), has("age", gt(32))).dedup().as("a"), Collections.singletonList(FilterRankingStrategy.instance()) }, { g.V().as("a").has("name", "marko").as("b").or(has("age"), has("age", gt(32))).has("lang", "java"), g_V("name", eq("marko"), "lang", eq("java")).or(has("age"), has("age", gt(32))).as("b", "a"), Collections.singletonList(FilterRankingStrategy.instance()) }, { g.V().as("a").dedup().has("name", "marko").or(has("age"), has("age", gt(32))).filter(has("name", "bob")).has("lang", "java"), g_V("name", eq("marko"), "lang", eq("java"), "name", eq("bob")).or(has("age"), has("age", gt(32))).dedup().as("a"), Arrays.asList(InlineFilterStrategy.instance(), FilterRankingStrategy.instance()) }, { g.V().has("name", "marko").or(not(has("age")), has("age", gt(32))).has("name", "bob").has("lang", "java"), g_V("name", eq("marko"), "name", eq("bob"), "lang", eq("java")).or(not(filter(properties("age"))), has("age", gt(32))), TraversalStrategies.GlobalCache.getStrategies(JanusGraph.class).toList() }, { g.V().has("name", eq("marko").and(eq("bob").and(eq("stephen")))).out("knows"), g_V("name", eq("marko"), "name", eq("bob"), "name", eq("stephen")).out("knows"), Collections.emptyList() }, { g.V().hasId(1), g_V(T.id, 1), Collections.emptyList() }, { g.V().hasId(within(1, 2)), g_V(T.id, 1, T.id, 2), Collections.emptyList() }, { g.V().hasId(1).has("name", "marko"), g_V(T.id, 1, "name", eq("marko")), Collections.emptyList() }, { g.V().hasId(1).hasLabel("Person"), g_V(T.id, 1, "~label", eq("Person")), Collections.emptyList() }, { g.V().hasLabel("Person").has("lang", "java").order().by("name"), g_V("~label", eq("Person"), "lang", eq("java"), new HasStepFolder.OrderEntry("name", Order.incr)), Collections.emptyList() }, // same as above, different order
    { g.V().hasLabel("Person").has("lang", "java").order().by("name", Order.decr), g_V("~label", eq("Person"), "lang", eq("java"), new HasStepFolder.OrderEntry("name", Order.decr)), Collections.emptyList() }, // if multiple order steps are specified in a row, only the last will be folded in because it overrides previous ordering
    { g.V().hasLabel("Person").has("lang", "java").order().by("lang", Order.incr).order().by("name", Order.decr), g_V("~label", eq("Person"), "lang", eq("java"), new HasStepFolder.OrderEntry("name", Order.decr)), Collections.emptyList() }, // do not folder in orders that include a nested traversal
    { g.V().hasLabel("Person").order().by(values("age")), g_V("~label", eq("Person")).order().by(values("age")), Collections.emptyList() }, // age property is not registered in the schema so the order should not be folded in
    { g.V().hasLabel("Person").has("lang", "java").order().by("age"), g_V("~label", eq("Person"), "lang", eq("java")).order().by("age"), Collections.emptyList() }, // into a single within(ids) lookup
    { g.V().hasId(1).hasId(2), g_V(T.id, 1).hasId(2), Collections.emptyList() } });
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraph(org.janusgraph.core.JanusGraph) HasStepFolder(org.janusgraph.graphdb.tinkerpop.optimize.HasStepFolder) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph)

Example 3 with StandardJanusGraph

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

the class ConfiguredGraphFactoryTest method removeConfigurationShouldRemoveGraphFromCache.

@Test
public void removeConfigurationShouldRemoveGraphFromCache() 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);
        ConfiguredGraphFactory.removeConfiguration("graph1");
        assertNull(gm.getGraph("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)

Example 4 with StandardJanusGraph

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

the class ConfiguredGraphFactoryTest method shouldCreateAndGetGraphUsingTemplateConfiguration.

@Test
public void shouldCreateAndGetGraphUsingTemplateConfiguration() throws Exception {
    try {
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
        final StandardJanusGraph graph1 = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
        assertNotNull(graph);
        assertEquals(graph, 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)

Example 5 with StandardJanusGraph

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

the class ConfiguredGraphFactoryTest method graphConfigurationShouldBeWhatWeExpect.

@Test
public void graphConfigurationShouldBeWhatWeExpect() 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);
        assertEquals("graph1", graph.getConfiguration().getConfiguration().get(GRAPH_NAME));
        assertEquals("inmemory", graph.getConfiguration().getConfiguration().get(STORAGE_BACKEND));
    } 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