Search in sources :

Example 11 with TitanVertex

use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.

the class TitanGraphTest method testConcurrentConsistencyEnforcement.

@Test
public void testConcurrentConsistencyEnforcement() throws Exception {
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
    TitanGraphIndex nameIndex = mgmt.buildIndex("name", Vertex.class).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();
    TitanVertex baseV = tx.addVertex("name", "base");
    newTx();
    final long baseVid = getId(baseV);
    final String nameA = "a", nameB = "b";
    final int parallelThreads = 4;
    final AtomicInteger totalExe = new AtomicInteger();
    int numSuccess = executeParallelTransactions(new TransactionJob() {

        @Override
        public void run(TitanTransaction tx) {
            TitanVertex a = tx.addVertex();
            TitanVertex base = getV(tx, baseVid);
            base.addEdge("married", a);
        }
    }, parallelThreads);
    assertTrue("At most 1 tx should succeed: " + numSuccess, numSuccess <= 1);
    numSuccess = executeParallelTransactions(new TransactionJob() {

        @Override
        public void run(TitanTransaction tx) {
            TitanVertex a = tx.addVertex("name", nameA);
            TitanVertex b = tx.addVertex("name", nameB);
            b.addEdge("friend", b);
        }
    }, parallelThreads);
    newTx();
    long numA = Iterables.size(tx.query().has("name", nameA).vertices());
    long numB = Iterables.size(tx.query().has("name", nameB).vertices());
    //        System.out.println(numA + " - " + numB);
    assertTrue("At most 1 tx should succeed: " + numSuccess, numSuccess <= 1);
    assertTrue(numA <= 1);
    assertTrue(numB <= 1);
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 12 with TitanVertex

use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.

the class TitanGraphTest method testDataTypes.

/**
     * Test the different data types that Titan supports natively and ensure that invalid data types aren't allowed
     */
@Test
public void testDataTypes() throws Exception {
    clopen(option(CUSTOM_ATTRIBUTE_CLASS, "attribute10"), SpecialInt.class.getCanonicalName(), option(CUSTOM_SERIALIZER_CLASS, "attribute10"), SpecialIntSerializer.class.getCanonicalName());
    PropertyKey num = makeKey("num", SpecialInt.class);
    PropertyKey barr = makeKey("barr", byte[].class);
    PropertyKey boolval = makeKey("boolval", Boolean.class);
    PropertyKey birthday = makeKey("birthday", Instant.class);
    PropertyKey geo = makeKey("geo", Geoshape.class);
    PropertyKey precise = makeKey("precise", Double.class);
    PropertyKey any = mgmt.makePropertyKey("any").cardinality(Cardinality.LIST).dataType(Object.class).make();
    try {
        //Not a valid data type - primitive
        makeKey("pint", int.class);
        fail();
    } catch (IllegalArgumentException e) {
    }
    try {
        //Not a valid data type - interface
        makeKey("number", Number.class);
        fail();
    } catch (IllegalArgumentException e) {
    }
    finishSchema();
    clopen();
    boolval = tx.getPropertyKey("boolval");
    num = tx.getPropertyKey("num");
    barr = tx.getPropertyKey("barr");
    birthday = tx.getPropertyKey("birthday");
    geo = tx.getPropertyKey("geo");
    precise = tx.getPropertyKey("precise");
    any = tx.getPropertyKey("any");
    assertEquals(Boolean.class, boolval.dataType());
    assertEquals(byte[].class, barr.dataType());
    assertEquals(Object.class, any.dataType());
    final Instant c = Instant.ofEpochSecond(1429225756);
    final Geoshape shape = Geoshape.box(10.0, 10.0, 20.0, 20.0);
    TitanVertex v = tx.addVertex();
    v.property(n(boolval), true);
    v.property(VertexProperty.Cardinality.single, n(birthday), c);
    v.property(VertexProperty.Cardinality.single, n(num), new SpecialInt(10));
    v.property(VertexProperty.Cardinality.single, n(barr), new byte[] { 1, 2, 3, 4 });
    v.property(VertexProperty.Cardinality.single, n(geo), shape);
    v.property(VertexProperty.Cardinality.single, n(precise), 10.12345);
    v.property(n(any), "Hello");
    v.property(n(any), 10l);
    int[] testarr = { 5, 6, 7 };
    v.property(n(any), testarr);
    // ######## VERIFICATION ##########
    assertTrue(v.<Boolean>value("boolval"));
    assertEquals(10, v.<SpecialInt>value("num").getValue());
    assertEquals(c, v.value("birthday"));
    assertEquals(4, v.<byte[]>value("barr").length);
    assertEquals(shape, v.<Geoshape>value("geo"));
    assertEquals(10.12345, v.<Double>value("precise").doubleValue(), 0.000001);
    assertCount(3, v.properties("any"));
    for (TitanVertexProperty prop : v.query().labels("any").properties()) {
        Object value = prop.value();
        if (value instanceof String)
            assertEquals("Hello", value);
        else if (value instanceof Long)
            assertEquals(10l, value);
        else if (value.getClass().isArray()) {
            assertTrue(Arrays.equals(testarr, (int[]) value));
        } else
            fail();
    }
    clopen();
    v = getV(tx, v);
    // ######## VERIFICATION (copied from above) ##########
    assertTrue(v.<Boolean>value("boolval"));
    assertEquals(10, v.<SpecialInt>value("num").getValue());
    assertEquals(c, v.value("birthday"));
    assertEquals(4, v.<byte[]>value("barr").length);
    assertEquals(shape, v.<Geoshape>value("geo"));
    assertEquals(10.12345, v.<Double>value("precise").doubleValue(), 0.000001);
    assertCount(3, v.properties("any"));
    for (TitanVertexProperty prop : v.query().labels("any").properties()) {
        Object value = prop.value();
        if (value instanceof String)
            assertEquals("Hello", value);
        else if (value instanceof Long)
            assertEquals(10l, value);
        else if (value.getClass().isArray()) {
            assertTrue(Arrays.equals(testarr, (int[]) value));
        } else
            fail();
    }
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) SpecialIntSerializer(com.thinkaurelius.titan.graphdb.serializer.SpecialIntSerializer) SpecialInt(com.thinkaurelius.titan.graphdb.serializer.SpecialInt) Instant(java.time.Instant) Geoshape(com.thinkaurelius.titan.core.attribute.Geoshape) TitanVertexProperty(com.thinkaurelius.titan.core.TitanVertexProperty) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 13 with TitanVertex

use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.

the class TitanGraphTest method testPropertyCardinality.

/* ==================================================================================
                            ADVANCED
     ==================================================================================*/
/**
     * This test exercises different types of updates against cardinality restricted properties
     * to ensure that the resulting behavior is fully consistent.
     */
@Test
public void testPropertyCardinality() {
    PropertyKey uid = mgmt.makePropertyKey("uid").dataType(Long.class).cardinality(Cardinality.SINGLE).make();
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
    mgmt.buildIndex("byUid", Vertex.class).addKey(uid).unique().buildCompositeIndex();
    mgmt.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex();
    finishSchema();
    TitanVertex v1 = tx.addVertex();
    v1.property("name", "name1");
    TitanVertex v2 = tx.addVertex();
    v2.property("uid", 512);
    newTx();
    v1 = tx.getVertex(v1.longId());
    //Ensure that the old index record gets removed
    v1.property("name", "name2");
    v2 = tx.getVertex(v2.longId());
    //Ensure that replacement is allowed
    v2.property("uid", 512);
    newTx();
    assertCount(0, tx.query().has("name", "name1").vertices());
    assertCount(1, tx.query().has("name", "name2").vertices());
    assertCount(1, tx.query().has("uid", 512).vertices());
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 14 with TitanVertex

use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.

the class TitanGraphTest method testRelationTypeIndexes.

@Test
public void testRelationTypeIndexes() {
    PropertyKey weight = makeKey("weight", Float.class);
    PropertyKey time = makeKey("time", Long.class);
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.LIST).make();
    EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(time).make();
    EdgeLabel child = mgmt.makeEdgeLabel("child").multiplicity(Multiplicity.ONE2MANY).make();
    EdgeLabel link = mgmt.makeEdgeLabel("link").unidirected().make();
    RelationTypeIndex name1 = mgmt.buildPropertyIndex(name, "weightDesc", weight);
    RelationTypeIndex connect1 = mgmt.buildEdgeIndex(connect, "weightAsc", Direction.BOTH, incr, weight);
    RelationTypeIndex connect2 = mgmt.buildEdgeIndex(connect, "weightDesc", Direction.OUT, decr, weight);
    RelationTypeIndex connect3 = mgmt.buildEdgeIndex(connect, "time+weight", Direction.OUT, decr, time, weight);
    RelationTypeIndex child1 = mgmt.buildEdgeIndex(child, "time", Direction.OUT, time);
    RelationTypeIndex link1 = mgmt.buildEdgeIndex(link, "time", Direction.OUT, time);
    final String name1n = name1.name(), connect1n = connect1.name(), connect2n = connect2.name(), connect3n = connect3.name(), child1n = child1.name(), link1n = link1.name();
    // ########### INSPECTION & FAILURE ##############
    assertTrue(mgmt.containsRelationIndex(name, "weightDesc"));
    assertTrue(mgmt.containsRelationIndex(connect, "weightDesc"));
    assertFalse(mgmt.containsRelationIndex(child, "weightDesc"));
    assertEquals("time+weight", mgmt.getRelationIndex(connect, "time+weight").name());
    assertNotNull(mgmt.getRelationIndex(link, "time"));
    assertNull(mgmt.getRelationIndex(name, "time"));
    assertEquals(1, size(mgmt.getRelationIndexes(child)));
    assertEquals(3, size(mgmt.getRelationIndexes(connect)));
    assertEquals(0, size(mgmt.getRelationIndexes(weight)));
    try {
        //Name already exists
        mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time);
        fail();
    } catch (SchemaViolationException e) {
    }
    //        } catch (IllegalArgumentException e) {}
    try {
        //Not valid in this direction due to multiplicity constraint
        mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time);
        fail();
    } catch (IllegalArgumentException e) {
    }
    try {
        //Not valid in this direction due to unidirectionality
        mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time);
        fail();
    } catch (IllegalArgumentException e) {
    }
    // ########## END INSPECTION ###########
    finishSchema();
    weight = mgmt.getPropertyKey("weight");
    time = mgmt.getPropertyKey("time");
    name = mgmt.getPropertyKey("name");
    connect = mgmt.getEdgeLabel("connect");
    child = mgmt.getEdgeLabel("child");
    link = mgmt.getEdgeLabel("link");
    // ########### INSPECTION & FAILURE (copied from above) ##############
    assertTrue(mgmt.containsRelationIndex(name, "weightDesc"));
    assertTrue(mgmt.containsRelationIndex(connect, "weightDesc"));
    assertFalse(mgmt.containsRelationIndex(child, "weightDesc"));
    assertEquals("time+weight", mgmt.getRelationIndex(connect, "time+weight").name());
    assertNotNull(mgmt.getRelationIndex(link, "time"));
    assertNull(mgmt.getRelationIndex(name, "time"));
    assertEquals(1, Iterables.size(mgmt.getRelationIndexes(child)));
    assertEquals(3, Iterables.size(mgmt.getRelationIndexes(connect)));
    assertEquals(0, Iterables.size(mgmt.getRelationIndexes(weight)));
    try {
        //Name already exists
        mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time);
        fail();
    } catch (SchemaViolationException e) {
    }
    //        } catch (IllegalArgumentException e) {}
    try {
        //Not valid in this direction due to multiplicity constraint
        mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time);
        fail();
    } catch (IllegalArgumentException e) {
    }
    try {
        //Not valid in this direction due to unidirectionality
        mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time);
        fail();
    } catch (IllegalArgumentException e) {
    }
    // ########## END INSPECTION ###########
    mgmt.rollback();
    /*
        ########## TEST WITHIN TRANSACTION ##################
        */
    weight = tx.getPropertyKey("weight");
    time = tx.getPropertyKey("time");
    final int numV = 100;
    TitanVertex v = tx.addVertex();
    TitanVertex[] ns = new TitanVertex[numV];
    for (int i = 0; i < numV; i++) {
        double w = (i * 0.5) % 5;
        long t = (i + 77) % numV;
        VertexProperty p = v.property("name", "v" + i, "weight", w, "time", t);
        ns[i] = tx.addVertex();
        for (String label : new String[] { "connect", "child", "link" }) {
            Edge e = v.addEdge(label, ns[i], "weight", w, "time", t);
        }
    }
    TitanVertex u = ns[0];
    VertexList vl;
    //######### QUERIES ##########
    v = getV(tx, v);
    u = getV(tx, u);
    evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").has("weight", Cmp.LESS_THAN, 0.9).orderBy("weight", incr), PROPERTY, 2 * numV / 10, 1, new boolean[] { true, true }, weight, Order.ASC);
    evaluateQuery(v.query().keys("name").interval("weight", 1.1, 2.2).orderBy("weight", decr).limit(numV / 10), PROPERTY, numV / 10, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name").has("time", Cmp.EQUAL, 5).orderBy("weight", decr), PROPERTY, 1, 1, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name"), PROPERTY, numV, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(BOTH).has("time", Cmp.EQUAL, 5), EDGE, 1, 2, new boolean[0]);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(BOTH).interval("weight", 0.0, 1.0).orderBy("weight", decr), EDGE, 2 * numV / 10, 2, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("weight", 0.0, 1.0), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("child").direction(BOTH), EDGE, numV, 1, new boolean[] { true, true });
    vl = v.query().labels("child").direction(BOTH).vertexIds();
    assertEquals(numV, vl.size());
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
    vl = v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT).vertexIds();
    assertEquals(2 * numV / 10, vl.size());
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr), EDGE, 10, 1, new boolean[] { true, true }, time, Order.ASC);
    vl = v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr).vertexIds();
    assertEquals(10, vl.size());
    assertFalse(vl.isSorted());
    assertFalse(isSortedByID(vl));
    vl.sort();
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(BOTH), EDGE, 1, 2, new boolean[0]);
    evaluateQuery(v.query().labels("connect").interval("time", 10, 20).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", incr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.ASC);
    evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", decr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 1.4, 2.75).orderBy("weight", decr), EDGE, 3 * numV / 10, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", decr), EDGE, 1, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", incr), EDGE, 1, 1, new boolean[] { true, false }, weight, Order.ASC);
    evaluateQuery(v.query().labels("connect").direction(OUT).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).has("weight", Cmp.EQUAL, 0.0).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 0.0, 1.0).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("time", 50, 100).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
    evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
    evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
    //--------------
    clopen();
    weight = tx.getPropertyKey("weight");
    time = tx.getPropertyKey("time");
    //######### QUERIES (copied from above) ##########
    v = getV(tx, v);
    u = getV(tx, u);
    evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").has("weight", Cmp.LESS_THAN, 0.9).orderBy("weight", incr), PROPERTY, 2 * numV / 10, 1, new boolean[] { true, true }, weight, Order.ASC);
    evaluateQuery(v.query().keys("name").interval("weight", 1.1, 2.2).orderBy("weight", decr).limit(numV / 10), PROPERTY, numV / 10, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name").has("time", Cmp.EQUAL, 5).orderBy("weight", decr), PROPERTY, 1, 1, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name"), PROPERTY, numV, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(BOTH).has("time", Cmp.EQUAL, 5), EDGE, 1, 2, new boolean[0]);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(BOTH).interval("weight", 0.0, 1.0).orderBy("weight", decr), EDGE, 2 * numV / 10, 2, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("weight", 0.0, 1.0), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("child").direction(BOTH), EDGE, numV, 1, new boolean[] { true, true });
    vl = v.query().labels("child").direction(BOTH).vertexIds();
    assertEquals(numV, vl.size());
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
    vl = v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT).vertexIds();
    assertEquals(2 * numV / 10, vl.size());
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr), EDGE, 10, 1, new boolean[] { true, true }, time, Order.ASC);
    vl = v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr).vertexIds();
    assertEquals(10, vl.size());
    assertFalse(vl.isSorted());
    assertFalse(isSortedByID(vl));
    vl.sort();
    assertTrue(vl.isSorted());
    assertTrue(isSortedByID(vl));
    evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(BOTH), EDGE, 1, 2, new boolean[0]);
    evaluateQuery(v.query().labels("connect").interval("time", 10, 20).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", incr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.ASC);
    evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", decr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 1.4, 2.75).orderBy("weight", decr), EDGE, 3 * numV / 10, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", decr), EDGE, 1, 1, new boolean[] { true, true }, weight, Order.DESC);
    evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", incr), EDGE, 1, 1, new boolean[] { true, false }, weight, Order.ASC);
    evaluateQuery(v.query().labels("connect").direction(OUT).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).has("weight", Cmp.EQUAL, 0.0).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 0.0, 1.0).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("connect").direction(OUT).interval("time", 50, 100).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
    evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
    evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
    //Update in transaction
    for (TitanVertexProperty<String> p : v.query().labels("name").properties()) {
        if (p.<Long>value("time") < (numV / 2))
            p.remove();
    }
    for (TitanEdge e : v.query().direction(BOTH).edges()) {
        if (e.<Long>value("time") < (numV / 2))
            e.remove();
    }
    ns = new TitanVertex[numV * 3 / 2];
    for (int i = numV; i < numV * 3 / 2; i++) {
        double w = (i * 0.5) % 5;
        long t = i;
        v.property("name", "v" + i, "weight", w, "time", t);
        ns[i] = tx.addVertex();
        for (String label : new String[] { "connect", "child", "link" }) {
            TitanEdge e = v.addEdge(label, ns[i], "weight", w, "time", t);
        }
    }
    //######### UPDATED QUERIES ##########
    evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10), PROPERTY, 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10).orderBy("weight", decr), PROPERTY, 10, 1, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name").interval("time", numV, numV + 10).limit(5), PROPERTY, 5, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 0, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, numV + 5), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 0, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", numV + 10, numV + 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
    evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
    //######### END UPDATED QUERIES ##########
    newTx();
    weight = tx.getPropertyKey("weight");
    time = tx.getPropertyKey("time");
    v = getV(tx, v);
    u = getV(tx, u);
    //######### UPDATED QUERIES (copied from above) ##########
    evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10), PROPERTY, 10, 1, new boolean[] { false, true });
    evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10).orderBy("weight", decr), PROPERTY, 10, 1, new boolean[] { false, false }, weight, Order.DESC);
    evaluateQuery(v.query().keys("name").interval("time", numV, numV + 10).limit(5), PROPERTY, 5, 1, new boolean[] { false, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 0, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, numV + 5), EDGE, 1, 1, new boolean[] { true, true });
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 0, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query().labels("child").direction(OUT).interval("time", numV + 10, numV + 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
    evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
    evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
//######### END UPDATED QUERIES ##########
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) SchemaViolationException(com.thinkaurelius.titan.core.SchemaViolationException) TitanVertexProperty(com.thinkaurelius.titan.core.TitanVertexProperty) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) TitanEdge(com.thinkaurelius.titan.core.TitanEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) TitanEdge(com.thinkaurelius.titan.core.TitanEdge) VertexList(com.thinkaurelius.titan.core.VertexList) Test(org.junit.Test)

Example 15 with TitanVertex

use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.

the class TitanGraphTest method testEdgeTTLWithIndex.

@Category({ BrittleTests.class })
@Test
public void testEdgeTTLWithIndex() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }
    // artificially low TTL for test
    int ttl = 1;
    final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
    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();
    mgmt.setTTL(wavedAt, Duration.ofSeconds(ttl));
    assertEquals(Duration.ZERO, mgmt.getTTL(time));
    assertEquals(Duration.ofSeconds(ttl), mgmt.getTTL(wavedAt));
    mgmt.commit();
    TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    v1.addEdge("wavedAt", v2, "time", 42);
    assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
    assertNotEmpty(v1.query().direction(Direction.OUT).edges());
    assertNotEmpty(graph.query().has("time", 42).edges());
    graph.tx().commit();
    long commitTime = System.currentTimeMillis();
    assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
    assertNotEmpty(v1.query().direction(Direction.OUT).edges());
    assertNotEmpty(graph.query().has("time", 42).edges());
    Thread.sleep(commitTime + (ttl * 1000L + 100) - System.currentTimeMillis());
    graph.tx().rollback();
    assertFalse(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
    assertEmpty(v1.query().direction(Direction.OUT).edges());
    assertEmpty(graph.query().has("time", 42).edges());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Category(org.junit.experimental.categories.Category) RelationCategory(com.thinkaurelius.titan.graphdb.internal.RelationCategory) ElementCategory(com.thinkaurelius.titan.graphdb.internal.ElementCategory) 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