verifyVerticesRetrieval(vids1, Lists.newArrayList(tx.getVertices(vids1))); verifyVerticesRetrieval(vids1, Lists.newArrayList(tx.getVertices(vids1))); verifyVerticesRetrieval(vids2, Lists.newArrayList(tx.getVertices(vids2)));
@Test public void testSimpleUpdate() { PropertyKey name = makeKey("name", String.class); EdgeLabel knows = makeLabel("knows"); mgmt.buildIndex("namev", Vertex.class).addKey(name).buildMixedIndex(INDEX); mgmt.buildIndex("namee", Edge.class).addKey(name).buildMixedIndex(INDEX); finishSchema(); TitanVertex v = tx.addVertex("name", "Marko Rodriguez"); Edge e = v.addEdge("knows", v, "name", "Hulu Bubab"); assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices()); assertCount(1, tx.query().has("name", Text.CONTAINS, "Hulu").edges()); for (Vertex u : tx.getVertices()) assertEquals("Marko Rodriguez", u.value("name")); clopen(); assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices()); assertCount(1, tx.query().has("name", Text.CONTAINS, "Hulu").edges()); for (Vertex u : tx.getVertices()) assertEquals("Marko Rodriguez", u.value("name")); v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko")); v.property(VertexProperty.Cardinality.single, "name", "Marko"); e = getOnlyEdge(v.query().direction(Direction.OUT)); e.property("name", "Tubu Rubu"); assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices()); assertCount(1, tx.query().has("name", Text.CONTAINS, "Rubu").edges()); assertCount(0, tx.query().has("name", Text.CONTAINS, "Hulu").edges()); for (Vertex u : tx.getVertices()) assertEquals("Marko", u.value("name")); clopen(); assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices()); assertCount(1, tx.query().has("name", Text.CONTAINS, "Rubu").edges()); assertCount(0, tx.query().has("name", Text.CONTAINS, "Hulu").edges()); for (Vertex u : tx.getVertices()) assertEquals("Marko", u.value("name")); }
1, new boolean[]{true, true}, "mixed"); for (Vertex u : tx.getVertices()) { String n = u.<String>value("name"); if (n.endsWith("Don")) {
@Override public void run() { for (int i = 0; i < vertexCount; i++) { for (int p = 0; p < propCount; p++) { tx.getVertices("p" + p, i); } } } }
@Override public void run() { for (int i = 0; i < vertexCount; i++) { for (int p = 0; p < propCount; p++) { tx.getVertices("p" + p, i); } } } }
public static TitanVertex getVertex(TitanTransaction tx, String key, Object value) { return (TitanVertex)Iterables.getOnlyElement(tx.getVertices(key,value),null); }
public static TitanVertex getVertex(TitanTransaction tx, PropertyKey key, Object value) { return Iterables.getOnlyElement(tx.getVertices(key,value),null); }
@Override public void run() { while (true) { // Set propType to a random value on a random node TitanVertex n = Iterables.getOnlyElement(tx.getVertices(idProp, RandomGenerator.randomInt(0, nodeCount))); String propVal = RandomGenerator.randomString(); n.addProperty(randomProp, propVal); if (Thread.interrupted()) break; // Is creating the same property twice an error? } } }
@Override public void run() { while (true) { // Set propType to a random value on a random node TitanVertex n = Iterables.getOnlyElement(tx.getVertices(idProp, RandomGenerator.randomInt(0, nodeCount))); String propVal = RandomGenerator.randomString(); n.addProperty(randomProp, propVal); if (Thread.interrupted()) break; // Is creating the same property twice an error? } } }
@Test public void testSimpleGlobalVertexCount() { final int n = 3; for (int i = 0; i < n; i++) { tx.addVertex(); } assertEquals(n, Iterables.size(tx.getVertices())); tx.commit(); tx = graph.newTransaction(); assertEquals(n, Iterables.size(tx.getVertices())); } }
@Override public void run() { while (true) { // Make or break relType between two (possibly same) random nodes // TitanVertex source = tx.getVertex(idProp, RandomGenerator.randomInt(0, nodeCount)); // TitanVertex sink = tx.getVertex(idProp, RandomGenerator.randomInt(0, nodeCount)); TitanVertex source = Iterables.getOnlyElement(tx.getVertices(idProp, 0)); TitanVertex sink = Iterables.getOnlyElement(tx.getVertices(idProp, 1)); for (TitanEdge r : source.getTitanEdges(Direction.OUT, relType)) { if (r.getVertex(Direction.IN).getLongId() == sink.getLongId()) { r.remove(); continue; } } source.addEdge(relType, sink); if (Thread.interrupted()) break; } }
@Override public void run() { while (true) { // Make or break relType between two (possibly same) random nodes // TitanVertex source = tx.getVertex(idProp, RandomGenerator.randomInt(0, nodeCount)); // TitanVertex sink = tx.getVertex(idProp, RandomGenerator.randomInt(0, nodeCount)); TitanVertex source = Iterables.getOnlyElement(tx.getVertices(idProp, 0)); TitanVertex sink = Iterables.getOnlyElement(tx.getVertices(idProp, 1)); for (TitanEdge r : source.getTitanEdges(Direction.OUT, relType)) { if (r.getVertex(Direction.IN).getID() == sink.getID()) { r.remove(); continue; } } source.addEdge(relType, sink); if (Thread.interrupted()) break; } }
@Override protected void doRun() throws Exception { TitanVertex n = Iterables.getOnlyElement(tx.getVertices(id, nodeid)); for (int i = 0; i < nodeTraversalCount; i++) { assertEquals("On vertex: " + n.getLongId(), expectedEdges, Iterables.size(n.getTitanEdges(Direction.BOTH, relTypeToTraverse))); for (TitanEdge r : n.getTitanEdges(Direction.OUT, relTypeToTraverse)) { n = r.getVertex(Direction.IN); } } } }
@Override protected void doRun() throws Exception { TitanVertex n = Iterables.getOnlyElement(tx.getVertices(id, nodeid)); for (int i = 0; i < nodeTraversalCount; i++) { assertEquals("On vertex: " + n.getID(), expectedEdges, Iterables.size(n.getTitanEdges(Direction.BOTH, relTypeToTraverse))); for (TitanEdge r : n.getTitanEdges(Direction.OUT, relTypeToTraverse)) { n = r.getVertex(Direction.IN); } } } }
@Test public void testInTxIndex() throws Exception { int trials = 2; int numV = 2000; int offset = 10000; tx.makeKey("uid").dataType(Long.class).indexed(Vertex.class).single().make(); newTx(); long start = System.currentTimeMillis(); for (int t = 0; t < trials; t++) { for (int i = offset; i < offset + numV; i++) { if (Iterables.isEmpty(tx.getVertices("uid", Long.valueOf(i)))) { Vertex v = tx.addVertex(); v.setProperty("uid", Long.valueOf(i)); } } } assertEquals(numV, Iterables.size(tx.getVertices())); System.out.println("Total time (ms): " + (System.currentTimeMillis() - start)); }
@Test public void testVertexDeletionWithIndex() { TitanKey name = makeStringPropertyKey("name"); Vertex v1 = tx.addVertex(null); v1.setProperty("name", "v1"); Vertex v2 = tx.addVertex(null); v2.setProperty("name", "v2"); Edge e = tx.addEdge(null, v1, v2, "some_edge"); clopen(); v1 = tx.getVertex(v1); tx.removeVertex(v1); v2 = tx.getVertices("name", "v2").iterator().next(); // generates IllegalArgumentException assertNotNull(v2); assertEquals(0, Iterables.size(tx.getVertices("name", "v1"))); }
@Test public void testRepeatingIterationOverAllVertices() { if (graph.getFeatures().supportsVertexIteration) { TitanVertex vertex = tx.addVertex(); vertex.setProperty("key", "value"); tx.commit(); for (int i = 0; i < 100; i++) { tx = graph.newTransaction(); Iterable<Vertex> vertices = tx.getVertices(); assertEquals(1, Iterables.size(vertices)); assertEquals("value", Iterables.getOnlyElement(vertices).getProperty("key")); tx.commit(); } } }
@Test public void concurrentIndexTest() { makeVertexIndexedUniqueKey("uid", String.class); makeVertexIndexedKey("value", Object.class); finishSchema(); TitanVertex v = tx.addVertex(); v.setProperty("uid", "v"); clopen(); //Concurrent index addition TitanTransaction tx1 = graph.newTransaction(); TitanTransaction tx2 = graph.newTransaction(); getVertex(tx1, "uid", "v").setProperty("value", 11); getVertex(tx2, "uid", "v").setProperty("value", 11); tx1.commit(); tx2.commit(); assertEquals("v", Iterables.getOnlyElement(tx.getVertices("value", 11)).getProperty("uid")); }
@Test public void testVertexDeletion() throws Exception { TitanKey name = makeUniqueStringPropertyKey("name"); newTx(); TitanVertex v = tx.addVertex(); TitanProperty p = v.addProperty("name", "oldName"); newTx(); TitanVertex v1 = tx.getVertex(v.getID()); tx.removeVertex(v1); newTx(); if (graph.getFeatures().supportsVertexIteration) { int count = 0; for (Vertex vertex : tx.getVertices()) count++; assertEquals(0, count); } }
@Test public void concurrentIndexTest() { TitanKey id = tx.makeKey("uid").single().unique().indexed(Vertex.class).dataType(String.class).make(); TitanKey value = tx.makeKey("value").single(TypeMaker.UniquenessConsistency.NO_LOCK).dataType(Object.class).indexed(Vertex.class).make(); TitanVertex v = tx.addVertex(); v.setProperty(id, "v"); clopen(); //Concurrent index addition TitanTransaction tx1 = graph.newTransaction(); TitanTransaction tx2 = graph.newTransaction(); tx1.getVertex(id, "v").setProperty("value", 11); tx2.getVertex(id, "v").setProperty("value", 11); tx1.commit(); tx2.commit(); assertEquals("v", Iterables.getOnlyElement(tx.getVertices("value", 11)).getProperty(id.getName())); }