use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class VertexListTest method testLists.
@Test
public void testLists() {
int num = 13;
TitanGraph g = TitanFactory.open("inmemory");
StandardTitanTx tx = (StandardTitanTx) g.newTransaction();
VertexLongList vll = new VertexLongList(tx);
VertexArrayList val = new VertexArrayList(tx);
for (int i = 0; i < num; i++) {
TitanVertex v = tx.addVertex();
vll.add(v);
val.add(v);
}
assertEquals(num, Iterables.size(vll));
assertEquals(num, Iterables.size(val));
vll.sort();
val.sort();
assertTrue(vll.isSorted());
assertTrue(val.isSorted());
for (Iterable<TitanVertex> iterable : new Iterable[] { val, vll }) {
Iterator<TitanVertex> iter = iterable.iterator();
TitanVertex previous = null;
for (int i = 0; i < num; i++) {
TitanVertex next = iter.next();
if (previous != null)
assertTrue(previous.longId() < next.longId());
previous = next;
}
try {
iter.next();
fail();
} catch (NoSuchElementException ex) {
}
}
tx.commit();
g.close();
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanGraphTest method testTransactionIsolation.
/**
* Verifies transactional isolation and internal vertex existence checking
*/
@Test
public void testTransactionIsolation() {
// Create edge label before attempting to write it from concurrent transactions
makeLabel("knows");
finishSchema();
TitanTransaction tx1 = graph.newTransaction();
TitanTransaction tx2 = graph.newTransaction();
//Verify that using vertices across transactions is prohibited
TitanVertex v11 = tx1.addVertex();
TitanVertex v12 = tx1.addVertex();
v11.addEdge("knows", v12);
TitanVertex v21 = tx2.addVertex();
try {
v21.addEdge("knows", v11);
fail();
} catch (IllegalStateException e) {
}
TitanVertex v22 = tx2.addVertex();
v21.addEdge("knows", v22);
tx2.commit();
try {
v22.addEdge("knows", v21);
fail();
} catch (IllegalStateException e) {
}
tx1.rollback();
try {
v11.property(VertexProperty.Cardinality.single, "test", 5);
fail();
} catch (IllegalStateException e) {
}
//Test unidirected edge with and without internal existence check
newTx();
v21 = getV(tx, v21);
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());
newTx();
TitanTransaction tx3 = graph.buildTransaction().checkInternalVertexExistence(true).start();
v21 = getV(tx3, v21);
v3 = getOnlyElement(v21.query().direction(Direction.OUT).labels("link").vertices());
assertTrue(v3.isRemoved());
tx3.commit();
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanGraphTest method testHasNot.
//................................................
@Test
public void testHasNot() {
TitanVertex v1, v2;
v1 = graph.addVertex();
v2 = (TitanVertex) graph.query().hasNot("abcd").vertices().iterator().next();
assertEquals(v1, v2);
v2 = (TitanVertex) graph.query().hasNot("abcd", true).vertices().iterator().next();
assertEquals(v1, v2);
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanGraphTest method testEdgeTTLWithTransactions.
@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());
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanGraphTest method testImplicitKey.
/**
* Test the correct application of {@link com.thinkaurelius.titan.graphdb.types.system.ImplicitKey}
* to vertices, edges, and properties.
* <p/>
* Additionally tests RelationIdentifier since this is closely related to ADJACENT and TITANID implicit keys.
*/
@Test
public void testImplicitKey() {
TitanVertex v = graph.addVertex("name", "Dan"), u = graph.addVertex();
Edge e = v.addEdge("knows", u);
graph.tx().commit();
RelationIdentifier eid = (RelationIdentifier) e.id();
assertEquals(v.id(), v.value(ID_NAME));
assertEquals(eid, e.value(ID_NAME));
assertEquals("knows", e.value(LABEL_NAME));
assertEquals(BaseVertexLabel.DEFAULT_VERTEXLABEL.name(), v.value(LABEL_NAME));
assertCount(1, v.query().direction(Direction.BOTH).labels("knows").has(ID_NAME, eid).edges());
assertCount(0, v.query().direction(Direction.BOTH).labels("knows").has(ID_NAME, RelationIdentifier.get(new long[] { 4, 5, 6, 7 })).edges());
assertCount(1, v.query().direction(Direction.BOTH).labels("knows").has("~nid", eid.getRelationId()).edges());
assertCount(0, v.query().direction(Direction.BOTH).labels("knows").has("~nid", 110111).edges());
//Test edge retrieval
assertNotNull(getE(graph, eid));
assertEquals(eid, getE(graph, eid).id());
//Test adjacent constraint
assertEquals(1, v.query().direction(BOTH).has("~adjacent", u.id()).edgeCount());
assertCount(1, v.query().direction(BOTH).has("~adjacent", (int) getId(u)).edges());
try {
//Not a valid vertex
assertCount(0, v.query().direction(BOTH).has("~adjacent", 110111).edges());
fail();
} catch (IllegalArgumentException ex) {
}
}
Aggregations