Search in sources :

Example 6 with EdgeLabel

use of org.janusgraph.core.EdgeLabel in project janusgraph by JanusGraph.

the class JanusGraphTest method testEdgeTTLWithTransactions.

@Test
public void testEdgeTTLWithTransactions() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }
    EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make();
    mgmt.setTTL(label1, Duration.ofSeconds(1));
    assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
    mgmt.commit();
    JanusGraphVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    v1.addEdge("likes", v2);
    // pre-commit state of the edge.  It is not yet subject to TTL
    assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
    Thread.sleep(1001);
    // the edge should have expired by now, but only if it had been committed
    assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
    graph.tx().commit();
    // still here, because we have just committed the edge.  Its countdown starts at the commit
    assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
    Thread.sleep(1001);
    // the edge has expired in Cassandra, but still appears alive in this transaction
    assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
    // syncing with the data store, we see that the edge has expired
    graph.tx().rollback();
    assertEmpty(v1.query().direction(Direction.OUT).vertices());
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) Test(org.junit.Test)

Example 7 with EdgeLabel

use of org.janusgraph.core.EdgeLabel in project janusgraph by JanusGraph.

the class JanusGraphTest method testEdgeTTLWithIndex.

@Category({ BrittleTests.class })
@Test
public void testEdgeTTLWithIndex() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }
    // artificially low TTL for test
    int ttl = 1;
    final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
    EdgeLabel wavedAt = mgmt.makeEdgeLabel("wavedAt").signature(time).make();
    mgmt.buildEdgeIndex(wavedAt, "timeindex", Direction.BOTH, decr, time);
    mgmt.buildIndex("edge-time", Edge.class).addKey(time).buildCompositeIndex();
    mgmt.setTTL(wavedAt, Duration.ofSeconds(ttl));
    assertEquals(Duration.ZERO, mgmt.getTTL(time));
    assertEquals(Duration.ofSeconds(ttl), mgmt.getTTL(wavedAt));
    mgmt.commit();
    JanusGraphVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    v1.addEdge("wavedAt", v2, "time", 42);
    assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
    assertNotEmpty(v1.query().direction(Direction.OUT).edges());
    assertNotEmpty(graph.query().has("time", 42).edges());
    graph.tx().commit();
    long commitTime = System.currentTimeMillis();
    assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
    assertNotEmpty(v1.query().direction(Direction.OUT).edges());
    assertNotEmpty(graph.query().has("time", 42).edges());
    Thread.sleep(commitTime + (ttl * 1000L + 100) - System.currentTimeMillis());
    graph.tx().rollback();
    assertFalse(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
    assertEmpty(v1.query().direction(Direction.OUT).edges());
    assertEmpty(graph.query().has("time", 42).edges());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) PropertyKey(org.janusgraph.core.PropertyKey) Category(org.junit.experimental.categories.Category) RelationCategory(org.janusgraph.graphdb.internal.RelationCategory) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) Test(org.junit.Test)

Example 8 with EdgeLabel

use of org.janusgraph.core.EdgeLabel in project janusgraph by JanusGraph.

the class JanusGraphAppTest method createSchema.

@Test
public void createSchema() throws ConfigurationException {
    final JanusGraphApp app = new JanusGraphApp(CONF_FILE);
    final GraphTraversalSource g = app.openGraph();
    app.createSchema();
    final JanusGraph janusGraph = (JanusGraph) g.getGraph();
    final JanusGraphManagement management = janusGraph.openManagement();
    final List<String> vertexLabels = StreamSupport.stream(management.getVertexLabels().spliterator(), false).map(Namifiable::name).collect(Collectors.toList());
    final List<String> expectedVertexLabels = Stream.of("titan", "location", "god", "demigod", "human", "monster").collect(Collectors.toList());
    assertTrue(vertexLabels.containsAll(expectedVertexLabels));
    final List<String> edgeLabels = StreamSupport.stream(management.getRelationTypes(EdgeLabel.class).spliterator(), false).map(Namifiable::name).collect(Collectors.toList());
    final List<String> expectedEdgeLabels = Stream.of("father", "mother", "brother", "pet", "lives", "battled").collect(Collectors.toList());
    assertTrue(edgeLabels.containsAll(expectedEdgeLabels));
    final EdgeLabel father = management.getEdgeLabel("father");
    assertTrue(father.isDirected());
    assertFalse(father.isUnidirected());
    assertEquals(Multiplicity.MANY2ONE, father.multiplicity());
    final List<String> propertyKeys = StreamSupport.stream(management.getRelationTypes(PropertyKey.class).spliterator(), false).map(Namifiable::name).collect(Collectors.toList());
    final List<String> expectedPropertyKeys = Stream.of("name", "age", "time", "place", "reason").collect(Collectors.toList());
    assertTrue(propertyKeys.containsAll(expectedPropertyKeys));
    final PropertyKey place = management.getPropertyKey("place");
    assertEquals(Cardinality.SINGLE, place.cardinality());
    assertEquals(Geoshape.class, place.dataType());
    final JanusGraphIndex nameIndex = management.getGraphIndex("nameIndex");
    assertTrue(nameIndex.isCompositeIndex());
    assertTrue(nameIndex.getIndexedElement().equals(JanusGraphVertex.class));
    final PropertyKey[] nameIndexKeys = nameIndex.getFieldKeys();
    assertEquals(1, nameIndexKeys.length);
    assertEquals("name", nameIndexKeys[0].name());
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraph(org.janusgraph.core.JanusGraph) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 9 with EdgeLabel

use of org.janusgraph.core.EdgeLabel in project janusgraph by JanusGraph.

the class AbstractIndexManagementIT method testRepairRelationIndex.

@Test
public void testRepairRelationIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();
    // Load the "Graph of the Gods" sample data (WITHOUT mixed index coverage)
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
    // Create and enable a relation index on lives edges by reason
    JanusGraphManagement m = graph.openManagement();
    PropertyKey reason = m.getPropertyKey("reason");
    EdgeLabel lives = m.getEdgeLabel("lives");
    m.buildEdgeIndex(lives, "livesByReason", Direction.BOTH, Order.decr, reason);
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to REGISTERED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives").status(SchemaStatus.REGISTERED).call().getSucceeded());
    m = graph.openManagement();
    RelationTypeIndex index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
    m.updateIndex(index, SchemaAction.ENABLE_INDEX);
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to ENABLED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives").status(SchemaStatus.ENABLED).call().getSucceeded());
    // Run a query that hits the index but erroneously returns nothing because we haven't repaired yet
    // assertFalse(graph.query().has("reason", "no fear of death").edges().iterator().hasNext());
    // Repair
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
    ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
    assertEquals(8, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) EdgeLabel(org.janusgraph.core.EdgeLabel) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Example 10 with EdgeLabel

use of org.janusgraph.core.EdgeLabel in project janusgraph by JanusGraph.

the class GraphOfTheGodsFactory method load.

public static void load(final JanusGraph graph, String mixedIndexName, boolean uniqueNameCompositeIndex) {
    if (graph instanceof StandardJanusGraph) {
        Preconditions.checkState(mixedIndexNullOrExists((StandardJanusGraph) graph, mixedIndexName), ERR_NO_INDEXING_BACKEND, mixedIndexName);
    }
    // Create Schema
    JanusGraphManagement management = graph.openManagement();
    final PropertyKey name = management.makePropertyKey("name").dataType(String.class).make();
    JanusGraphManagement.IndexBuilder nameIndexBuilder = management.buildIndex("name", Vertex.class).addKey(name);
    if (uniqueNameCompositeIndex)
        nameIndexBuilder.unique();
    JanusGraphIndex nameIndex = nameIndexBuilder.buildCompositeIndex();
    management.setConsistency(nameIndex, ConsistencyModifier.LOCK);
    final PropertyKey age = management.makePropertyKey("age").dataType(Integer.class).make();
    if (null != mixedIndexName)
        management.buildIndex("vertices", Vertex.class).addKey(age).buildMixedIndex(mixedIndexName);
    final PropertyKey time = management.makePropertyKey("time").dataType(Integer.class).make();
    final PropertyKey reason = management.makePropertyKey("reason").dataType(String.class).make();
    final PropertyKey place = management.makePropertyKey("place").dataType(Geoshape.class).make();
    if (null != mixedIndexName)
        management.buildIndex("edges", Edge.class).addKey(reason).addKey(place).buildMixedIndex(mixedIndexName);
    management.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    management.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make();
    EdgeLabel battled = management.makeEdgeLabel("battled").signature(time).make();
    management.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time);
    management.makeEdgeLabel("lives").signature(reason).make();
    management.makeEdgeLabel("pet").make();
    management.makeEdgeLabel("brother").make();
    management.makeVertexLabel("titan").make();
    management.makeVertexLabel("location").make();
    management.makeVertexLabel("god").make();
    management.makeVertexLabel("demigod").make();
    management.makeVertexLabel("human").make();
    management.makeVertexLabel("monster").make();
    management.commit();
    JanusGraphTransaction tx = graph.newTransaction();
    // vertices
    Vertex saturn = tx.addVertex(T.label, "titan", "name", "saturn", "age", 10000);
    Vertex sky = tx.addVertex(T.label, "location", "name", "sky");
    Vertex sea = tx.addVertex(T.label, "location", "name", "sea");
    Vertex jupiter = tx.addVertex(T.label, "god", "name", "jupiter", "age", 5000);
    Vertex neptune = tx.addVertex(T.label, "god", "name", "neptune", "age", 4500);
    Vertex hercules = tx.addVertex(T.label, "demigod", "name", "hercules", "age", 30);
    Vertex alcmene = tx.addVertex(T.label, "human", "name", "alcmene", "age", 45);
    Vertex pluto = tx.addVertex(T.label, "god", "name", "pluto", "age", 4000);
    Vertex nemean = tx.addVertex(T.label, "monster", "name", "nemean");
    Vertex hydra = tx.addVertex(T.label, "monster", "name", "hydra");
    Vertex cerberus = tx.addVertex(T.label, "monster", "name", "cerberus");
    Vertex tartarus = tx.addVertex(T.label, "location", "name", "tartarus");
    // edges
    jupiter.addEdge("father", saturn);
    jupiter.addEdge("lives", sky, "reason", "loves fresh breezes");
    jupiter.addEdge("brother", neptune);
    jupiter.addEdge("brother", pluto);
    neptune.addEdge("lives", sea).property("reason", "loves waves");
    neptune.addEdge("brother", jupiter);
    neptune.addEdge("brother", pluto);
    hercules.addEdge("father", jupiter);
    hercules.addEdge("mother", alcmene);
    hercules.addEdge("battled", nemean, "time", 1, "place", Geoshape.point(38.1f, 23.7f));
    hercules.addEdge("battled", hydra, "time", 2, "place", Geoshape.point(37.7f, 23.9f));
    hercules.addEdge("battled", cerberus, "time", 12, "place", Geoshape.point(39f, 22f));
    pluto.addEdge("brother", jupiter);
    pluto.addEdge("brother", neptune);
    pluto.addEdge("lives", tartarus, "reason", "no fear of death");
    pluto.addEdge("pet", cerberus);
    cerberus.addEdge("lives", tartarus);
    // commit the transaction to disk
    tx.commit();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) Geoshape(org.janusgraph.core.attribute.Geoshape) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph)

Aggregations

EdgeLabel (org.janusgraph.core.EdgeLabel)26 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)21 PropertyKey (org.janusgraph.core.PropertyKey)21 Test (org.junit.Test)21 Edge (org.apache.tinkerpop.gremlin.structure.Edge)9 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)9 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)6 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)6 VertexLabel (org.janusgraph.core.VertexLabel)6 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)6 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)6 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)5 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)5 BaseVertexLabel (org.janusgraph.graphdb.types.system.BaseVertexLabel)5 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)4 JanusGraph (org.janusgraph.core.JanusGraph)4 SchemaViolationException (org.janusgraph.core.SchemaViolationException)4 VertexList (org.janusgraph.core.VertexList)4