v11.addEdge("knows", v12); v21.addEdge("knows", v11); fail(); } catch (IllegalStateException e) { v21.addEdge("knows", v22); tx2.commit(); try { v22.addEdge("knows", v21); fail(); } catch (IllegalStateException e) { v11.property(VertexProperty.Cardinality.single, "test", 5); fail(); } catch (IllegalStateException e) { tx.makeEdgeLabel("link").unidirected().make(); TitanVertex v3 = tx.addVertex(); v21.addEdge("link", v3); newTx(); v21 = getV(tx, v21); v3 = getOnlyElement(v21.query().direction(Direction.OUT).labels("link").vertices()); assertFalse(v3.isRemoved()); v3.remove(); newTx(); v21 = getV(tx, v21); v3 = getOnlyElement(v21.query().direction(Direction.OUT).labels("link").vertices()); assertFalse(v3.isRemoved());
private void verifyWriteAccess(TitanVertex... vertices) { if (config.isReadOnly()) throw new UnsupportedOperationException("Cannot create new entities in read-only transaction"); for (TitanVertex v : vertices) { if (v.hasId() && idInspector.isUnmodifiableVertex(v.longId()) && !v.isNew()) throw new SchemaViolationException("Cannot modify unmodifiable vertex: "+v); } verifyAccess(vertices); }
@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(); } } });
private void processTx(TitanTransaction tx, int txid, long vid, long uid) { TitanVertex v = tx.getVertex(vid); TitanVertex u = tx.getVertex(uid); assertEquals(5.0,v.<Decimal>getProperty("weight").doubleValue(),0.00001); TitanProperty p = Iterables.getOnlyElement(v.getProperties("weight")); assertEquals(1,p.getProperty("sig")); sign(v.addProperty("weight",6.0),txid); p = Iterables.getOnlyElement(v.getProperties("name")); assertEquals(1,p.getProperty("sig")); assertEquals("John",p.getValue()); p.remove(); sign(v.addProperty("name","Bob"),txid); for (String pkey : new String[]{"value","valuef"}) { p = Iterables.getOnlyElement(v.getProperties(pkey)); assertEquals(1,p.getProperty("sig")); assertEquals(2,p.getValue()); TitanEdge e = (TitanEdge)Iterables.getOnlyElement(v.getEdges(Direction.OUT,"es")); assertEquals(1,e.getProperty("sig")); e.remove(); sign(v.addEdge("es",u),txid); e = (TitanEdge)Iterables.getOnlyElement(v.getEdges(Direction.OUT,"o2o")); assertEquals(1,e.getProperty("sig")); sign(e,txid); e = (TitanEdge)Iterables.getOnlyElement(v.getEdges(Direction.OUT,"o2m")); assertEquals(1,e.getProperty("sig")); e.remove(); sign(v.addEdge("o2m",u),txid); for (String label : new String[]{"em","emf"}) { e = (TitanEdge)Iterables.getOnlyElement(v.getEdges(Direction.OUT,label));
g.property(VertexProperty.Cardinality.single, "gid", i); g.property(VertexProperty.Cardinality.single, "sig", 0); for (String n : names) { g.property("name", n); assertEquals(i, g.<Integer>value("gid").intValue()); assertEquals(0, g.<Integer>value("sig").intValue()); assertEquals("group", g.label()); assertCount(names.size(), g.properties("name")); assertTrue(getId(g) > 0); gids[i] = getId(g); if (i > 0) { g.addEdge("base", getV(tx, gids[0])); g.addEdge("one", getV(tx, gids[i - 1])); assertCount(1, g.query().direction(Direction.BOTH).labels("one").edges()); assertCount(1, g.query().direction(i % 2 == 0 ? Direction.IN : Direction.OUT).labels("one").edges()); assertCount(0, g.query().direction(i % 2 == 1 ? Direction.IN : Direction.OUT).labels("one").edges()); if (i > 0) { assertCount(1, g.query().direction(Direction.OUT).labels("base").edges()); } else { assertCount(numG - 1, g.query().direction(Direction.IN).labels("base").edges()); final int canonicalPartition = getPartitionID(g); assertEquals(g, (Vertex) getOnlyElement(tx.query().has("gid", i).vertices())); assertEquals(i, g.<Integer>value("gid").intValue()); assertCount(names.size(), g.properties("name"));
nodes[i].addProperty(name, names[i]); nodes[i].addProperty(id, ids[i]); if ((i + 1) % 100 == 0) log.debug("Added 100 nodes"); nodeEdges[i] = new ArrayList(10); for (int c : connectOff) { TitanEdge r = n.addEdge(connect, nodes[wrapAround(i + c, noNodes)]); nodeEdges[i].add(r); TitanEdge r = n.addEdge(knows, n2); r.setProperty(id, ((Number) n.getProperty(id)).intValue() + ((Number) n2.getProperty(id)).intValue()); r.setProperty(weight, k * 1.5); r.setProperty(name, i + "-" + k); Set[] nodeEdgeIds = new Set[noNodes]; for (int i = 0; i < noNodes; i++) { nodeIds[i] = nodes[i].getID(); nodeEdgeIds[i] = new HashSet(10); for (Object r : nodeEdges[i]) { TitanVertex n = tx.getVertex(id, ids[i]); assertEquals(n, tx.getVertex(name, names[i])); assertEquals(names[i], n.getProperty(name)); nodes[i] = n; assertEquals(nodeIds[i], n.getID()); assertEquals(connectOff.length + knowsOff.length, Iterables.size(n.getEdges(OUT))); assertEquals(connectOff.length, Iterables.size(n.getEdges(OUT, "connect"))); assertEquals(connectOff.length * 2, Iterables.size(n.getTitanEdges(BOTH, tx.getEdgeLabel("connect"))));
@Test public void removeGhostVertices() throws Exception { TitanVertex v1 = tx.addVertex("person"); v1.property("name","stephen"); TitanVertex v2 = tx.addVertex("person"); v1.property("name","marko"); TitanVertex v3 = tx.addVertex("person"); v1.property("name","dan"); v2.addEdge("knows",v3); v1.addEdge("knows",v2); newTx(); long v3id = getId(v3); v3.remove(); tx.commit(); v1 = getV(xx, v1id); assertNotNull(v1); v3.property("name", "deleted"); v3.addEdge("knows", v1); xx.commit(); v1 = getV(tx, v1id); assertNotNull(v1); assertEquals(v3id,v1.query().direction(Direction.IN).labels("knows").vertices().iterator().next().longId()); tx.commit(); mgmt.commit();
v.property("uid", "v1"); v.property("weight", 1.5); v.property("someid", "Hello"); v.property("name", "Bob"); v.property("name", "John"); VertexProperty p = v.property("value", 11); p.property("weight", 22); v.property("value", 33.3, "weight", 66.6); v.property("value", 11, "weight", 22); //same values are supported for list-properties v12.property("uid", "v12"); v13.property("uid", "v13"); v12.addEdge("parent", v, "weight", 4.5); v13.addEdge("parent", v, "weight", 4.5); v.addEdge("child", v12); v.addEdge("child", v13); v.addEdge("spouse", v12); v.addEdge("friend", v12); v.addEdge("friend", v12); //supports multi edges v.addEdge("connect", v12, "uid", "e1"); v.addEdge("link", v13); TitanVertex v2 = tx.addVertex("tweet"); v2.addEdge("link", v13); v12.addEdge("connect", v2); TitanEdge edge; v.property("weight", "x"); fail(); } catch (SchemaViolationException e) {
@Test public void testEdgesExceedCacheSize() { // Add a vertex with as many edges as the tx-cache-size. (20000 by default) int numEdges = graph.getConfiguration().getTxVertexCacheSize(); TitanVertex parentVertex = graph.addVertex(); for (int i = 0; i < numEdges; i++) { TitanVertex childVertex = graph.addVertex(); parentVertex.addEdge("friend", childVertex); } graph.tx().commit(); assertCount(numEdges, parentVertex.query().direction(Direction.OUT).edges()); // Remove an edge. parentVertex.query().direction(OUT).edges().iterator().next().remove(); // Check that getEdges returns one fewer. assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges()); // Run the same check one more time. // This fails! (Expected: 19999. Actual: 20000.) assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges()); }
TitanVertex n3 = tx.addVertex(); assertNotNull(n1.toString()); n1.addProperty(name, "Node1"); n2.addProperty(name, "Node2"); n3.addProperty(weight, 5.0); TitanEdge e = n1.addEdge(connect, n2); assertNotNull(e.toString()); assertEquals(n1, e.getVertex(OUT)); assertEquals(n2, e.getVertex(IN)); e = n2.addEdge(knows, n3); e.setProperty(weight, 3.0); e.setProperty(name, "HasProperties TitanRelation"); e = n3.addEdge(knows, n1); n3.addEdge(connect, n3); e.setProperty(id, 111); assertEquals(4, Iterables.size(n3.getEdges())); assertEquals(2, Iterables.size(n3.getEdges(Direction.OUT))); assertEquals(2, Iterables.size(n3.getEdges(Direction.IN))); n2 = tx.getVertex(name, "Node2"); assertNotNull(n2.toString()); assertEquals("Node2", n2.getProperty(name)); e = Iterables.getOnlyElement(n2.getTitanEdges(BOTH, connect)); assertNotNull(e.toString()); n1 = e.getVertex(OUT); assertEquals(e, Iterables.getOnlyElement(n2.getEdges(IN))); log.debug("Second:"); assertEquals(e, Iterables.getOnlyElement(n1.getEdges(OUT)));
TitanRelation findRelation(TitanTransaction tx) { TitanVertex v = ((StandardTitanTx)tx).getInternalVertex(outVertexId); if (v == null || v.isRemoved()) return null; TitanVertex typeVertex = tx.getVertex(typeId); if (typeVertex == null) return null; if (!(typeVertex instanceof RelationType)) throw new IllegalArgumentException("Invalid RelationIdentifier: typeID does not reference a type"); RelationType type = (RelationType) typeVertex; Iterable<? extends TitanRelation> rels; if (((RelationType) typeVertex).isEdgeLabel()) { Direction dir = Direction.OUT; TitanVertex other = ((StandardTitanTx)tx).getInternalVertex(inVertexId); if (other==null || other.isRemoved()) return null; if (((StandardTitanTx) tx).isPartitionedVertex(v) && !((StandardTitanTx) tx).isPartitionedVertex(other)) { //Swap for likely better performance TitanVertex tmp = other; other = v; v = tmp; dir = Direction.IN; } rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((EdgeLabel) type).direction(dir).adjacent(other).edges(); } else { rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((PropertyKey) type).properties(); } for (TitanRelation r : rels) { //Find current or previous relation if (r.longId() == relationId || ((r instanceof StandardRelation) && ((StandardRelation) r).getPreviousID() == relationId)) return r; } return null; }
v21.addEdge("knows", v11); fail(); } catch (IllegalStateException e) { v21.addEdge("knows", v22); tx2.commit(); try { v22.addEdge("knows", v21); fail(); } catch (IllegalStateException e) { v11.setProperty("test", 5); fail(); } catch (IllegalStateException e) { v21 = tx.getVertex(v21.getLongId()); tx.makeEdgeLabel("link").unidirected().make(); TitanVertex v3 = tx.addVertex(); v21.addEdge("link", v3); newTx(); v21 = tx.getVertex(v21.getLongId()); v3 = (TitanVertex) Iterables.getOnlyElement(v21.getVertices(OUT, "link")); assertFalse(v3.isRemoved()); v3.remove(); newTx(); v21 = tx.getVertex(v21.getLongId()); v3 = (TitanVertex) Iterables.getOnlyElement(v21.getVertices(OUT, "link")); assertFalse(v3.isRemoved()); newTx();
v.setProperty("time",5); v.addEdge("knows",v).setProperty("time",11); assertEquals("people",v.getLabel()); assertEquals(5,v.getProperty("time")); assertEquals(1,Iterables.size(v.getEdges(IN,"knows"))); assertEquals(1,v.query().labels("knows").direction(OUT).has("time",11).count()); newTx(); v = (TitanVertex)Iterables.getOnlyElement(tx.query().has("time",5).vertices()); assertNotNull(v); assertEquals("person",v.getLabel()); assertEquals(5,v.getProperty("time")); assertEquals(1,Iterables.size(v.getEdges(Direction.IN,"know"))); assertEquals(0,Iterables.size(v.getEdges(Direction.IN,"knows"))); assertEquals(1,v.query().labels("know").direction(OUT).has("time",11).count());
v21.addEdge("knows", v11); fail(); } catch (IllegalArgumentException e) { v21.addEdge("knows", v22); tx2.commit(); try { v22.addEdge("knows", v21); fail(); } catch (IllegalStateException e) { v11.setProperty("test", 5); fail(); } catch (IllegalStateException e) { v21 = tx.getVertex(v21.getID()); tx.makeLabel("link").unidirected().make(); TitanVertex v3 = tx.addVertex(); v21.addEdge("link", v3); newTx(); v21 = tx.getVertex(v21.getID()); v3 = (TitanVertex) Iterables.getOnlyElement(v21.getVertices(OUT, "link")); assertFalse(v3.isRemoved()); v3.remove(); newTx(); v21 = tx.getVertex(v21.getID()); v3 = (TitanVertex) Iterables.getOnlyElement(v21.getVertices(OUT, "link")); assertFalse(v3.isRemoved()); newTx();
@Test public void testBasic() { TitanKey weight = makeWeightPropertyKey("weight"); TitanVertex n1 = tx.addVertex(); n1.addProperty(weight, 10.5); clopen(); long nid = n1.getID(); assertTrue(tx.containsVertex(nid)); assertTrue(tx.containsVertex(weight.getID())); assertFalse(tx.containsVertex(nid + 64)); assertFalse(tx.containsVertex(weight.getID() + 64)); assertTrue(tx.containsType("weight")); weight = tx.getPropertyKey("weight"); assertEquals(weight.getDataType(), Double.class); assertEquals(weight.getName(), "weight"); n1 = tx.getVertex(nid); for (TitanProperty prop : n1.getProperties()) { Object o = prop.getValue(); } n1.query().relations(); assertEquals(10.5, n1.getProperty(weight)); }
v1.setProperty(name, "a"); v2.setProperty(age, "14"); v2.setProperty(name, "b"); v2.setProperty(age, "42"); tx1.commit(); long id1 = v1.getLongId(); long id2 = v2.getLongId(); v1 = tx2.getVertex(id1); v2 = tx2.getVertex(id2); for (TitanProperty prop : v1.getProperties(name)) { if (features.hasTimestamps()) { Timestamp t = prop.getProperty("$timestamp"); assertEquals(1,v1.query().has("$timestamp",new Timestamp(100,unit)).propertyCount()); assertEquals(1,v1.query().has("$timestamp", Cmp.GREATER_THAN,new Timestamp(10, unit)).propertyCount()); v1.removeProperty(name); v1.setProperty(address, "xyz"); Edge edge = tx2.addEdge(1, v2, v1, "parent"); tx2.commit(); v1.removeProperty(address); tx3.commit(); v2.setProperty(age, "15"); tx4.removeEdge(tx4.getEdge(edgeId)); tx4.commit();
TitanTransaction tx2 = graph.buildTransaction().logIdentifier(userlogName).start(); TitanVertex v1 = tx2.addVertex("weight", 111.1); v1.addEdge("knows", v1); tx2.commit(); final long v1id = getId(v1); tx2 = graph.buildTransaction().logIdentifier(userlogName).start(); TitanVertex v2 = tx2.addVertex("weight", 222.2); v2.addEdge("knows", getV(tx2, v1id)); tx2.commit(); final long v2id = getId(v2); assertEquals(111.1, v1.<Float>value("weight").doubleValue(), 0.01); assertEquals(222.2, getV(tx2, v2).<Float>value("weight").doubleValue(), 0.01); tx2.commit(); tx2 = graph.buildTransaction().logIdentifier(userlogName).start(); v2 = getV(tx2, v2id); assertEquals(222.2, v2.<Float>value("weight").doubleValue(), 0.01); v2.remove(); tx2.commit(); tx2 = graph.buildTransaction().logIdentifier(userlogName).start(); v1 = getV(tx2, v1id); assertEquals(111.1, v1.<Float>value("weight").doubleValue(), 0.01); Edge e = getOnlyElement(v1.query().direction(Direction.OUT).labels("knows").edges()); assertFalse(e.property("weight").isPresent()); e.property("weight", 44.4);
public static Set<String> getPropertyKeys(TitanVertex v) { final Set<String> s = new HashSet<>(); v.query().properties().forEach( p -> s.add(p.propertyKey().name())); return s; }
@Override public void run() { TitanTransaction tx = graph.newTransaction(); long ruid = random.nextInt(maxUID) + 1; getVertex(tx,"uid", ruid).property(VertexProperty.Cardinality.single, "name", fixedName); for (int t = 1; t <= trials; t++) { TitanVertex v = getVertex(tx,"uid", random.nextInt(maxUID) + 1); assertCount(2, v.properties()); int count = 0; for (TitanEdge e : v.query().direction(Direction.BOTH).edges()) { count++; assertTrue(e.<Integer>value("time") >= 0); } assertTrue(count <= 2); // if (t%(trials/10)==0) System.out.println(t); } assertEquals(fixedName, getVertex(tx,"uid", ruid).value("name")); tx.commit(); } });