use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project titan by thinkaurelius.
the class TitanEventualGraphTest method processTx.
private void processTx(TitanTransaction tx, int txid, long vid, long uid) {
TitanVertex v = getV(tx, vid);
TitanVertex u = getV(tx, uid);
assertEquals(5.0, v.<Double>value("weight").doubleValue(), 0.00001);
VertexProperty p = getOnlyElement(v.properties("weight"));
assertEquals(1, p.<Integer>value("sig").intValue());
sign(v.property("weight", 6.0), txid);
p = getOnlyElement(v.properties("name"));
assertEquals(1, p.<Integer>value("sig").intValue());
assertEquals("John", p.value());
p.remove();
sign(v.property("name", "Bob"), txid);
for (String pkey : new String[] { "value", "valuef" }) {
p = getOnlyElement(v.properties(pkey));
assertEquals(1, p.<Integer>value("sig").intValue());
assertEquals(2, p.value());
sign((TitanVertexProperty) p, txid);
}
Edge e = getOnlyElement(v.query().direction(OUT).labels("es").edges());
assertEquals(1, e.<Integer>value("sig").intValue());
e.remove();
sign(v.addEdge("es", u), txid);
e = getOnlyElement(v.query().direction(OUT).labels("o2o").edges());
assertEquals(1, e.<Integer>value("sig").intValue());
sign((TitanEdge) e, txid);
e = getOnlyElement(v.query().direction(OUT).labels("o2m").edges());
assertEquals(1, e.<Integer>value("sig").intValue());
e.remove();
sign(v.addEdge("o2m", u), txid);
for (String label : new String[] { "em", "emf" }) {
e = getOnlyElement(v.query().direction(OUT).labels(label).edges());
assertEquals(1, e.<Integer>value("sig").intValue());
sign((TitanEdge) e, txid);
}
}
use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project titan by thinkaurelius.
the class TitanGraphTest method testThreadBoundTx.
/**
* Tests that elements can be accessed beyond their transactional boundaries if they
* are bound to single-threaded graph transactions
*/
@Test
@SuppressWarnings("deprecation")
public void testThreadBoundTx() {
PropertyKey t = mgmt.makePropertyKey("type").dataType(Integer.class).make();
mgmt.buildIndex("etype", Edge.class).addKey(t).buildCompositeIndex();
((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("friend")).sortKey(t).make();
finishSchema();
TitanVertex v1 = graph.addVertex("name", "Vertex1", "age", 35);
TitanVertex v2 = graph.addVertex("name", "Vertex2", "age", 45);
TitanVertex v3 = graph.addVertex("name", "Vertex3", "age", 55);
Edge e1 = v1.addEdge("knows", v2, "time", 5);
Edge e2 = v2.addEdge("knows", v3, "time", 15);
Edge e3 = v3.addEdge("knows", v1, "time", 25);
Edge e4 = v2.addEdge("friend", v2, "type", 1);
for (TitanVertex v : new TitanVertex[] { v1, v2, v3 }) {
assertCount(2, v.query().direction(Direction.BOTH).labels("knows").edges());
assertCount(1, v.query().direction(Direction.OUT).labels("knows").edges());
TitanEdge tmpE = getOnlyElement(v.query().direction(Direction.OUT).labels("knows").edges());
assertEquals(5, tmpE.<Integer>value("time") % 10);
}
e3.property("time", 35);
assertEquals(35, e3.<Integer>value("time").intValue());
v1.addEdge("friend", v2, "type", 0);
graph.tx().commit();
e4.property("type", 2);
TitanEdge ef = getOnlyElement(v1.query().direction(Direction.OUT).labels("friend").edges());
assertEquals(ef, (Edge) getOnlyElement(graph.query().has("type", 0).edges()));
ef.property("type", 1);
graph.tx().commit();
assertEquals(35, e3.<Integer>value("time").intValue());
e3 = getE(graph, e3);
e3.property("time", 45);
assertEquals(45, e3.<Integer>value("time").intValue());
assertEquals(15, e2.<Integer>value("time").intValue());
e2.property("time", 25);
assertEquals(25, e2.<Integer>value("time").intValue());
assertEquals(35, v1.<Integer>value("age").intValue());
assertEquals(55, v3.<Integer>value("age").intValue());
v3.property("age", 65);
assertEquals(65, v3.<Integer>value("age").intValue());
e1 = getE(graph, e1);
for (TitanVertex v : new TitanVertex[] { v1, v2, v3 }) {
assertCount(2, v.query().direction(Direction.BOTH).labels("knows").edges());
assertCount(1, v.query().direction(Direction.OUT).labels("knows").edges());
assertEquals(5, getOnlyElement(v.query().direction(Direction.OUT).labels("knows").edges()).<Integer>value("time").intValue() % 10);
}
graph.tx().commit();
VertexProperty prop = v1.properties().next();
assertTrue(getId(prop) > 0);
prop = (VertexProperty) ((Iterable) graph.multiQuery((TitanVertex) v1).properties().values().iterator().next()).iterator().next();
assertTrue(getId(prop) > 0);
assertEquals(45, e3.<Integer>value("time").intValue());
assertEquals(5, e1.<Integer>value("time").intValue());
assertEquals(35, v1.<Integer>value("age").intValue());
assertEquals(65, v3.<Integer>value("age").intValue());
for (TitanVertex v : new TitanVertex[] { v1, v2, v3 }) {
assertCount(2, v.query().direction(Direction.BOTH).labels("knows").edges());
assertCount(1, v.query().direction(Direction.OUT).labels("knows").edges());
assertEquals(5, getOnlyElement(v.query().direction(Direction.OUT).labels("knows").edges()).<Integer>value("time").intValue() % 10);
}
graph.tx().commit();
v1 = graph.addVertex();
v2 = graph.addVertex();
v1.addEdge("knows", v2);
graph.tx().commit();
v3 = graph.addVertex();
Edge e = v1.addEdge("knows", v3);
assertFalse(e.property("age").isPresent());
}
Aggregations