finishSchema(); assertEquals("internalindex", gindex.getBackingIndex()); assertEquals(SchemaStatus.ENABLED, gindex.getIndexStatus(gindex.getFieldKeys()[0])); finishSchema(); finishSchema(); mgmt.updateIndex(gindex, SchemaAction.REMOVE_INDEX); TitanManagement.IndexJobFuture gmetrics = mgmt.getIndexJobStatus(gindex); finishSchema();
PropertyKey b = mgmt.makePropertyKey(bar).dataType(String.class).cardinality(Cardinality.LIST).make(); mgmt.buildIndex(bar, Vertex.class).addKey(b).buildCompositeIndex(); finishSchema();
@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()); } }
@Test public void testStaleVertex() { PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make(); mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex(); finishSchema(); TitanVertex cartman = graph.addVertex("name", "cartman", "age", 10); TitanVertex stan = graph.addVertex("name", "stan", "age", 8); graph.tx().commit(); cartman = getOnlyElement(graph.query().has("name", "cartman").vertices()); graph.tx().commit(); TitanVertexProperty p = (TitanVertexProperty) cartman.properties().next(); assertTrue(((Long) p.longId()) > 0); graph.tx().commit(); }
mgmt.setConsistency(married, ConsistencyModifier.LOCK); EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make(); finishSchema();
@Test public void testLargeJointIndexRetrieval() { makeVertexIndexedKey("sid", Integer.class); makeVertexIndexedKey("color", String.class); finishSchema(); int sids = 17; String[] colors = {"blue", "red", "yellow", "brown", "green", "orange", "purple"}; int multiplier = 200; int numV = sids * colors.length * multiplier; for (int i = 0; i < numV; i++) { TitanVertex v = graph.addVertex( "color", colors[i % colors.length], "sid", i % sids); } clopen(); assertCount(numV / sids, graph.query().has("sid", 8).vertices()); assertCount(numV / colors.length, graph.query().has("color", colors[2]).vertices()); assertCount(multiplier, graph.query().has("sid", 11).has("color", colors[3]).vertices()); }
((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("knows")).sortKey(uid).sortOrder(Order.DESC).directed().make(); mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make(); finishSchema();
@Test public void testWithoutIndex() { PropertyKey kid = mgmt.makePropertyKey("kid").dataType(Long.class).make(); mgmt.makePropertyKey("name").dataType(String.class).make(); mgmt.makeEdgeLabel("knows").signature(kid).make(); finishSchema(); Random random = new Random(); int numV = 1000; TitanVertex previous = null; for (int i = 0; i < numV; i++) { TitanVertex v = graph.addVertex( "kid", random.nextInt(numV), "name", "v" + i); if (previous != null) { Edge e = v.addEdge("knows", previous, "kid", random.nextInt(numV / 2)); } previous = v; } verifyElementOrder(graph.query().orderBy("kid", incr).limit(500).vertices(), "kid", Order.ASC, 500); verifyElementOrder(graph.query().orderBy("kid", incr).limit(300).edges(), "kid", Order.ASC, 300); verifyElementOrder(graph.query().orderBy("kid", decr).limit(400).vertices(), "kid", Order.DESC, 400); verifyElementOrder(graph.query().orderBy("kid", decr).limit(200).edges(), "kid", Order.DESC, 200); clopen(); //Copied from above verifyElementOrder(graph.query().orderBy("kid", incr).limit(500).vertices(), "kid", Order.ASC, 500); verifyElementOrder(graph.query().orderBy("kid", incr).limit(300).edges(), "kid", Order.ASC, 300); verifyElementOrder(graph.query().orderBy("kid", decr).limit(400).vertices(), "kid", Order.DESC, 400); verifyElementOrder(graph.query().orderBy("kid", decr).limit(200).edges(), "kid", Order.DESC, 200); }
finishSchema(); clopen();
@Test public void testForceIndexUsage() { PropertyKey age = makeKey("age", Integer.class); PropertyKey time = makeKey("time", Long.class); mgmt.buildIndex("time", Vertex.class).addKey(time).buildCompositeIndex(); finishSchema(); for (int i = 1; i <= 10; i++) { TitanVertex v = tx.addVertex("time", i, "age", i); } //Graph query with and with-out index support assertCount(1, tx.query().has("time", 5).vertices()); assertCount(1, tx.query().has("age", 6).vertices()); clopen(option(FORCE_INDEX_USAGE), true); //Query with-out index support should now throw exception assertCount(1, tx.query().has("time", 5).vertices()); try { assertCount(1, tx.query().has("age", 6).vertices()); fail(); } catch (Exception e) { } }
/** * Very simple graph operation to ensure minimal functionality and cleanup */ @Test public void testBasic() { PropertyKey uid = makeVertexIndexedUniqueKey("name", String.class); finishSchema(); TitanVertex n1 = tx.addVertex(); uid = tx.getPropertyKey("name"); n1.property(uid.name(), "abcd"); clopen(); long nid = n1.longId(); uid = tx.getPropertyKey("name"); assertTrue(getV(tx, nid) != null); assertTrue(getV(tx, uid.longId()) != null); assertMissing(tx, nid + 64); uid = tx.getPropertyKey(uid.name()); n1 = getV(tx, nid); assertEquals(n1, getOnlyVertex(tx.query().has(uid.name(), "abcd"))); assertEquals(1, Iterables.size(n1.query().relations())); //TODO: how to expose relations? assertEquals("abcd", n1.value(uid.name())); assertCount(1, tx.query().vertices()); close(); TitanCleanup.clear(graph); open(config); assertEmpty(tx.query().vertices()); }
public void testTransactionalScopeOfSchemaTypes() { makeVertexIndexedUniqueKey("domain", String.class); finishSchema();
@Test public void testTinkerPopCardinality() { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.SINGLE).dataType(String.class).make(); PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make(); mgmt.buildIndex("byId", Vertex.class).addKey(id).buildCompositeIndex(); finishSchema(); GraphTraversalSource gts; Vertex v; v = graph.addVertex("id", 1); v.property(single, "name", "t1"); graph.addVertex("id", 2, "names", "n1", "names", "n2"); graph.tx().commit(); gts = graph.traversal(); v = gts.V().has("id", 1).next(); v.property(single, "name", "t2"); v = gts.V().has("id", 1).next(); v.property(single, "name", "t3"); assertCount(1, gts.V(v).properties("name")); assertCount(2, gts.V().has("id", 2).properties("names")); assertCount(2, gts.V().hasLabel("vertex")); }
/** * This test exercises different types of updates against cardinality restricted properties * to ensure that the resulting behavior is fully consistent. */ @Test public void testPropertyCardinality() { PropertyKey uid = mgmt.makePropertyKey("uid").dataType(Long.class).cardinality(Cardinality.SINGLE).make(); PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex("byUid", Vertex.class).addKey(uid).unique().buildCompositeIndex(); mgmt.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex(); finishSchema(); TitanVertex v1 = tx.addVertex(); v1.property("name", "name1"); TitanVertex v2 = tx.addVertex(); v2.property("uid", 512); newTx(); v1 = tx.getVertex(v1.longId()); v1.property("name", "name2"); //Ensure that the old index record gets removed v2 = tx.getVertex(v2.longId()); v2.property("uid", 512); //Ensure that replacement is allowed newTx(); assertCount(0, tx.query().has("name", "name1").vertices()); assertCount(1, tx.query().has("name", "name2").vertices()); assertCount(1, tx.query().has("uid", 512).vertices()); }
mgmt.buildIndex("timeIndex", Vertex.class).addKey(time).buildCompositeIndex(); mgmt.makeVertexLabel("people").make(); finishSchema(); assertEquals("byTime", gindex.name()); finishSchema();
@Test public void testLimitWithMixedIndexCoverage() { final String vt = "vt"; final String fn = "firstname"; final String user = "user"; final String alice = "alice"; final String bob = "bob"; PropertyKey vtk = makeVertexIndexedKey(vt, String.class); PropertyKey fnk = makeKey(fn, String.class); finishSchema(); TitanVertex a = tx.addVertex(vt, user, fn, "alice"); TitanVertex b = tx.addVertex(vt, user, fn, "bob"); TitanVertex v; v = getOnlyElement(tx.query().has(vt, user).has(fn, bob).limit(1).vertices()); assertEquals(bob, v.value(fn)); assertEquals(user, v.value(vt)); v = getOnlyElement(tx.query().has(vt, user).has(fn, alice).limit(1).vertices()); assertEquals(alice, v.value(fn)); assertEquals(user, v.value(vt)); tx.commit(); tx = graph.newTransaction(); v = getOnlyElement(tx.query().has(vt, user).has(fn, bob).limit(1).vertices()); assertEquals(bob, v.value(fn)); assertEquals(user, v.value(vt)); v = getOnlyElement(tx.query().has(vt, user).has(fn, alice).limit(1).vertices()); assertEquals(alice, v.value(fn)); assertEquals(user, v.value(vt)); }
final String namen = "name"; makeVertexIndexedUniqueKey(namen, String.class); finishSchema();
mgmt.buildEdgeIndex(bought, "byTimeDesc", BOTH, decr, time); mgmt.buildEdgeIndex(bought, "byTimeIncr", BOTH, incr, time); finishSchema();