use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testVertexCentricIndexOrderingOnMetaPropertyWithCardinalityList.
@Test
public void testVertexCentricIndexOrderingOnMetaPropertyWithCardinalityList() {
clopen(option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250));
PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.LIST).make();
PropertyKey sensor = mgmt.makePropertyKey("sensor").dataType(Integer.class).cardinality(Cardinality.LIST).make();
mgmt.buildPropertyIndex(sensor, "byTime", decr, time);
finishSchema();
JanusGraphVertex v = tx.addVertex();
for (int i = 200; i < 210; i++) {
v.property("sensor", i, "time", i);
}
assertEquals(SchemaStatus.ENABLED, mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime").getIndexStatus());
evaluateQuery(v.query().keys("sensor").interval("time", 201, 205).orderBy("time", decr), PROPERTY, 4, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
tx.commit();
finishSchema();
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testVertexCentricPropertyIndexOnSetCardinalityShouldWork.
@Test
public void testVertexCentricPropertyIndexOnSetCardinalityShouldWork() {
clopen(option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250));
PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SET).make();
mgmt.buildPropertyIndex(name, "byTime", decr, time);
finishSchema();
assertEquals(SchemaStatus.ENABLED, mgmt.getRelationIndex(mgmt.getRelationType("name"), "byTime").getIndexStatus());
JanusGraphVertex v = tx.addVertex();
v = getV(tx, v);
for (int i = 200; i < 210; i++) {
v.property("name", String.valueOf(i), "time", i);
}
evaluateQuery(v.query().keys("name").interval("time", 199, 210).orderBy("time", decr), PROPERTY, 10, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
tx.commit();
finishSchema();
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testEdgeTTLImplicitKey.
@Test
public void testEdgeTTLImplicitKey() throws Exception {
Duration d;
if (!features.hasCellTTL()) {
return;
}
clopen(option(GraphDatabaseConfiguration.STORE_META_TTL, "edgestore"), true);
assertEquals("~ttl", ImplicitKey.TTL.name());
int ttl = 24 * 60 * 60;
EdgeLabel likes = mgmt.makeEdgeLabel("likes").make();
EdgeLabel hasLiked = mgmt.makeEdgeLabel("hasLiked").make();
mgmt.setTTL(likes, Duration.ofSeconds(ttl));
assertEquals(Duration.ofSeconds(ttl), mgmt.getTTL(likes));
assertEquals(Duration.ZERO, mgmt.getTTL(hasLiked));
mgmt.commit();
JanusGraphVertex v1 = graph.addVertex(), v2 = graph.addVertex();
Edge e1 = v1.addEdge("likes", v2);
Edge e2 = v1.addEdge("hasLiked", v2);
graph.tx().commit();
// read from the edge created in this transaction
d = e1.value("~ttl");
assertEquals(Duration.ofDays(1), d);
// get the edge via a vertex
e1 = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("likes").edges());
d = e1.value("~ttl");
assertEquals(Duration.ofDays(1), d);
// returned value of ^ttl is the total time to live since commit, not remaining time
Thread.sleep(1001);
graph.tx().rollback();
e1 = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("likes").edges());
d = e1.value("~ttl");
assertEquals(Duration.ofDays(1), d);
// no ttl on edges of this label
d = e2.value("~ttl");
assertEquals(Duration.ZERO, d);
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testVertexCentricIndexWithNull.
@Test
public void testVertexCentricIndexWithNull() {
EdgeLabel bought = makeLabel("bought");
PropertyKey time = makeKey("time", Long.class);
mgmt.buildEdgeIndex(bought, "byTimeDesc", BOTH, decr, time);
mgmt.buildEdgeIndex(bought, "byTimeIncr", BOTH, incr, time);
finishSchema();
JanusGraphVertex v1 = tx.addVertex(), v2 = tx.addVertex();
v1.addEdge("bought", v2).property("time", 1);
v1.addEdge("bought", v2).property("time", 2);
v1.addEdge("bought", v2).property("time", 3);
v1.addEdge("bought", v2);
v1.addEdge("bought", v2);
assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", 1).edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).has("time", Cmp.GREATER_THAN, 1).edgeCount());
assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 5).edgeCount());
assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 0).edgeCount());
assertEquals(2, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 2).edgeCount());
assertEquals(2, v1.query().direction(OUT).labels("bought").hasNot("time").edgeCount());
assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
newTx();
v1 = tx.getVertex(v1.longId());
// Queries copied from above
assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", 1).edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).has("time", Cmp.GREATER_THAN, 1).edgeCount());
assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 5).edgeCount());
assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 0).edgeCount());
assertEquals(2, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).edgeCount());
assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 2).edgeCount());
assertEquals(2, v1.query().direction(OUT).labels("bought").hasNot("time").edgeCount());
assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testEdgeTTLLimitedByVertexTTL.
@Category({ BrittleTests.class })
@Test
public void testEdgeTTLLimitedByVertexTTL() throws Exception {
if (!features.hasCellTTL()) {
return;
}
Boolean dbCache = config.get("cache.db-cache", Boolean.class);
if (null == dbCache) {
dbCache = false;
}
EdgeLabel likes = mgmt.makeEdgeLabel("likes").make();
// long edge TTL will be overridden by short vertex TTL
mgmt.setTTL(likes, Duration.ofSeconds(42));
EdgeLabel dislikes = mgmt.makeEdgeLabel("dislikes").make();
mgmt.setTTL(dislikes, Duration.ofSeconds(1));
EdgeLabel indifferentTo = mgmt.makeEdgeLabel("indifferentTo").make();
VertexLabel label1 = mgmt.makeVertexLabel("person").setStatic().make();
mgmt.setTTL(label1, Duration.ofSeconds(2));
assertEquals(Duration.ofSeconds(42), mgmt.getTTL(likes));
assertEquals(Duration.ofSeconds(1), mgmt.getTTL(dislikes));
assertEquals(Duration.ZERO, mgmt.getTTL(indifferentTo));
assertEquals(Duration.ofSeconds(2), mgmt.getTTL(label1));
mgmt.commit();
JanusGraphVertex v1 = tx.addVertex("person");
JanusGraphVertex v2 = tx.addVertex();
Edge v1LikesV2 = v1.addEdge("likes", v2);
Edge v1DislikesV2 = v1.addEdge("dislikes", v2);
Edge v1IndifferentToV2 = v1.addEdge("indifferentTo", v2);
tx.commit();
long commitTime = System.currentTimeMillis();
Object v1Id = v1.id();
Object v2id = v2.id();
Object v1LikesV2Id = v1LikesV2.id();
Object v1DislikesV2Id = v1DislikesV2.id();
Object v1IndifferentToV2Id = v1IndifferentToV2.id();
v1 = getV(graph, v1Id);
v2 = getV(graph, v2id);
v1LikesV2 = getE(graph, v1LikesV2Id);
v1DislikesV2 = getE(graph, v1DislikesV2Id);
v1IndifferentToV2 = getE(graph, v1IndifferentToV2Id);
assertNotNull(v1);
assertNotNull(v2);
assertNotNull(v1LikesV2);
assertNotNull(v1DislikesV2);
assertNotNull(v1IndifferentToV2);
assertNotEmpty(v2.query().direction(Direction.IN).labels("likes").edges());
assertNotEmpty(v2.query().direction(Direction.IN).labels("dislikes").edges());
assertNotEmpty(v2.query().direction(Direction.IN).labels("indifferentTo").edges());
Thread.sleep(commitTime + 1001L - System.currentTimeMillis());
graph.tx().rollback();
v1 = getV(graph, v1Id);
v2 = getV(graph, v2id);
v1LikesV2 = getE(graph, v1LikesV2Id);
v1DislikesV2 = getE(graph, v1DislikesV2Id);
v1IndifferentToV2 = getE(graph, v1IndifferentToV2Id);
assertNotNull(v1);
assertNotNull(v2);
assertNotNull(v1LikesV2);
// this edge has expired
assertNull(v1DislikesV2);
assertNotNull(v1IndifferentToV2);
assertNotEmpty(v2.query().direction(Direction.IN).labels("likes").edges());
// expired
assertEmpty(v2.query().direction(Direction.IN).labels("dislikes").edges());
assertNotEmpty(v2.query().direction(Direction.IN).labels("indifferentTo").edges());
Thread.sleep(commitTime + 2001L - System.currentTimeMillis());
graph.tx().rollback();
v1 = getV(graph, v1Id);
v2 = getV(graph, v2id);
v1LikesV2 = getE(graph, v1LikesV2Id);
v1DislikesV2 = getE(graph, v1DislikesV2Id);
v1IndifferentToV2 = getE(graph, v1IndifferentToV2Id);
// the vertex itself has expired
assertNull(v1);
assertNotNull(v2);
// all incident edges have necessarily expired
assertNull(v1LikesV2);
assertNull(v1DislikesV2);
assertNull(v1IndifferentToV2);
if (dbCache) {
/* TODO: uncomment
assertNotEmpty(v2.query().direction(Direction.IN).labels("likes").edges());
assertNotEmpty(v2.query().direction(Direction.IN).labels("dislikes").edges());
assertNotEmpty(v2.query().direction(Direction.IN).labels("indifferentTo").edges());
*/
} else {
assertEmpty(v2.query().direction(Direction.IN).labels("likes").edges());
assertEmpty(v2.query().direction(Direction.IN).labels("dislikes").edges());
assertEmpty(v2.query().direction(Direction.IN).labels("indifferentTo").edges());
}
}
Aggregations