use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testIndexQueryWithLabelsAndContainsIN.
@Test
public void testIndexQueryWithLabelsAndContainsIN() {
// This test is based on the steps to reproduce #882
String labelName = "labelName";
VertexLabel label = mgmt.makeVertexLabel(labelName).make();
PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make();
JanusGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex();
mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK);
finishSchema();
JanusGraphVertex foo = graph.addVertex(labelName);
JanusGraphVertex bar = graph.addVertex(labelName);
foo.property("uid", "foo");
bar.property("uid", "bar");
graph.tx().commit();
Iterable<JanusGraphVertex> vertexes = graph.query().has("uid", Contain.IN, ImmutableList.of("foo", "bar")).has(LABEL_NAME, labelName).vertices();
assertEquals(2, Iterables.size(vertexes));
for (JanusGraphVertex v : vertexes) {
assertEquals(labelName, v.vertexLabel().name());
}
}
use of org.janusgraph.core.JanusGraphVertex 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.JanusGraphVertex 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.JanusGraphVertex in project janusgraph by JanusGraph.
the class VertexIDAssignerTest method testCustomIdAssignment.
private void testCustomIdAssignment(CustomIdStrategy idStrategy) {
LongSet vertexIds = new LongHashSet();
final long maxCount = idAssigner.getIDManager().getVertexCountBound();
long count = 1;
for (int trial = 0; trial < 10; trial++) {
final JanusGraph graph = getInMemoryGraph(true, true);
int numVertices = 1000;
final List<JanusGraphVertex> vertices = new ArrayList<>(numVertices);
try {
for (int i = 0; i < numVertices; i++, count++) {
final long userVertexId;
switch(idStrategy) {
case LOW:
userVertexId = count;
break;
case HIGH:
userVertexId = maxCount - count;
break;
default:
throw new RuntimeException("Unsupported custom id strategy: " + idStrategy);
}
final long id = idAssigner.getIDManager().toVertexId(userVertexId);
JanusGraphVertex next = graph.addVertex(T.id, id, "user_id", userVertexId);
vertices.add(next);
}
// Verify that ids are set, unique and consistent with user id basis
for (JanusGraphVertex v : vertices) {
assertTrue(v.hasId());
long id = v.longId();
assertTrue(id > 0 && id < Long.MAX_VALUE);
assertTrue(vertexIds.add(id));
assertEquals((long) v.value("user_id"), idAssigner.getIDManager().fromVertexId(id));
}
} finally {
graph.tx().rollback();
graph.close();
}
}
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphHadoopSetupImpl method getTypeInspector.
@Override
public TypeInspector getTypeInspector() {
// Pre-load schema
for (JanusGraphSchemaCategory sc : JanusGraphSchemaCategory.values()) {
for (JanusGraphVertex k : QueryUtil.getVertices(tx, BaseKey.SchemaCategory, sc)) {
assert k instanceof JanusGraphSchemaVertex;
JanusGraphSchemaVertex s = (JanusGraphSchemaVertex) k;
if (sc.hasName()) {
String name = s.name();
Preconditions.checkNotNull(name);
}
TypeDefinitionMap dm = s.getDefinition();
Preconditions.checkNotNull(dm);
s.getRelated(TypeDefinitionCategory.TYPE_MODIFIER, Direction.OUT);
s.getRelated(TypeDefinitionCategory.TYPE_MODIFIER, Direction.IN);
}
}
return tx;
}
Aggregations