use of org.janusgraph.core.PropertyKey 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.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphTest method testAutomaticTypeCreation.
/**
* Tests the automatic creation of types
*/
@Test
public void testAutomaticTypeCreation() {
assertFalse(tx.containsVertexLabel("person"));
assertFalse(tx.containsVertexLabel("person"));
assertFalse(tx.containsRelationType("value"));
assertNull(tx.getPropertyKey("value"));
PropertyKey value = tx.getOrCreatePropertyKey("value");
assertNotNull(value);
assertTrue(tx.containsRelationType("value"));
JanusGraphVertex v = tx.addVertex("person");
assertTrue(tx.containsVertexLabel("person"));
assertEquals("person", v.label());
assertFalse(tx.containsRelationType("knows"));
Edge e = v.addEdge("knows", v);
assertTrue(tx.containsRelationType("knows"));
assertNotNull(tx.getEdgeLabel(e.label()));
clopen(option(AUTO_TYPE), "none");
assertTrue(tx.containsRelationType("value"));
assertTrue(tx.containsVertexLabel("person"));
assertTrue(tx.containsRelationType("knows"));
v = getV(tx, v);
// Cannot create new labels
try {
tx.addVertex("org");
fail();
} catch (IllegalArgumentException ignored) {
}
try {
v.property("bla", 5);
fail();
} catch (IllegalArgumentException ignored) {
}
try {
v.addEdge("blub", v);
fail();
} catch (IllegalArgumentException ignored) {
}
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphDefaultSchemaMakerTest method mockPropertyKeyMaker.
private PropertyKeyMaker mockPropertyKeyMaker() {
PropertyKeyMaker propertyKeyMaker = createMock(PropertyKeyMaker.class);
PropertyKey pk = createMock(PropertyKey.class);
expect(propertyKeyMaker.make()).andReturn(pk).anyTimes();
expect(propertyKeyMaker.getName()).andReturn("Quux").anyTimes();
expect(propertyKeyMaker.cardinality(Cardinality.SINGLE)).andReturn(propertyKeyMaker).anyTimes();
expect(propertyKeyMaker.dataType(String.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Character.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Boolean.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Byte.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Short.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Integer.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Long.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Float.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Double.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Date.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Geoshape.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(UUID.class)).andReturn(propertyKeyMaker);
expect(propertyKeyMaker.dataType(Object.class)).andReturn(propertyKeyMaker);
replayAll();
return propertyKeyMaker;
}
use of org.janusgraph.core.PropertyKey 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.PropertyKey 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));
}
Aggregations