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());
}
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());
}
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());
}
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));
}
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();
}
Aggregations