public EdgeLabel makeLabel(String name) { return mgmt.makeEdgeLabel(name).make(); }
public void loadData(final int numVertices, final int numThreads) throws Exception { makeKey("w",Integer.class); PropertyKey time = makeKey("t",Long.class); ((StandardEdgeLabelMaker)mgmt.makeEdgeLabel("l")).sortKey(time).make(); finishSchema();
@Test public void testReservedNamesRejectedForEdgeLabels() { for (String s : ILLEGAL_USER_DEFINED_NAMES) { TitanManagement tm = graph.openManagement(); try { tm.makeEdgeLabel(s); Assert.fail("Edge label \"" + s + "\" must be rejected"); } catch (IllegalArgumentException e) { log.debug("Caught expected exception", e); } finally { tm.commit(); } } }
EdgeLabelMaker tm = mgmt.makeEdgeLabel("test" + i); if (i % 4 == 1) tm.unidirected(); tm.make();
@Override public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) { if (loadGraphWith != null) { this.createIndices((TitanGraph) g, loadGraphWith.value()); } else { if (TransactionTest.class.equals(testClass) && testName.equalsIgnoreCase("shouldExecuteWithCompetingThreads")) { TitanManagement mgmt = ((TitanGraph) g).openManagement(); mgmt.makePropertyKey("blah").dataType(Double.class).make(); mgmt.makePropertyKey("bloop").dataType(Integer.class).make(); mgmt.makePropertyKey("test").dataType(Object.class).make(); mgmt.makeEdgeLabel("friend").make(); mgmt.commit(); } } super.loadGraphData(g, loadGraphWith, testClass, testName); }
@Test public void testPageRank() throws ExecutionException, InterruptedException { mgmt.makePropertyKey("distance").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make(); mgmt.makeEdgeLabel("likes").multiplicity(Multiplicity.MULTI).make(); finishSchema(); final int branch = 6;
@Test public void testGettingUndefinedEdgeLabelTTL() { if (!features.hasCellTTL()) { return; } // getTTL should return a null duration on an extant type without a TTL mgmt.makeEdgeLabel("likes").make(); mgmt.commit(); graph.tx().rollback(); // Check getTTL on edge label mgmt = graph.openManagement(); assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getEdgeLabel("likes"))); mgmt.rollback(); }
private int generateRandomGraph(int numV) { mgmt.makePropertyKey("uid").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make(); mgmt.makePropertyKey("values").cardinality(Cardinality.LIST).dataType(Integer.class).make(); mgmt.makePropertyKey("numvals").dataType(Integer.class).make(); finishSchema(); int numE = 0; TitanVertex[] vs = new TitanVertex[numV]; for (int i=0;i<numV;i++) { vs[i] = tx.addVertex("uid",i+1); int numVals = random.nextInt(5)+1; vs[i].property(VertexProperty.Cardinality.single, "numvals", numVals); for (int j=0;j<numVals;j++) { vs[i].property("values",random.nextInt(100)); } } for (int i=0;i<numV;i++) { int edges = i+1; TitanVertex v = vs[i]; for (int j=0;j<edges;j++) { TitanVertex u = vs[random.nextInt(numV)]; v.addEdge("knows", u); numE++; } } assertEquals(numV*(numV+1),numE*2); return numE; }
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())); } }
.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();
EdgeLabel wavedAt = mgmt.makeEdgeLabel("wavedAt").signature(time).make(); mgmt.buildEdgeIndex(wavedAt, "timeindex", Direction.BOTH, decr, time); mgmt.buildIndex("edge-time", Edge.class).addKey(time).buildCompositeIndex();
@Test public void testEdgeTTLWithTransactions() throws Exception { if (!features.hasCellTTL()) { return; } EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make(); mgmt.setTTL(label1, Duration.ofSeconds(1)); assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1)); mgmt.commit(); TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex(); v1.addEdge("likes", v2); // pre-commit state of the edge. It is not yet subject to TTL assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); Thread.sleep(1001); // the edge should have expired by now, but only if it had been committed assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); graph.tx().commit(); // still here, because we have just committed the edge. Its countdown starts at the commit assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); Thread.sleep(1001); // the edge has expired in Cassandra, but still appears alive in this transaction assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); // syncing with the data store, we see that the edge has expired graph.tx().rollback(); assertEmpty(v1.query().direction(Direction.OUT).vertices()); }
EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make(); int ttl1 = 1; int ttl2 = 4; mgmt.setTTL(label1, Duration.ofSeconds(ttl1)); EdgeLabel label2 = mgmt.makeEdgeLabel("dislikes").make(); mgmt.setTTL(label2, Duration.ofSeconds(ttl2)); EdgeLabel label3 = mgmt.makeEdgeLabel("indifferentTo").make(); assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1)); assertEquals(Duration.ofSeconds(ttl2), mgmt.getTTL(label2));
EdgeLabel likes = mgmt.makeEdgeLabel("likes").make(); mgmt.setTTL(likes, Duration.ofMillis(initialTTLMillis)); mgmt.commit();
makeKey("weight", Double.class); PropertyKey uid = makeVertexIndexedUniqueKey("uid", Integer.class); ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("knows")).sortKey(uid).sortOrder(Order.DESC).directed().make(); mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make(); finishSchema();
@Test public void testShortestDistance() throws Exception { PropertyKey distance = mgmt.makePropertyKey("distance").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("connect").signature(distance).multiplicity(Multiplicity.MULTI).make(); finishSchema();
EdgeLabel likes = mgmt.makeEdgeLabel("likes").make(); EdgeLabel hasLiked = mgmt.makeEdgeLabel("hasLiked").make(); mgmt.setTTL(likes, Duration.ofSeconds(ttl)); assertEquals(Duration.ofSeconds(ttl), mgmt.getTTL(likes));
@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); }
private void setupChainGraph(int numV, String[] strs, boolean sameNameMapping) { clopen(option(INDEX_NAME_MAPPING, INDEX), sameNameMapping); TitanGraphIndex vindex = getExternalIndex(Vertex.class, INDEX); TitanGraphIndex eindex = getExternalIndex(Edge.class, INDEX); TitanGraphIndex pindex = getExternalIndex(TitanVertexProperty.class, INDEX); PropertyKey name = makeKey("name", String.class); mgmt.addIndexKey(vindex, name, getStringMapping()); mgmt.addIndexKey(eindex, name, getStringMapping()); mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr")); PropertyKey text = makeKey("text", String.class); mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name", "xtext")); mgmt.addIndexKey(eindex, text, getTextMapping()); mgmt.addIndexKey(pindex, text, getTextMapping()); mgmt.makeEdgeLabel("knows").signature(name).make(); mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make(); finishSchema(); TitanVertex previous = null; for (int i = 0; i < numV; i++) { TitanVertex v = graph.addVertex("name", strs[i % strs.length], "text", strs[i % strs.length]); Edge e = v.addEdge("knows", previous == null ? v : previous, "name", strs[i % strs.length], "text", strs[i % strs.length]); VertexProperty p = v.property("uid", "v" + i, "name", strs[i % strs.length], "text", strs[i % strs.length]); previous = v; } }
@Test public void testSchemaNameChange() { PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make(); mgmt.buildEdgeIndex(knows, "byTime", Direction.BOTH, time); mgmt.buildIndex("timeIndex", Vertex.class).addKey(time).buildCompositeIndex();