Search in sources :

Example 26 with RelationType

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

the class JanusGraphConcurrentTest method concurrentTxRead.

@RepeatedTest(10)
public void concurrentTxRead() throws Exception {
    final int numTypes = 20;
    final int numThreads = 100;
    for (int i = 0; i < numTypes / 2; i++) {
        if (i % 4 == 0)
            makeVertexIndexedUniqueKey("test" + i, String.class);
        else
            makeKey("test" + i, String.class);
    }
    for (int i = numTypes / 2; i < numTypes; i++) {
        EdgeLabelMaker tm = mgmt.makeEdgeLabel("test" + i);
        if (i % 4 == 1)
            tm.unidirected();
        tm.make();
    }
    finishSchema();
    clopen();
    Thread[] threads = new Thread[numThreads];
    for (int t = 0; t < numThreads; t++) {
        threads[t] = new Thread(() -> {
            JanusGraphTransaction tx = graph.newTransaction();
            for (int i = 0; i < numTypes; i++) {
                RelationType type = tx.getRelationType("test" + i);
                if (i < numTypes / 2)
                    assertTrue(type.isPropertyKey());
                else
                    assertTrue(type.isEdgeLabel());
            }
            tx.commit();
        });
        threads[t].start();
    }
    for (int t = 0; t < numThreads; t++) {
        threads[t].join();
    }
}
Also used : JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) RelationType(org.janusgraph.core.RelationType) EdgeLabelMaker(org.janusgraph.core.schema.EdgeLabelMaker) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 27 with RelationType

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

the class StandardJanusGraphTxTest method createTxWithMockedInternals.

private StandardJanusGraphTx createTxWithMockedInternals() throws BackendException {
    StandardJanusGraph mockGraph = createMock(StandardJanusGraph.class);
    TransactionConfiguration txConfig = createMock(TransactionConfiguration.class);
    GraphDatabaseConfiguration gdbConfig = createMock(GraphDatabaseConfiguration.class);
    BackendTransaction txHandle = createMock(BackendTransaction.class);
    TimestampProvider tsProvider = createMock(TimestampProvider.class);
    Serializer mockSerializer = createMock(Serializer.class);
    EdgeSerializer mockEdgeSerializer = createMock(EdgeSerializer.class);
    IndexSerializer mockIndexSerializer = createMock(IndexSerializer.class);
    RelationType relationType = createMock(RelationType.class);
    IDManager idManager = createMock(IDManager.class);
    PropertyKey propertyKey = createMock(PropertyKey.class);
    DefaultSchemaMaker defaultSchemaMaker = createMock(DefaultSchemaMaker.class);
    IndexSelectionStrategy indexSelectionStrategy = createMock(ThresholdBasedIndexSelectionStrategy.class);
    expect(mockGraph.getConfiguration()).andReturn(gdbConfig);
    expect(mockGraph.isOpen()).andReturn(true).anyTimes();
    expect(mockGraph.getDataSerializer()).andReturn(mockSerializer);
    expect(mockGraph.getEdgeSerializer()).andReturn(mockEdgeSerializer);
    expect(mockGraph.getIndexSerializer()).andReturn(mockIndexSerializer);
    expect(mockGraph.getIDManager()).andReturn(idManager);
    expect(mockGraph.getIndexSelector()).andReturn(indexSelectionStrategy);
    mockGraph.closeTransaction(isA(StandardJanusGraphTx.class));
    EasyMock.expectLastCall().anyTimes();
    expect(gdbConfig.getTimestampProvider()).andReturn(tsProvider);
    expect(txConfig.isSingleThreaded()).andReturn(true);
    expect(txConfig.hasPreloadedData()).andReturn(false);
    expect(txConfig.hasVerifyExternalVertexExistence()).andReturn(false);
    expect(txConfig.hasVerifyInternalVertexExistence()).andReturn(false);
    expect(txConfig.getVertexCacheSize()).andReturn(6);
    expect(txConfig.isReadOnly()).andReturn(true);
    expect(txConfig.getDirtyVertexSize()).andReturn(2);
    expect(txConfig.getIndexCacheWeight()).andReturn(2L);
    expect(txConfig.getGroupName()).andReturn(null).anyTimes();
    expect(txConfig.getAutoSchemaMaker()).andReturn(defaultSchemaMaker);
    expect(defaultSchemaMaker.makePropertyKey(isA(PropertyKeyMaker.class), notNull())).andReturn(propertyKey);
    expect(relationType.isPropertyKey()).andReturn(false);
    expect(propertyKey.isPropertyKey()).andReturn(true);
    txHandle.rollback();
    EasyMock.expectLastCall().anyTimes();
    replayAll();
    StandardJanusGraphTx partialMock = createMockBuilder(StandardJanusGraphTx.class).withConstructor(mockGraph, txConfig).addMockedMethod("getRelationType").createMock();
    partialMock.setBackendTransaction(txHandle);
    expect(partialMock.getRelationType("Foo")).andReturn(null);
    expect(partialMock.getRelationType("Qux")).andReturn(propertyKey);
    expect(partialMock.getRelationType("Baz")).andReturn(relationType);
    replay(partialMock);
    return partialMock;
}
Also used : IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) IDManager(org.janusgraph.graphdb.idmanagement.IDManager) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) ThresholdBasedIndexSelectionStrategy(org.janusgraph.graphdb.query.index.ThresholdBasedIndexSelectionStrategy) IndexSelectionStrategy(org.janusgraph.graphdb.query.index.IndexSelectionStrategy) PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) DefaultSchemaMaker(org.janusgraph.core.schema.DefaultSchemaMaker) RelationType(org.janusgraph.core.RelationType) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) BackendTransaction(org.janusgraph.diskstorage.BackendTransaction) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) IndexSerializer(org.janusgraph.graphdb.database.IndexSerializer) Serializer(org.janusgraph.graphdb.database.serialize.Serializer)

Example 28 with RelationType

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

the class StandardJanusGraphTx method getPropertyKey.

@Override
public PropertyKey getPropertyKey(String name) {
    RelationType pk = getRelationType(name);
    Preconditions.checkArgument(pk == null || pk.isPropertyKey(), "The relation type with name [%s] is not a property key", name);
    return (PropertyKey) pk;
}
Also used : SystemRelationType(org.janusgraph.graphdb.types.system.SystemRelationType) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) PropertyKey(org.janusgraph.core.PropertyKey)

Example 29 with RelationType

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

the class StandardJanusGraphTx method getRelationType.

@Override
public RelationType getRelationType(String name) {
    verifyOpen();
    RelationType type = SystemTypeManager.getSystemType(name);
    if (type != null)
        return type;
    return (RelationType) getSchemaVertex(JanusGraphSchemaCategory.getRelationTypeName(name));
}
Also used : SystemRelationType(org.janusgraph.graphdb.types.system.SystemRelationType) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType)

Example 30 with RelationType

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

the class StandardJanusGraphTx method getEdgeLabel.

@Override
public EdgeLabel getEdgeLabel(String name) {
    RelationType el = getRelationType(name);
    Preconditions.checkArgument(el == null || el.isEdgeLabel(), "The relation type with name [%s] is not an edge label", name);
    return (EdgeLabel) el;
}
Also used : SystemRelationType(org.janusgraph.graphdb.types.system.SystemRelationType) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) EdgeLabel(org.janusgraph.core.EdgeLabel)

Aggregations

RelationType (org.janusgraph.core.RelationType)30 InternalRelationType (org.janusgraph.graphdb.internal.InternalRelationType)22 PropertyKey (org.janusgraph.core.PropertyKey)10 JanusGraphRelation (org.janusgraph.core.JanusGraphRelation)6 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)6 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)6 StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)6 Map (java.util.Map)5 Direction (org.apache.tinkerpop.gremlin.structure.Direction)5 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)4 SystemRelationType (org.janusgraph.graphdb.types.system.SystemRelationType)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 EdgeLabel (org.janusgraph.core.EdgeLabel)3 VertexLabel (org.janusgraph.core.VertexLabel)3 PredicateCondition (org.janusgraph.graphdb.query.condition.PredicateCondition)3 ImplicitKey (org.janusgraph.graphdb.types.system.ImplicitKey)3 Preconditions (com.google.common.base.Preconditions)2 Collection (java.util.Collection)2 List (java.util.List)2