@Override public void run(TitanTransaction tx) { TitanVertex v1 = tx.addVertex("time", 2, "text", "hello"); } });
@Override public void run(TitanTransaction tx) { TitanVertex v1 = tx.addVertex("person"); v1.property(VertexProperty.Cardinality.single, "time", 1); } });
private int growVertex(Vertex vertex, int depth, int maxDepth, int maxBranch) { vertex.property(VertexProperty.Cardinality.single, "distance", depth); int total=1; if (depth>=maxDepth) return total; for (int i=0;i<random.nextInt(maxBranch)+1;i++) { int dist = random.nextInt(3)+1; TitanVertex n = tx.addVertex(); n.addEdge("connect",vertex, "distance",dist); total+=growVertex(n,depth+dist,maxDepth,maxBranch); } return total; }
@Override public void run(TitanTransaction tx) { TitanVertex a = tx.addVertex(); TitanVertex base = getV(tx, baseVid); base.addEdge("married", a); } }, parallelThreads);
@Override public void run() { TitanTransaction tx = graph.newTransaction(); TitanVertex[] vs = new TitanVertex[verticesPerTask]; for (int j=0;j<verticesPerTask;j++) { vs[j]=tx.addVertex(); vs[j].property(VertexProperty.Cardinality.single, "w", random.nextInt(maxWeight)); } for (int j=0;j<verticesPerTask*10;j++) { TitanEdge e = vs[random.nextInt(verticesPerTask)].addEdge("l",vs[random.nextInt(verticesPerTask)]); e.property("t",random.nextInt(maxTime)); } System.out.print("."); tx.commit(); } });
private void addVertex(int time, String text, double height, String[] phones) { newTx(); TitanVertex v = tx.addVertex("text", text, "time", time, "height", height); for (String phone : phones) { v.property("phone", phone); } newTx(); }
@Override public void run() { for (int r = 0; r < rounds; r++) { TitanTransaction tx = graph.newTransaction(); TitanVertex previous = null; for (int c = 0; c < commitSize; c++) { TitanVertex v = tx.addVertex(); long uid = uidCounter.incrementAndGet(); v.property(VertexProperty.Cardinality.single, "uid", uid); v.property(VertexProperty.Cardinality.single, "name", "user" + uid); if (previous != null) { v.addEdge("friend", previous, "time", Math.abs(random.nextInt())); } previous = v; } tx.commit(); } } });
@Override public void run() { while (run.get()) { TitanTransaction tx = graph.newTransaction(); try { for (int i = 0; i < batchV; i++) { TitanVertex v = tx.addVertex(); v.property("k", random.nextInt(maxK)); v.property("q", random.nextInt(maxQ)); } tx.commit(); } catch (Throwable e) { e.printStackTrace(); } finally { if (tx.isOpen()) tx.rollback(); } } } });
private void expand(Vertex v, final int distance, final int diameter, final int branch) { v.property(VertexProperty.Cardinality.single, "distance", distance); if (distance<diameter) { TitanVertex previous = null; for (int i=0;i<branch;i++) { TitanVertex u = tx.addVertex(); u.addEdge("likes",v); log.debug("likes {}->{}", u.id(), v.id()); // Commented since the PageRank implementation does not discriminate by label // if (previous!=null) { // u.addEdge("knows",previous); // log.error("knows {}->{}", u.id(), v.id()); // } previous=u; expand(u,distance+1,diameter,branch); } } }
@Test public void testIndexQueryWithScore() throws InterruptedException { PropertyKey textKey = mgmt.makePropertyKey("text").dataType(String.class).make(); mgmt.buildIndex("store1", Vertex.class).addKey(textKey).buildMixedIndex(INDEX); mgmt.commit(); TitanVertex v1 = tx.addVertex(); TitanVertex v2 = tx.addVertex(); TitanVertex v3 = tx.addVertex(); v1.property("text", "Hello Hello Hello Hello Hello Hello Hello Hello"); v2.property("text", "Hello abab abab fsdfsd sfdfsd sdffs fsdsdf fdf fsdfsd aera fsad abab abab fsdfsd sfdf"); v3.property("text", "Hello"); tx.commit(); Thread.sleep(5000); Set<Double> scores = new HashSet<Double>(); for (TitanIndexQuery.Result<TitanVertex> r : graph.indexQuery("store1", "v.text:(Hello)").vertices()) { scores.add(r.getScore()); } Assert.assertEquals(3, scores.size()); }
private void initializeGraph() { //Create schema for (int i = 0; i < REL_COUNT; i++) { makeLabel("rel" + i); } makeVertexIndexedUniqueKey("uid",Integer.class); finishSchema(); // Generate synthetic graph Vertex vertices[] = new Vertex[VERTEX_COUNT]; for (int i = 0; i < VERTEX_COUNT; i++) { vertices[i] = tx.addVertex("uid", i); } for (int i = 0; i < VERTEX_COUNT; i++) { for (int r = 0; r < REL_COUNT; r++) { for (int j = 1; j <= EDGE_COUNT; j++) { vertices[i].addEdge("rel"+r, vertices[wrapAround(i + j, VERTEX_COUNT)]); } } } // Get a new transaction clopen(); }
@Test // this tests a case when there as AND with a single CONTAINS condition inside AND(name:(was here)) // which (in case of Solr) spans multiple conditions such as AND(AND(name:was, name:here)) // so we need to make sure that we don't apply AND twice. public void testContainsWithMultipleValues() throws Exception { PropertyKey name = makeKey("name", String.class); mgmt.buildIndex("store1", Vertex.class).addKey(name).buildMixedIndex(INDEX); mgmt.commit(); TitanVertex v1 = tx.addVertex(); v1.property("name", "hercules was here"); tx.commit(); Thread.sleep(2000); TitanVertex r = Iterables.<TitanVertex>get(graph.query().has("name", Text.CONTAINS, "hercules here").vertices(), 0); Assert.assertEquals(r.property("name").value(), "hercules was here"); }
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(); // System.out.println("Time: " + (System.currentTimeMillis()-start)); 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())); } }
@Test public void testNestedTransactions() { Vertex v1 = graph.addVertex(); newTx(); Vertex v2 = tx.addVertex(); v2.property("name", "foo"); tx.commit(); v1.addEdge("related", graph.traversal().V(v2).next()); graph.tx().commit(); assertCount(1, v1.edges(OUT)); }
@Test public void concurrentIndexTest() { makeVertexIndexedUniqueKey("uid", String.class); makeVertexIndexedKey("value", Object.class); finishSchema(); TitanVertex v = tx.addVertex("uid", "v"); clopen(); //Concurrent index addition TitanTransaction tx1 = graph.newTransaction(); TitanTransaction tx2 = graph.newTransaction(); getVertex(tx1, "uid", "v").property(VertexProperty.Cardinality.single, "value", 11); getVertex(tx2, "uid", "v").property(VertexProperty.Cardinality.single, "value", 11); tx1.commit(); tx2.commit(); assertEquals("v", Iterators.<String>getOnlyElement(Iterables.<TitanVertex>getOnlyElement(tx.query().has("value", 11).vertices()).values("uid"))); }
@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) { } }
/** * Tests that self-loop edges are handled and counted correctly */ @Test public void testSelfLoop() { TitanVertex v = tx.addVertex(); v.addEdge("self", v); assertCount(1, v.query().direction(Direction.OUT).labels("self").edges()); assertCount(1, v.query().direction(Direction.IN).labels("self").edges()); assertCount(2, v.query().direction(Direction.BOTH).labels("self").edges()); clopen(); v = getV(tx, v); assertNotNull(v); assertCount(1, v.query().direction(Direction.IN).labels("self").edges()); assertCount(1, v.query().direction(Direction.OUT).labels("self").edges()); assertCount(1, v.query().direction(Direction.IN).labels("self").edges()); assertCount(2, v.query().direction(Direction.BOTH).labels("self").edges()); }