use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.
the class TitanGraphTest method testGlobalGraphIndexingAndQueriesForInternalIndexes.
/* ==================================================================================
GLOBAL GRAPH QUERIES
==================================================================================*/
/**
* Tests index defintions and their correct application for internal indexes only
*/
@Test
public void testGlobalGraphIndexingAndQueriesForInternalIndexes() {
PropertyKey weight = makeKey("weight", Float.class);
PropertyKey time = makeKey("time", Long.class);
PropertyKey text = makeKey("text", String.class);
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.LIST).make();
EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(weight).make();
EdgeLabel related = mgmt.makeEdgeLabel("related").signature(time).make();
VertexLabel person = mgmt.makeVertexLabel("person").make();
VertexLabel organization = mgmt.makeVertexLabel("organization").make();
TitanGraphIndex edge1 = mgmt.buildIndex("edge1", Edge.class).addKey(time).addKey(weight).buildCompositeIndex();
TitanGraphIndex edge2 = mgmt.buildIndex("edge2", Edge.class).indexOnly(connect).addKey(text).buildCompositeIndex();
TitanGraphIndex prop1 = mgmt.buildIndex("prop1", TitanVertexProperty.class).addKey(time).buildCompositeIndex();
TitanGraphIndex prop2 = mgmt.buildIndex("prop2", TitanVertexProperty.class).addKey(weight).addKey(text).buildCompositeIndex();
TitanGraphIndex vertex1 = mgmt.buildIndex("vertex1", Vertex.class).addKey(time).indexOnly(person).unique().buildCompositeIndex();
TitanGraphIndex vertex12 = mgmt.buildIndex("vertex12", Vertex.class).addKey(text).indexOnly(person).buildCompositeIndex();
TitanGraphIndex vertex2 = mgmt.buildIndex("vertex2", Vertex.class).addKey(time).addKey(name).indexOnly(organization).buildCompositeIndex();
TitanGraphIndex vertex3 = mgmt.buildIndex("vertex3", Vertex.class).addKey(name).buildCompositeIndex();
// ########### INSPECTION & FAILURE ##############
assertTrue(mgmt.containsRelationType("name"));
assertTrue(mgmt.containsGraphIndex("prop1"));
assertFalse(mgmt.containsGraphIndex("prop3"));
assertEquals(2, Iterables.size(mgmt.getGraphIndexes(Edge.class)));
assertEquals(2, Iterables.size(mgmt.getGraphIndexes(TitanVertexProperty.class)));
assertEquals(4, Iterables.size(mgmt.getGraphIndexes(Vertex.class)));
assertNull(mgmt.getGraphIndex("balblub"));
edge1 = mgmt.getGraphIndex("edge1");
edge2 = mgmt.getGraphIndex("edge2");
prop1 = mgmt.getGraphIndex("prop1");
prop2 = mgmt.getGraphIndex("prop2");
vertex1 = mgmt.getGraphIndex("vertex1");
vertex12 = mgmt.getGraphIndex("vertex12");
vertex2 = mgmt.getGraphIndex("vertex2");
vertex3 = mgmt.getGraphIndex("vertex3");
assertTrue(vertex1.isUnique());
assertFalse(edge2.isUnique());
assertEquals("prop1", prop1.name());
assertTrue(Vertex.class.isAssignableFrom(vertex3.getIndexedElement()));
assertTrue(TitanVertexProperty.class.isAssignableFrom(prop1.getIndexedElement()));
assertTrue(Edge.class.isAssignableFrom(edge2.getIndexedElement()));
assertEquals(2, vertex2.getFieldKeys().length);
assertEquals(1, vertex1.getFieldKeys().length);
try {
//Parameters not supported
mgmt.buildIndex("blablub", Vertex.class).addKey(text, Mapping.TEXT.asParameter()).buildCompositeIndex();
fail();
} catch (IllegalArgumentException e) {
}
try {
//Name already in use
mgmt.buildIndex("edge1", Vertex.class).addKey(weight).buildCompositeIndex();
fail();
} catch (IllegalArgumentException e) {
}
try {
//ImplicitKeys not allowed
mgmt.buildIndex("jupdup", Vertex.class).addKey(ImplicitKey.ID).buildCompositeIndex();
fail();
} catch (IllegalArgumentException e) {
}
try {
//Unique is only allowed for vertex
mgmt.buildIndex("edgexyz", Edge.class).addKey(time).unique().buildCompositeIndex();
fail();
} catch (IllegalArgumentException e) {
}
// ########### END INSPECTION & FAILURE ##############
finishSchema();
clopen();
text = mgmt.getPropertyKey("text");
time = mgmt.getPropertyKey("time");
weight = mgmt.getPropertyKey("weight");
// ########### INSPECTION & FAILURE (copied from above) ##############
assertTrue(mgmt.containsRelationType("name"));
assertTrue(mgmt.containsGraphIndex("prop1"));
assertFalse(mgmt.containsGraphIndex("prop3"));
assertEquals(2, Iterables.size(mgmt.getGraphIndexes(Edge.class)));
assertEquals(2, Iterables.size(mgmt.getGraphIndexes(TitanVertexProperty.class)));
assertEquals(4, Iterables.size(mgmt.getGraphIndexes(Vertex.class)));
assertNull(mgmt.getGraphIndex("balblub"));
edge1 = mgmt.getGraphIndex("edge1");
edge2 = mgmt.getGraphIndex("edge2");
prop1 = mgmt.getGraphIndex("prop1");
prop2 = mgmt.getGraphIndex("prop2");
vertex1 = mgmt.getGraphIndex("vertex1");
vertex12 = mgmt.getGraphIndex("vertex12");
vertex2 = mgmt.getGraphIndex("vertex2");
vertex3 = mgmt.getGraphIndex("vertex3");
assertTrue(vertex1.isUnique());
assertFalse(edge2.isUnique());
assertEquals("prop1", prop1.name());
assertTrue(Vertex.class.isAssignableFrom(vertex3.getIndexedElement()));
assertTrue(TitanVertexProperty.class.isAssignableFrom(prop1.getIndexedElement()));
assertTrue(Edge.class.isAssignableFrom(edge2.getIndexedElement()));
assertEquals(2, vertex2.getFieldKeys().length);
assertEquals(1, vertex1.getFieldKeys().length);
try {
//Parameters not supported
mgmt.buildIndex("blablub", Vertex.class).addKey(text, Mapping.TEXT.asParameter()).buildCompositeIndex();
fail();
} catch (IllegalArgumentException e) {
}
try {
//Name already in use
mgmt.buildIndex("edge1", Vertex.class).addKey(weight).buildCompositeIndex();
fail();
} catch (IllegalArgumentException e) {
}
try {
//ImplicitKeys not allowed
mgmt.buildIndex("jupdup", Vertex.class).addKey(ImplicitKey.ID).buildCompositeIndex();
fail();
} catch (IllegalArgumentException e) {
}
try {
//Unique is only allowed for vertex
mgmt.buildIndex("edgexyz", Edge.class).addKey(time).unique().buildCompositeIndex();
fail();
} catch (IllegalArgumentException e) {
}
// ########### END INSPECTION & FAILURE ##############
final int numV = 100;
final boolean sorted = true;
TitanVertex[] ns = new TitanVertex[numV];
String[] strs = { "aaa", "bbb", "ccc", "ddd" };
for (int i = 0; i < numV; i++) {
ns[i] = tx.addVertex(i % 2 == 0 ? "person" : "organization");
VertexProperty p1 = ns[i].property("name", "v" + i);
VertexProperty p2 = ns[i].property("name", "u" + (i % 5));
double w = (i * 0.5) % 5;
long t = i;
String txt = strs[i % (strs.length)];
ns[i].property(VertexProperty.Cardinality.single, "weight", w);
ns[i].property(VertexProperty.Cardinality.single, "time", t);
ns[i].property(VertexProperty.Cardinality.single, "text", txt);
for (VertexProperty p : new VertexProperty[] { p1, p2 }) {
p.property("weight", w);
p.property("time", t);
p.property("text", txt);
}
//previous or self-loop
TitanVertex u = ns[(i > 0 ? i - 1 : i)];
for (String label : new String[] { "connect", "related" }) {
Edge e = ns[i].addEdge(label, u, "weight", (w++) % 5, "time", t, "text", txt);
}
}
//########## QUERIES ################
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of(10, 20, 30)).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 3, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0).has("text", Cmp.EQUAL, strs[10 % strs.length]), ElementCategory.EDGE, 1, new boolean[] { false, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 1), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20).has("weight", Cmp.EQUAL, 3), ElementCategory.EDGE, 0, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[0]).has(LABEL_NAME, "connect"), ElementCategory.EDGE, numV / strs.length, new boolean[] { true, sorted }, edge2.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[0]).has(LABEL_NAME, "connect").limit(10), ElementCategory.EDGE, 10, new boolean[] { true, sorted }, edge2.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[0]), ElementCategory.EDGE, numV / strs.length * 2, new boolean[] { false, sorted });
evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.EDGE, numV / 10 * 2, new boolean[] { false, sorted });
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 50), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop1.name());
evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 0.0).has("text", Cmp.EQUAL, strs[0]), ElementCategory.PROPERTY, 2 * numV / (4 * 5), new boolean[] { true, sorted }, prop2.name());
evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 0.0).has("text", Cmp.EQUAL, strs[0]).has("time", Cmp.EQUAL, 0), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop2.name(), prop1.name());
evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.PROPERTY, 2 * numV / 10, new boolean[] { false, sorted });
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 50).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex1.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[2]).has(LABEL_NAME, "person"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, sorted }, vertex12.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[3]).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 0, new boolean[] { true, sorted }, vertex12.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[2]).has(LABEL_NAME, "person").has("time", Cmp.EQUAL, 2), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex12.name(), vertex1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has("name", Cmp.EQUAL, "v51").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex2.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has("name", Cmp.EQUAL, "u1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex2.name());
evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of(51, 61, 71, 31, 41)).has("name", Cmp.EQUAL, "u1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 5, new boolean[] { true, sorted }, vertex2.name());
evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of()), ElementCategory.VERTEX, 0, new boolean[] { true, false });
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[2]).has(LABEL_NAME, "person").has("time", Contain.NOT_IN, ImmutableList.of()), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, sorted }, vertex12.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { false, sorted });
evaluateQuery(tx.query().has("name", Cmp.EQUAL, "u1"), ElementCategory.VERTEX, numV / 5, new boolean[] { true, sorted }, vertex3.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, "v1"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex3.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, "v1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { false, sorted }, vertex3.name());
clopen();
//########## QUERIES (copied from above) ################
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of(10, 20, 30)).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 3, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0).has("text", Cmp.EQUAL, strs[10 % strs.length]), ElementCategory.EDGE, 1, new boolean[] { false, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 1), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20).has("weight", Cmp.EQUAL, 3), ElementCategory.EDGE, 0, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[0]).has(LABEL_NAME, "connect"), ElementCategory.EDGE, numV / strs.length, new boolean[] { true, sorted }, edge2.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[0]).has(LABEL_NAME, "connect").limit(10), ElementCategory.EDGE, 10, new boolean[] { true, sorted }, edge2.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[0]), ElementCategory.EDGE, numV / strs.length * 2, new boolean[] { false, sorted });
evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.EDGE, numV / 10 * 2, new boolean[] { false, sorted });
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 50), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop1.name());
evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 0.0).has("text", Cmp.EQUAL, strs[0]), ElementCategory.PROPERTY, 2 * numV / (4 * 5), new boolean[] { true, sorted }, prop2.name());
evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 0.0).has("text", Cmp.EQUAL, strs[0]).has("time", Cmp.EQUAL, 0), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop2.name(), prop1.name());
evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.PROPERTY, 2 * numV / 10, new boolean[] { false, sorted });
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 50).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex1.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[2]).has(LABEL_NAME, "person"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, sorted }, vertex12.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[3]).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 0, new boolean[] { true, sorted }, vertex12.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[2]).has(LABEL_NAME, "person").has("time", Cmp.EQUAL, 2), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex12.name(), vertex1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has("name", Cmp.EQUAL, "v51").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex2.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has("name", Cmp.EQUAL, "u1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex2.name());
evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of(51, 61, 71, 31, 41)).has("name", Cmp.EQUAL, "u1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 5, new boolean[] { true, sorted }, vertex2.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { false, sorted });
evaluateQuery(tx.query().has("name", Cmp.EQUAL, "u1"), ElementCategory.VERTEX, numV / 5, new boolean[] { true, sorted }, vertex3.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, "v1"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex3.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, "v1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { false, sorted }, vertex3.name());
evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of()), ElementCategory.VERTEX, 0, new boolean[] { true, false });
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[2]).has(LABEL_NAME, "person").has("time", Contain.NOT_IN, ImmutableList.of()), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, sorted }, vertex12.name());
//Update in transaction
for (int i = 0; i < numV / 2; i++) {
TitanVertex v = getV(tx, ns[i]);
v.remove();
}
ns = new TitanVertex[numV * 3 / 2];
for (int i = numV; i < numV * 3 / 2; i++) {
ns[i] = tx.addVertex(i % 2 == 0 ? "person" : "organization");
VertexProperty p1 = ns[i].property("name", "v" + i);
VertexProperty p2 = ns[i].property("name", "u" + (i % 5));
double w = (i * 0.5) % 5;
long t = i;
String txt = strs[i % (strs.length)];
ns[i].property(VertexProperty.Cardinality.single, "weight", w);
ns[i].property(VertexProperty.Cardinality.single, "time", t);
ns[i].property(VertexProperty.Cardinality.single, "text", txt);
for (VertexProperty p : new VertexProperty[] { p1, p2 }) {
p.property("weight", w);
p.property("time", t);
p.property("text", txt);
}
//previous or self-loop
TitanVertex u = ns[(i > numV ? i - 1 : i)];
for (String label : new String[] { "connect", "related" }) {
Edge e = ns[i].addEdge(label, u, "weight", (w++) % 5, "time", t, "text", txt);
}
}
//######### UPDATED QUERIES ##########
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 0, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[0]).has(LABEL_NAME, "connect").limit(10), ElementCategory.EDGE, 10, new boolean[] { true, sorted }, edge2.name());
evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.EDGE, numV / 10 * 2, new boolean[] { false, sorted });
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20), ElementCategory.PROPERTY, 0, new boolean[] { true, sorted }, prop1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 20), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 30).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 0, new boolean[] { true, sorted }, vertex1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 30).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex1.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, "u1"), ElementCategory.VERTEX, numV / 5, new boolean[] { true, sorted }, vertex3.name());
//######### END UPDATED QUERIES ##########
newTx();
//######### UPDATED QUERIES (copied from above) ##########
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 0, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
evaluateQuery(tx.query().has("text", Cmp.EQUAL, strs[0]).has(LABEL_NAME, "connect").limit(10), ElementCategory.EDGE, 10, new boolean[] { true, sorted }, edge2.name());
evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.EDGE, numV / 10 * 2, new boolean[] { false, sorted });
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20), ElementCategory.PROPERTY, 0, new boolean[] { true, sorted }, prop1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 20), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, 30).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 0, new boolean[] { true, sorted }, vertex1.name());
evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 30).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex1.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, "u1"), ElementCategory.VERTEX, numV / 5, new boolean[] { true, sorted }, vertex3.name());
//*** INIVIDUAL USE CASE TESTS ******
}
use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.
the class TitanGraphTest method testConcurrentConsistencyEnforcement.
@Test
public void testConcurrentConsistencyEnforcement() throws Exception {
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
TitanGraphIndex nameIndex = mgmt.buildIndex("name", Vertex.class).addKey(name).unique().buildCompositeIndex();
mgmt.setConsistency(nameIndex, ConsistencyModifier.LOCK);
EdgeLabel married = mgmt.makeEdgeLabel("married").multiplicity(Multiplicity.ONE2ONE).make();
mgmt.setConsistency(married, ConsistencyModifier.LOCK);
EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make();
finishSchema();
TitanVertex baseV = tx.addVertex("name", "base");
newTx();
final long baseVid = getId(baseV);
final String nameA = "a", nameB = "b";
final int parallelThreads = 4;
final AtomicInteger totalExe = new AtomicInteger();
int numSuccess = executeParallelTransactions(new TransactionJob() {
@Override
public void run(TitanTransaction tx) {
TitanVertex a = tx.addVertex();
TitanVertex base = getV(tx, baseVid);
base.addEdge("married", a);
}
}, parallelThreads);
assertTrue("At most 1 tx should succeed: " + numSuccess, numSuccess <= 1);
numSuccess = executeParallelTransactions(new TransactionJob() {
@Override
public void run(TitanTransaction tx) {
TitanVertex a = tx.addVertex("name", nameA);
TitanVertex b = tx.addVertex("name", nameB);
b.addEdge("friend", b);
}
}, parallelThreads);
newTx();
long numA = Iterables.size(tx.query().has("name", nameA).vertices());
long numB = Iterables.size(tx.query().has("name", nameB).vertices());
// System.out.println(numA + " - " + numB);
assertTrue("At most 1 tx should succeed: " + numSuccess, numSuccess <= 1);
assertTrue(numA <= 1);
assertTrue(numB <= 1);
}
use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.
the class TitanEventualGraphTest method testBatchLoadingLocking.
public void testBatchLoadingLocking(boolean batchloading) {
PropertyKey uid = makeKey("uid", Long.class);
TitanGraphIndex uidIndex = mgmt.buildIndex("uid", Vertex.class).unique().addKey(uid).buildCompositeIndex();
mgmt.setConsistency(uid, ConsistencyModifier.LOCK);
mgmt.setConsistency(uidIndex, ConsistencyModifier.LOCK);
EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.ONE2ONE).make();
mgmt.setConsistency(knows, ConsistencyModifier.LOCK);
finishSchema();
TestLockerManager.ERROR_ON_LOCKING = true;
clopen(option(GraphDatabaseConfiguration.STORAGE_BATCH), batchloading, option(GraphDatabaseConfiguration.LOCK_BACKEND), "test");
int numV = 10000;
long start = System.currentTimeMillis();
for (int i = 0; i < numV; i++) {
TitanVertex v = tx.addVertex("uid", i + 1);
v.addEdge("knows", v);
}
clopen();
for (int i = 0; i < Math.min(numV, 300); i++) {
assertEquals(1, Iterables.size(graph.query().has("uid", i + 1).vertices()));
TitanVertex v = Iterables.<TitanVertex>getOnlyElement(graph.query().has("uid", i + 1).vertices());
assertEquals(1, Iterables.size(v.query().direction(OUT).labels("knows").edges()));
}
}
use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.
the class TitanGraphTest method testVertexTTLWithCompositeIndex.
@Test
public void testVertexTTLWithCompositeIndex() throws Exception {
if (!features.hasCellTTL()) {
return;
}
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make();
TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex();
VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
mgmt.setTTL(label1, Duration.ofSeconds(1));
assertEquals(Duration.ZERO, mgmt.getTTL(name));
assertEquals(Duration.ZERO, mgmt.getTTL(time));
assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
mgmt.commit();
TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis());
tx.commit();
Object id = v1.id();
v1 = getV(graph, id);
assertNotNull(v1);
assertNotEmpty(graph.query().has("name", "some event").vertices());
Thread.sleep(1001);
graph.tx().rollback();
v1 = getV(graph, id);
assertNull(v1);
assertEmpty(graph.query().has("name", "some event").vertices());
}
use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.
the class TitanGraphTest 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();
TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex();
mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK);
finishSchema();
TitanVertex foo = graph.addVertex(labelName);
TitanVertex bar = graph.addVertex(labelName);
foo.property("uid", "foo");
bar.property("uid", "bar");
graph.tx().commit();
Iterable<TitanVertex> vertexes = graph.query().has("uid", Contain.IN, ImmutableList.of("foo", "bar")).has(LABEL_NAME, labelName).vertices();
assertEquals(2, Iterables.size(vertexes));
for (TitanVertex v : vertexes) {
assertEquals(labelName, v.vertexLabel().name());
}
}
Aggregations