use of org.janusgraph.core.PropertyKey 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.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method shouldAwaitMultipleStatuses.
@Test
public void shouldAwaitMultipleStatuses() throws InterruptedException, ExecutionException {
PropertyKey key1 = makeKey("key1", String.class);
JanusGraphIndex index = mgmt.buildIndex("randomMixedIndex", Vertex.class).addKey(key1).buildMixedIndex(INDEX);
if (index.getIndexStatus(key1) == SchemaStatus.INSTALLED) {
mgmt.updateIndex(mgmt.getGraphIndex("randomMixedIndex"), SchemaAction.REGISTER_INDEX).get();
mgmt.updateIndex(mgmt.getGraphIndex("randomMixedIndex"), SchemaAction.ENABLE_INDEX).get();
} else if (index.getIndexStatus(key1) == SchemaStatus.REGISTERED) {
mgmt.updateIndex(mgmt.getGraphIndex("randomMixedIndex"), SchemaAction.ENABLE_INDEX).get();
}
PropertyKey key2 = makeKey("key2", String.class);
mgmt.addIndexKey(index, key2);
mgmt.commit();
// key1 now has status ENABLED, let's ensure we can watch for REGISTERED and ENABLED
try {
ManagementSystem.awaitGraphIndexStatus(graph, "randomMixedIndex").status(SchemaStatus.REGISTERED, SchemaStatus.ENABLED).call();
} catch (Exception e) {
Assert.fail("Failed to awaitGraphIndexStatus on multiple statuses.");
}
}
use of org.janusgraph.core.PropertyKey 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.PropertyKey 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);
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testSetUpdate.
@Test
public void testSetUpdate() {
if (!indexFeatures.supportsCardinality(Cardinality.SET)) {
return;
}
PropertyKey name = makeKey("name", String.class);
PropertyKey alias = mgmt.makePropertyKey("alias").dataType(String.class).cardinality(Cardinality.SET).make();
mgmt.buildIndex("namev", Vertex.class).addKey(name).addKey(alias, indexFeatures.supportsStringMapping(Mapping.TEXTSTRING) ? Mapping.TEXTSTRING.asParameter() : Mapping.DEFAULT.asParameter()).buildMixedIndex(INDEX);
finishSchema();
JanusGraphVertex v = tx.addVertex("name", "Marko Rodriguez");
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
clopen();
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko"));
v.property(VertexProperty.Cardinality.set, "alias", "Marko");
assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices());
clopen();
assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices());
v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko"));
v.property(VertexProperty.Cardinality.set, "alias", "mRodriguez");
assertCount(1, tx.query().has("alias", Text.CONTAINS, "mRodriguez").vertices());
clopen();
assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices());
assertCount(1, tx.query().has("alias", Text.CONTAINS, "mRodriguez").vertices());
if (indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) {
assertCount(1, tx.query().has("alias", Cmp.EQUAL, "Marko").vertices());
assertCount(1, tx.query().has("alias", Cmp.EQUAL, "mRodriguez").vertices());
}
}
Aggregations