use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testBooleanIndexing.
/**
* Tests indexing boolean
*/
@Test
public void testBooleanIndexing() {
PropertyKey name = makeKey("visible", Boolean.class);
mgmt.buildIndex("booleanIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
JanusGraphVertex v1 = graph.addVertex();
v1.property("visible", true);
JanusGraphVertex v2 = graph.addVertex();
v2.property("visible", false);
assertCount(2, graph.vertices());
assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
// Flush the index
clopen();
assertCount(2, graph.vertices());
assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class CassandraScanJobIT method testPartitionedVertexFilteredScan.
@Test
public void testPartitionedVertexFilteredScan() throws Exception {
tearDown();
clearGraph(getConfiguration());
WriteConfiguration partConf = getConfiguration();
open(partConf);
mgmt.makeVertexLabel("part").partition().make();
finishSchema();
JanusGraphVertex supernode = graph.addVertex("part");
for (int i = 0; i < 128; i++) {
JanusGraphVertex v = graph.addVertex("part");
v.addEdge("default", supernode);
if (0 < i && 0 == i % 4)
graph.tx().commit();
}
graph.tx().commit();
org.apache.hadoop.conf.Configuration c = new org.apache.hadoop.conf.Configuration();
c.set(ConfigElement.getPath(JanusGraphHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.cassandra.keyspace", getClass().getSimpleName());
c.set(ConfigElement.getPath(JanusGraphHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.backend", "cassandrathrift");
c.set(ConfigElement.getPath(JanusGraphHadoopConfiguration.FILTER_PARTITIONED_VERTICES), "true");
c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner");
Job job = getVertexJobWithDefaultMapper(c);
// Should succeed
assertTrue(job.waitForCompletion(true));
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testUUIDIndexing.
/**
* Tests indexing boolean
*/
@Test
public void testUUIDIndexing() {
PropertyKey name = makeKey("uid", UUID.class);
mgmt.buildIndex("uuidIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
UUID uid1 = UUID.randomUUID();
UUID uid2 = UUID.randomUUID();
JanusGraphVertex v1 = graph.addVertex();
v1.property("uid", uid1);
JanusGraphVertex v2 = graph.addVertex();
v2.property("uid", uid2);
assertCount(2, graph.query().vertices());
assertEquals(v1, getOnlyVertex(graph.query().has("uid", uid1)));
assertEquals(v2, getOnlyVertex(graph.query().has("uid", uid2)));
assertEquals(v2, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid1)));
assertEquals(v1, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid2)));
// Flush the index
clopen();
assertCount(2, graph.query().vertices());
assertEquals(v1, getOnlyVertex(graph.query().has("uid", uid1)));
assertEquals(v2, getOnlyVertex(graph.query().has("uid", uid2)));
assertEquals(v2, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid1)));
assertEquals(v1, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid2)));
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testNestedWrites.
private void testNestedWrites(String initialValue, String updatedValue) throws BackendException {
// This method touches a single vertex with multiple transactions,
// leading to deadlock under BDB and cascading test failures. Check for
// the hasTxIsolation() store feature, which is currently true for BDB
// but false for HBase/Cassandra. This is kind of a hack; a more robust
// approach might implement different methods/assertions depending on
// whether the store is capable of deadlocking or detecting conflicting
// writes and aborting a transaction.
Backend b = null;
try {
b = graph.getConfiguration().getBackend();
if (b.getStoreFeatures().hasTxIsolation()) {
log.info("Skipping " + getClass().getSimpleName() + "." + methodName.getMethodName());
return;
}
} finally {
if (null != b)
b.close();
}
final String propName = "foo";
// Write schema and one vertex
PropertyKey prop = makeKey(propName, String.class);
createExternalVertexIndex(prop, INDEX);
finishSchema();
JanusGraphVertex v = graph.addVertex();
if (null != initialValue)
v.property(VertexProperty.Cardinality.single, propName, initialValue);
graph.tx().commit();
Object id = v.id();
// Open two transactions and modify the same vertex
JanusGraphTransaction vertexDeleter = graph.newTransaction();
JanusGraphTransaction propDeleter = graph.newTransaction();
getV(vertexDeleter, id).remove();
if (null == updatedValue)
getV(propDeleter, id).property(propName).remove();
else
getV(propDeleter, id).property(VertexProperty.Cardinality.single, propName, updatedValue);
vertexDeleter.commit();
propDeleter.commit();
// The vertex must not exist after deletion
graph.tx().rollback();
assertEquals(null, getV(graph, id));
assertEmpty(graph.query().has(propName).vertices());
if (null != updatedValue)
assertEmpty(graph.query().has(propName, updatedValue).vertices());
graph.tx().rollback();
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testVertexTTLWithMixedIndices.
/* ==================================================================================
TIME-TO-LIVE
==================================================================================*/
@Test
public void testVertexTTLWithMixedIndices() throws Exception {
if (!features.hasCellTTL() || !indexFeatures.supportsDocumentTTL()) {
return;
}
PropertyKey name = makeKey("name", String.class);
PropertyKey time = makeKey("time", Long.class);
PropertyKey text = makeKey("text", String.class);
VertexLabel event = mgmt.makeVertexLabel("event").setStatic().make();
final int eventTTLSeconds = (int) TestGraphConfigs.getTTL(TimeUnit.SECONDS);
mgmt.setTTL(event, Duration.ofSeconds(eventTTLSeconds));
mgmt.buildIndex("index1", Vertex.class).addKey(name, getStringMapping()).addKey(time).buildMixedIndex(INDEX);
mgmt.buildIndex("index2", Vertex.class).indexOnly(event).addKey(text, getTextMapping()).buildMixedIndex(INDEX);
assertEquals(Duration.ZERO, mgmt.getTTL(name));
assertEquals(Duration.ZERO, mgmt.getTTL(time));
assertEquals(Duration.ofSeconds(eventTTLSeconds), mgmt.getTTL(event));
finishSchema();
JanusGraphVertex v1 = tx.addVertex("event");
v1.property(VertexProperty.Cardinality.single, "name", "first event");
v1.property(VertexProperty.Cardinality.single, "text", "this text will help to identify the first event");
long time1 = System.currentTimeMillis();
v1.property(VertexProperty.Cardinality.single, "time", time1);
JanusGraphVertex v2 = tx.addVertex("event");
v2.property(VertexProperty.Cardinality.single, "name", "second event");
v2.property(VertexProperty.Cardinality.single, "text", "this text won't match");
long time2 = time1 + 1;
v2.property(VertexProperty.Cardinality.single, "time", time2);
evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr), ElementCategory.VERTEX, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC, "index1");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "index2");
clopen();
Object v1Id = v1.id();
Object v2Id = v2.id();
evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr), ElementCategory.VERTEX, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC, "index1");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "index2");
v1 = getV(tx, v1Id);
v2 = getV(tx, v1Id);
assertNotNull(v1);
assertNotNull(v2);
Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));
clopen();
Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "index2");
evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr), ElementCategory.VERTEX, 0, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC, "index1");
v1 = getV(tx, v1Id);
v2 = getV(tx, v2Id);
assertNull(v1);
assertNull(v2);
}
Aggregations