Search in sources :

Example 11 with JanusGraphVertex

use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method testConditionalIndexing.

/**
 * Tests conditional indexing and the different management features
 */
@Test
public void testConditionalIndexing() {
    PropertyKey name = makeKey("name", String.class);
    PropertyKey weight = makeKey("weight", Double.class);
    PropertyKey text = makeKey("text", String.class);
    VertexLabel person = mgmt.makeVertexLabel("person").make();
    VertexLabel org = mgmt.makeVertexLabel("org").make();
    JanusGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name, getStringMapping()).buildMixedIndex(INDEX);
    JanusGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).indexOnly(person).addKey(text, getTextMapping()).addKey(weight).buildMixedIndex(INDEX);
    JanusGraphIndex index3 = mgmt.buildIndex("index3", Vertex.class).indexOnly(org).addKey(text, getTextMapping()).addKey(weight).buildMixedIndex(INDEX);
    // ########### INSPECTION & FAILURE ##############
    assertTrue(mgmt.containsGraphIndex("index1"));
    assertFalse(mgmt.containsGraphIndex("index"));
    assertCount(3, mgmt.getGraphIndexes(Vertex.class));
    assertNull(mgmt.getGraphIndex("indexx"));
    name = mgmt.getPropertyKey("name");
    weight = mgmt.getPropertyKey("weight");
    text = mgmt.getPropertyKey("text");
    person = mgmt.getVertexLabel("person");
    org = mgmt.getVertexLabel("org");
    index1 = mgmt.getGraphIndex("index1");
    index2 = mgmt.getGraphIndex("index2");
    index3 = mgmt.getGraphIndex("index3");
    assertTrue(Vertex.class.isAssignableFrom(index1.getIndexedElement()));
    assertEquals("index2", index2.name());
    assertEquals(INDEX, index3.getBackingIndex());
    assertFalse(index2.isUnique());
    assertEquals(2, index3.getFieldKeys().length);
    assertEquals(1, index1.getFieldKeys().length);
    assertEquals(3, index3.getParametersFor(text).length);
    assertEquals(2, index3.getParametersFor(weight).length);
    try {
        // Already exists
        mgmt.buildIndex("index2", Vertex.class).addKey(weight).buildMixedIndex(INDEX);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Already exists
        mgmt.buildIndex("index2", Vertex.class).addKey(weight).buildCompositeIndex();
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Key is already added
        mgmt.addIndexKey(index2, weight);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    finishSchema();
    clopen();
    // ########### INSPECTION & FAILURE (copied from above) ##############
    assertTrue(mgmt.containsGraphIndex("index1"));
    assertFalse(mgmt.containsGraphIndex("index"));
    assertCount(3, mgmt.getGraphIndexes(Vertex.class));
    assertNull(mgmt.getGraphIndex("indexx"));
    name = mgmt.getPropertyKey("name");
    weight = mgmt.getPropertyKey("weight");
    text = mgmt.getPropertyKey("text");
    person = mgmt.getVertexLabel("person");
    org = mgmt.getVertexLabel("org");
    index1 = mgmt.getGraphIndex("index1");
    index2 = mgmt.getGraphIndex("index2");
    index3 = mgmt.getGraphIndex("index3");
    assertTrue(Vertex.class.isAssignableFrom(index1.getIndexedElement()));
    assertEquals("index2", index2.name());
    assertEquals(INDEX, index3.getBackingIndex());
    assertFalse(index2.isUnique());
    assertEquals(2, index3.getFieldKeys().length);
    assertEquals(1, index1.getFieldKeys().length);
    assertEquals(3, index3.getParametersFor(text).length);
    assertEquals(2, index3.getParametersFor(weight).length);
    try {
        // Already exists
        mgmt.buildIndex("index2", Vertex.class).addKey(weight).buildMixedIndex(INDEX);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Already exists
        mgmt.buildIndex("index2", Vertex.class).addKey(weight).buildCompositeIndex();
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Key is already added
        mgmt.addIndexKey(index2, weight);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // ########### TRANSACTIONAL ##############
    weight = tx.getPropertyKey("weight");
    final int numV = 200;
    String[] strings = { "houseboat", "humanoid", "differential", "extraordinary" };
    String[] stringsTwo = new String[strings.length];
    for (int i = 0; i < strings.length; i++) stringsTwo[i] = strings[i] + " " + strings[i];
    final int modulo = 5;
    assert numV % (modulo * strings.length * 2) == 0;
    for (int i = 0; i < numV; i++) {
        JanusGraphVertex v = tx.addVertex(i % 2 == 0 ? "person" : "org");
        v.property("name", strings[i % strings.length]);
        v.property("text", strings[i % strings.length]);
        v.property("weight", (i % modulo) + 0.5);
    }
    // ########## QUERIES ################
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, index2.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has(LABEL_NAME, Cmp.EQUAL, "person").orderBy("weight", decr), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, weight, Order.DESC, index2.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has(LABEL_NAME, Cmp.EQUAL, "org"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, index3.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[1]).has(LABEL_NAME, Cmp.EQUAL, "org").orderBy("weight", decr), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, weight, Order.DESC, index3.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has("weight", Cmp.EQUAL, 2.5).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / (modulo * strings.length), new boolean[] { true, true }, index2.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[2]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true }, index1.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[3]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, 0, new boolean[] { false, true }, index1.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, index1.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[2]).has("text", Text.CONTAINS, strings[2]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, index1.name(), index2.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("text", Text.CONTAINS, strings[0]).has(LABEL_NAME, Cmp.EQUAL, "person").orderBy("weight", incr), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, weight, Order.ASC, index1.name(), index2.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true });
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).orderBy("weight", incr), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, false }, weight, Order.ASC);
    clopen();
    weight = tx.getPropertyKey("weight");
    // ########## QUERIES (copied from above) ################
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, index2.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has(LABEL_NAME, Cmp.EQUAL, "person").orderBy("weight", decr), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, weight, Order.DESC, index2.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has(LABEL_NAME, Cmp.EQUAL, "org"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, index3.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[1]).has(LABEL_NAME, Cmp.EQUAL, "org").orderBy("weight", decr), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, weight, Order.DESC, index3.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has("weight", Cmp.EQUAL, 2.5).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / (modulo * strings.length), new boolean[] { true, true }, index2.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[2]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true }, index1.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[3]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, 0, new boolean[] { false, true }, index1.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, index1.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[2]).has("text", Text.CONTAINS, strings[2]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, index1.name(), index2.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("text", Text.CONTAINS, strings[0]).has(LABEL_NAME, Cmp.EQUAL, "person").orderBy("weight", incr), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, weight, Order.ASC, index1.name(), index2.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true });
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).orderBy("weight", incr), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, false }, weight, Order.ASC);
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexLabel(org.janusgraph.core.VertexLabel) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 12 with JanusGraphVertex

use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.

the class JanusGraphTest method testConsistencyEnforcement.

/* ==================================================================================
                            CONSISTENCY
     ==================================================================================*/
/**
 * Tests the correct application of ConsistencyModifiers across transactional boundaries
 */
@Test
public void testConsistencyEnforcement() {
    PropertyKey uid = makeVertexIndexedUniqueKey("uid", Integer.class);
    PropertyKey name = makeKey("name", String.class);
    mgmt.setConsistency(uid, ConsistencyModifier.LOCK);
    mgmt.setConsistency(name, ConsistencyModifier.LOCK);
    mgmt.setConsistency(mgmt.getGraphIndex("uid"), ConsistencyModifier.LOCK);
    EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.SIMPLE).make();
    EdgeLabel spouse = mgmt.makeEdgeLabel("spouse").multiplicity(Multiplicity.ONE2ONE).make();
    EdgeLabel connect = mgmt.makeEdgeLabel("connect").multiplicity(Multiplicity.MULTI).make();
    EdgeLabel related = mgmt.makeEdgeLabel("related").multiplicity(Multiplicity.MULTI).make();
    mgmt.setConsistency(knows, ConsistencyModifier.LOCK);
    mgmt.setConsistency(spouse, ConsistencyModifier.LOCK);
    mgmt.setConsistency(related, ConsistencyModifier.FORK);
    finishSchema();
    name = tx.getPropertyKey("name");
    connect = tx.getEdgeLabel("connect");
    related = tx.getEdgeLabel("related");
    JanusGraphVertex v1 = tx.addVertex("uid", 1);
    JanusGraphVertex v2 = tx.addVertex("uid", 2);
    JanusGraphVertex v3 = tx.addVertex("uid", 3);
    Edge e1 = v1.addEdge(connect.name(), v2, name.name(), "e1");
    Edge e2 = v1.addEdge(related.name(), v2, name.name(), "e2");
    newTx();
    v1 = getV(tx, v1);
    /*
         ==== check fork, no fork behavior
         */
    long e1id = getId(e1);
    long e2id = getId(e2);
    e1 = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("connect").edges());
    assertEquals("e1", e1.value("name"));
    assertEquals(e1id, getId(e1));
    e2 = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("related").edges());
    assertEquals("e2", e2.value("name"));
    assertEquals(e2id, getId(e2));
    // Update edges - one should simply update, the other fork
    e1.property("name", "e1.2");
    e2.property("name", "e2.2");
    newTx();
    v1 = getV(tx, v1);
    e1 = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("connect").edges());
    assertEquals("e1.2", e1.value("name"));
    // should have same id
    assertEquals(e1id, getId(e1));
    e2 = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("related").edges());
    assertEquals("e2.2", e2.value("name"));
    // should have different id since forked
    assertNotEquals(e2id, getId(e2));
    clopen();
    /*
         === check cross transaction
         */
    final Random random = new Random();
    final long[] vertexIds = { getId(v1), getId(v2), getId(v3) };
    // 1) Index uniqueness
    executeLockConflictingTransactionJobs(graph, new TransactionJob() {

        private int pos = 0;

        @Override
        public void run(JanusGraphTransaction tx) {
            JanusGraphVertex u = getV(tx, vertexIds[pos++]);
            u.property(VertexProperty.Cardinality.single, "uid", 5);
        }
    });
    // 2) Property out-uniqueness
    executeLockConflictingTransactionJobs(graph, tx -> {
        final JanusGraphVertex u = getV(tx, vertexIds[0]);
        u.property(VertexProperty.Cardinality.single, "name", "v" + random.nextInt(10));
    });
    // 3) knows simpleness
    executeLockConflictingTransactionJobs(graph, tx -> {
        final JanusGraphVertex u1 = getV(tx, vertexIds[0]), u2 = getV(tx, vertexIds[1]);
        u1.addEdge("knows", u2);
    });
    // 4) knows one2one (in 2 separate configurations)
    executeLockConflictingTransactionJobs(graph, new TransactionJob() {

        private int pos = 1;

        @Override
        public void run(JanusGraphTransaction tx) {
            final JanusGraphVertex u1 = getV(tx, vertexIds[0]), u2 = getV(tx, vertexIds[pos++]);
            u1.addEdge("spouse", u2);
        }
    });
    executeLockConflictingTransactionJobs(graph, new TransactionJob() {

        private int pos = 1;

        @Override
        public void run(JanusGraphTransaction tx) {
            final JanusGraphVertex u1 = getV(tx, vertexIds[pos++]), u2 = getV(tx, vertexIds[0]);
            u1.addEdge("spouse", u2);
        }
    });
    // ######### TRY INVALID CONSISTENCY
    try {
        // Fork does not apply to constrained types
        mgmt.setConsistency(mgmt.getPropertyKey("name"), ConsistencyModifier.FORK);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
}
Also used : JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) Random(java.util.Random) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 13 with JanusGraphVertex

use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.

the class JanusGraphTest method testIndexUniqueness.

@Test
public void testIndexUniqueness() {
    PropertyKey time = makeKey("time", Long.class);
    PropertyKey text = makeKey("text", String.class);
    VertexLabel person = mgmt.makeVertexLabel("person").make();
    VertexLabel org = mgmt.makeVertexLabel("organization").make();
    final JanusGraphIndex vertexIndex1 = mgmt.buildIndex("vindex1", Vertex.class).addKey(time).indexOnly(person).unique().buildCompositeIndex();
    final JanusGraphIndex vertexIndex2 = mgmt.buildIndex("vindex2", Vertex.class).addKey(time).addKey(text).unique().buildCompositeIndex();
    finishSchema();
    // ================== VERTEX UNIQUENESS ====================
    // I) Label uniqueness
    // Ia) Uniqueness violation in same transaction
    failTransactionOnCommit(tx -> {
        final JanusGraphVertex v0 = tx.addVertex("person");
        v0.property(VertexProperty.Cardinality.single, "time", 1);
        final JanusGraphVertex v1 = tx.addVertex("person");
        v1.property(VertexProperty.Cardinality.single, "time", 1);
    });
    // Ib) Uniqueness violation across transactions
    JanusGraphVertex v0 = tx.addVertex("person");
    v0.property(VertexProperty.Cardinality.single, "time", 1);
    newTx();
    failTransactionOnCommit(tx -> {
        final JanusGraphVertex v1 = tx.addVertex("person");
        v1.property(VertexProperty.Cardinality.single, "time", 1);
    });
    // Ic) However, this should work since the label is different
    final JanusGraphVertex v1 = tx.addVertex("organization");
    v1.property(VertexProperty.Cardinality.single, "time", 1);
    newTx();
    // II) Composite uniqueness
    // IIa) Uniqueness violation in same transaction
    failTransactionOnCommit(tx -> {
        final JanusGraphVertex v01 = tx.addVertex("time", 2, "text", "hello");
        final JanusGraphVertex v11 = tx.addVertex("time", 2, "text", "hello");
    });
    // IIb) Uniqueness violation across transactions
    v0 = tx.addVertex("time", 2, "text", "hello");
    newTx();
    failTransactionOnCommit(tx -> {
        final JanusGraphVertex v112 = tx.addVertex("time", 2, "text", "hello");
    });
}
Also used : VertexLabel(org.janusgraph.core.VertexLabel) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 14 with JanusGraphVertex

use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.

the class JanusGraphTest method testConcurrentConsistencyEnforcement.

@Test
public void testConcurrentConsistencyEnforcement() throws Exception {
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make();
    JanusGraphIndex 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);
    mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make();
    finishSchema();
    JanusGraphVertex baseV = tx.addVertex("name", "base");
    newTx();
    final long baseVid = getId(baseV);
    final String nameA = "a", nameB = "b";
    final int parallelThreads = 4;
    int numSuccess = executeParallelTransactions(tx -> {
        final JanusGraphVertex a = tx.addVertex();
        final JanusGraphVertex base = getV(tx, baseVid);
        base.addEdge("married", a);
    }, parallelThreads);
    assertTrue("At most 1 tx should succeed: " + numSuccess, numSuccess <= 1);
    numSuccess = executeParallelTransactions(tx -> {
        tx.addVertex("name", nameA);
        final JanusGraphVertex b = tx.addVertex("name", nameB);
        b.addEdge("friend", b);
    }, parallelThreads);
    newTx();
    final long numA = Iterables.size(tx.query().has("name", nameA).vertices());
    final 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 : ManagementUtil(org.janusgraph.core.util.ManagementUtil) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) BasicVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder) Arrays(java.util.Arrays) MessageReader(org.janusgraph.diskstorage.log.MessageReader) Geoshape(org.janusgraph.core.attribute.Geoshape) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) Cardinality(org.janusgraph.core.Cardinality) Serializer(org.janusgraph.graphdb.database.serialize.Serializer) Cardinality.single(org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality.single) Duration(java.time.Duration) Map(java.util.Map) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) LogTxStatus(org.janusgraph.graphdb.database.log.LogTxStatus) Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) EnumSet(java.util.EnumSet) JanusGraphSchemaType(org.janusgraph.core.schema.JanusGraphSchemaType) IndexRepairJob(org.janusgraph.graphdb.olap.job.IndexRepairJob) PropertyKey(org.janusgraph.core.PropertyKey) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) EnumMap(java.util.EnumMap) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Order.decr(org.apache.tinkerpop.gremlin.process.traversal.Order.decr) Set(java.util.Set) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) Category(org.junit.experimental.categories.Category) CountDownLatch(java.util.concurrent.CountDownLatch) LogProcessorFramework(org.janusgraph.core.log.LogProcessorFramework) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.JanusGraphVertexStep) Iterables(com.google.common.collect.Iterables) StartStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.StartStep) TestGraphConfigs(org.janusgraph.testutil.TestGraphConfigs) GraphStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep) SimpleQueryProfiler(org.janusgraph.graphdb.query.profile.SimpleQueryProfiler) ArrayList(java.util.ArrayList) StandardTransactionLogProcessor(org.janusgraph.graphdb.log.StandardTransactionLogProcessor) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) Lists(com.google.common.collect.Lists) Change(org.janusgraph.core.log.Change) Cmp(org.janusgraph.core.attribute.Cmp) ConsistencyModifier(org.janusgraph.core.schema.ConsistencyModifier) JanusGraphException(org.janusgraph.core.JanusGraphException) StreamSupport(java.util.stream.StreamSupport) StandardEdgeLabelMaker(org.janusgraph.graphdb.types.StandardEdgeLabelMaker) JanusGraphElement(org.janusgraph.core.JanusGraphElement) TransactionLogHeader(org.janusgraph.graphdb.database.log.TransactionLogHeader) Test(org.junit.Test) T(org.apache.tinkerpop.gremlin.structure.T) ExecutionException(java.util.concurrent.ExecutionException) Direction(org.apache.tinkerpop.gremlin.structure.Direction) ChronoUnit(java.time.temporal.ChronoUnit) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) JanusGraphVertexQuery(org.janusgraph.core.JanusGraphVertexQuery) Preconditions(com.google.common.base.Preconditions) VertexLabel(org.janusgraph.core.VertexLabel) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) JanusGraphAssert(org.janusgraph.testutil.JanusGraphAssert) Assert(org.junit.Assert) SpecialIntSerializer(org.janusgraph.graphdb.serializer.SpecialIntSerializer) JanusGraphConfigurationException(org.janusgraph.core.JanusGraphConfigurationException) Log(org.janusgraph.diskstorage.log.Log) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) PropertyKeyDefinition(org.janusgraph.graphdb.schema.PropertyKeyDefinition) LoggerFactory(org.slf4j.LoggerFactory) ConfigOption(org.janusgraph.diskstorage.configuration.ConfigOption) Random(java.util.Random) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) SchemaAction(org.janusgraph.core.schema.SchemaAction) Order.incr(org.apache.tinkerpop.gremlin.process.traversal.Order.incr) OrderList(org.janusgraph.graphdb.internal.OrderList) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SchemaStatus(org.janusgraph.core.schema.SchemaStatus) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) JanusGraphPropertiesStep(org.janusgraph.graphdb.tinkerpop.optimize.JanusGraphPropertiesStep) P(org.apache.tinkerpop.gremlin.process.traversal.P) TransactionRecovery(org.janusgraph.core.log.TransactionRecovery) Multiplicity(org.janusgraph.core.Multiplicity) RelationType(org.janusgraph.core.RelationType) EdgeLabelDefinition(org.janusgraph.graphdb.schema.EdgeLabelDefinition) Property(org.apache.tinkerpop.gremlin.structure.Property) SchemaViolationException(org.janusgraph.core.SchemaViolationException) Mapping(org.janusgraph.core.schema.Mapping) ImmutableMap(com.google.common.collect.ImmutableMap) IndexRemoveJob(org.janusgraph.graphdb.olap.job.IndexRemoveJob) BrittleTests(org.janusgraph.testcategory.BrittleTests) LogTxMeta(org.janusgraph.graphdb.database.log.LogTxMeta) StandardPropertyKeyMaker(org.janusgraph.graphdb.types.StandardPropertyKeyMaker) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) ImplicitKey(org.janusgraph.graphdb.types.system.ImplicitKey) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) GraphCentricQueryBuilder(org.janusgraph.graphdb.query.graph.GraphCentricQueryBuilder) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) JanusGraphStep(org.janusgraph.graphdb.tinkerpop.optimize.JanusGraphStep) SchemaContainer(org.janusgraph.graphdb.schema.SchemaContainer) Backend(org.janusgraph.diskstorage.Backend) Iterators(com.google.common.collect.Iterators) SpecialInt(org.janusgraph.graphdb.serializer.SpecialInt) JanusGraphQuery(org.janusgraph.core.JanusGraphQuery) OrderGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep) HashSet(java.util.HashSet) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) ImmutableList(com.google.common.collect.ImmutableList) ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) Message(org.janusgraph.diskstorage.log.Message) RelationCategory(org.janusgraph.graphdb.internal.RelationCategory) GraphOfTheGodsFactory(org.janusgraph.example.GraphOfTheGodsFactory) Edge(org.apache.tinkerpop.gremlin.structure.Edge) BackendException(org.janusgraph.diskstorage.BackendException) QueryProfiler(org.janusgraph.graphdb.query.profile.QueryProfiler) Logger(org.slf4j.Logger) KCVSLog(org.janusgraph.diskstorage.log.kcvs.KCVSLog) Iterator(java.util.Iterator) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) VertexList(org.janusgraph.core.VertexList) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) JanusGraph(org.janusgraph.core.JanusGraph) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) Order(org.janusgraph.graphdb.internal.Order) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) TimeUnit(java.util.concurrent.TimeUnit) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) TraversalFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep) ReadMarker(org.janusgraph.diskstorage.log.ReadMarker) VertexLabelDefinition(org.janusgraph.graphdb.schema.VertexLabelDefinition) Contain(org.janusgraph.core.attribute.Contain) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 15 with JanusGraphVertex

use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.

the class JanusGraphTest method testLimitWithMixedIndexCoverage.

@Test
public void testLimitWithMixedIndexCoverage() {
    final String vt = "vt";
    final String fn = "firstname";
    final String user = "user";
    final String alice = "alice";
    final String bob = "bob";
    PropertyKey vtk = makeVertexIndexedKey(vt, String.class);
    PropertyKey fnk = makeKey(fn, String.class);
    finishSchema();
    JanusGraphVertex a = tx.addVertex(vt, user, fn, "alice");
    JanusGraphVertex b = tx.addVertex(vt, user, fn, "bob");
    JanusGraphVertex v;
    v = Iterables.getOnlyElement(tx.query().has(vt, user).has(fn, bob).limit(1).vertices());
    assertEquals(bob, v.value(fn));
    assertEquals(user, v.value(vt));
    v = Iterables.getOnlyElement(tx.query().has(vt, user).has(fn, alice).limit(1).vertices());
    assertEquals(alice, v.value(fn));
    assertEquals(user, v.value(vt));
    tx.commit();
    tx = graph.newTransaction();
    v = Iterables.getOnlyElement(tx.query().has(vt, user).has(fn, bob).limit(1).vertices());
    assertEquals(bob, v.value(fn));
    assertEquals(user, v.value(vt));
    v = Iterables.getOnlyElement(tx.query().has(vt, user).has(fn, alice).limit(1).vertices());
    assertEquals(alice, v.value(fn));
    assertEquals(user, v.value(vt));
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Aggregations

JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)87 Test (org.junit.Test)72 PropertyKey (org.janusgraph.core.PropertyKey)54 EdgeLabel (org.janusgraph.core.EdgeLabel)20 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)18 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)18 Edge (org.apache.tinkerpop.gremlin.structure.Edge)17 VertexLabel (org.janusgraph.core.VertexLabel)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)13 BaseVertexLabel (org.janusgraph.graphdb.types.system.BaseVertexLabel)12 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)11 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)8 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)8 Instant (java.time.Instant)5 ArrayList (java.util.ArrayList)5 Random (java.util.Random)5 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)5 Direction (org.apache.tinkerpop.gremlin.structure.Direction)5 JanusGraph (org.janusgraph.core.JanusGraph)5