Search in sources :

Example 66 with TitanVertex

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();
}
Also used : TitanGraph(com.thinkaurelius.titan.core.TitanGraph) VertexLongList(com.thinkaurelius.titan.graphdb.query.vertex.VertexLongList) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) VertexArrayList(com.thinkaurelius.titan.graphdb.query.vertex.VertexArrayList) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 67 with TitanVertex

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();
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) Test(org.junit.Test)

Example 68 with TitanVertex

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);
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Test(org.junit.Test)

Example 69 with TitanVertex

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());
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) Test(org.junit.Test)

Example 70 with TitanVertex

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) {
    }
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) RelationIdentifier(com.thinkaurelius.titan.graphdb.relations.RelationIdentifier) TitanEdge(com.thinkaurelius.titan.core.TitanEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Aggregations

TitanVertex (com.thinkaurelius.titan.core.TitanVertex)77 Test (org.junit.Test)63 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)46 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)21 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)17 Edge (org.apache.tinkerpop.gremlin.structure.Edge)17 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)14 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)12 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)12 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)10 BaseVertexLabel (com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)8 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)7 ElementCategory (com.thinkaurelius.titan.graphdb.internal.ElementCategory)4 Category (org.junit.experimental.categories.Category)4 SchemaViolationException (com.thinkaurelius.titan.core.SchemaViolationException)3 VertexList (com.thinkaurelius.titan.core.VertexList)3 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)3 TitanGraphBaseTest (com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)3