Search in sources :

Example 56 with PropertyKey

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

the class JanusGraphTest method testVertexCentricEdgeIndexOnSimpleMultiplicityShouldWork.

@Test
public void testVertexCentricEdgeIndexOnSimpleMultiplicityShouldWork() {
    clopen(option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250));
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.SIMPLE).make();
    mgmt.buildEdgeIndex(friend, "byTime", Direction.OUT, decr, time);
    finishSchema();
    assertEquals(SchemaStatus.ENABLED, mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime").getIndexStatus());
    JanusGraphVertex v = tx.addVertex();
    v = getV(tx, v);
    for (int i = 200; i < 210; i++) {
        JanusGraphVertex o = tx.addVertex();
        v.addEdge("friend", o, "time", i);
    }
    evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 199, 210).orderBy("time", decr), EDGE, 10, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
    tx.commit();
    finishSchema();
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 57 with PropertyKey

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

the class JanusGraphIndexTest method testEdgeTTLWithMixedIndices.

@Test
public void testEdgeTTLWithMixedIndices() throws Exception {
    if (!features.hasCellTTL() || !indexFeatures.supportsDocumentTTL()) {
        return;
    }
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey text = mgmt.makePropertyKey("text").dataType(String.class).make();
    PropertyKey time = makeKey("time", Long.class);
    EdgeLabel label = mgmt.makeEdgeLabel("likes").make();
    final int likesTTLSeconds = (int) TestGraphConfigs.getTTL(TimeUnit.SECONDS);
    mgmt.setTTL(label, Duration.ofSeconds(likesTTLSeconds));
    mgmt.buildIndex("index1", Edge.class).addKey(name, getStringMapping()).addKey(time).buildMixedIndex(INDEX);
    mgmt.buildIndex("index2", Edge.class).indexOnly(label).addKey(text, getTextMapping()).buildMixedIndex(INDEX);
    assertEquals(Duration.ZERO, mgmt.getTTL(name));
    assertEquals(Duration.ofSeconds(likesTTLSeconds), mgmt.getTTL(label));
    finishSchema();
    JanusGraphVertex v1 = tx.addVertex(), v2 = tx.addVertex(), v3 = tx.addVertex();
    Edge e1 = v1.addEdge("likes", v2, "name", "v1 likes v2", "text", "this will help to identify the edge");
    long time1 = System.currentTimeMillis();
    e1.property("time", time1);
    Edge e2 = v2.addEdge("likes", v3, "name", "v2 likes v3", "text", "this won't match anything");
    long time2 = time1 + 1;
    e2.property("time", time2);
    tx.commit();
    clopen();
    Object e1Id = e1.id();
    e2.id();
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "likes"), ElementCategory.EDGE, 1, new boolean[] { true, true }, "index2");
    evaluateQuery(tx.query().has("name", "v2 likes v3").orderBy("time", decr), ElementCategory.EDGE, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC, "index1");
    v1 = getV(tx, v1.id());
    v2 = getV(tx, v2.id());
    v3 = getV(tx, v3.id());
    e1 = getE(tx, e1Id);
    e2 = getE(tx, e1Id);
    assertNotNull(v1);
    assertNotNull(v2);
    assertNotNull(v3);
    assertNotNull(e1);
    assertNotNull(e2);
    assertNotEmpty(v1.query().direction(Direction.OUT).edges());
    assertNotEmpty(v2.query().direction(Direction.OUT).edges());
    Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(likesTTLSeconds * 1.25), TimeUnit.SECONDS));
    clopen();
    // ...indexes have expired
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "likes"), ElementCategory.EDGE, 0, new boolean[] { true, true }, "index2");
    evaluateQuery(tx.query().has("name", "v2 likes v3").orderBy("time", decr), ElementCategory.EDGE, 0, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC, "index1");
    v1 = getV(tx, v1.id());
    v2 = getV(tx, v2.id());
    v3 = getV(tx, v3.id());
    e1 = getE(tx, e1Id);
    e2 = getE(tx, e1Id);
    assertNotNull(v1);
    assertNotNull(v2);
    assertNotNull(v3);
    // edges have expired from the graph...
    assertNull(e1);
    assertNull(e2);
    assertEmpty(v1.query().direction(Direction.OUT).edges());
    assertEmpty(v2.query().direction(Direction.OUT).edges());
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 58 with PropertyKey

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

the class JanusGraphIndexTest method testBooleanIndexing.

/**
 * Tests indexing boolean
 */
@Test
public void testBooleanIndexing() {
    PropertyKey name = makeKey("visible", Boolean.class);
    mgmt.buildIndex("booleanIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
    finishSchema();
    clopen();
    JanusGraphVertex v1 = graph.addVertex();
    v1.property("visible", true);
    JanusGraphVertex v2 = graph.addVertex();
    v2.property("visible", false);
    assertCount(2, graph.vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
    // Flush the index
    clopen();
    assertCount(2, graph.vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 59 with PropertyKey

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

the class JanusGraphAbstractAuthenticator method setup.

@Override
public void setup(final Map<String, Object> config) {
    logger.info("Initializing authentication with the {}", this.getClass().getName());
    Preconditions.checkArgument(config != null, String.format("Could not configure a %s - provide a 'config' in the 'authentication' settings", this.getClass().getName()));
    Preconditions.checkState(config.containsKey(CONFIG_CREDENTIALS_DB), String.format("Credential configuration missing the %s key that points to a graph config file or graph name", CONFIG_CREDENTIALS_DB));
    if (!config.containsKey(CONFIG_DEFAULT_USER) || !config.containsKey(CONFIG_DEFAULT_PASSWORD)) {
        logger.warn(String.format("%s and %s should be defined to bootstrap authentication", CONFIG_DEFAULT_USER, CONFIG_DEFAULT_PASSWORD));
    }
    final JanusGraph graph = openGraph(config.get(CONFIG_CREDENTIALS_DB).toString());
    backingGraph = graph;
    credentialStore = createCredentialGraph(graph);
    graph.tx().rollback();
    ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
    if (!mgmt.containsGraphIndex(USERNAME_INDEX_NAME)) {
        final PropertyKey username = mgmt.makePropertyKey(PROPERTY_USERNAME).dataType(String.class).cardinality(Cardinality.SINGLE).make();
        mgmt.buildIndex(USERNAME_INDEX_NAME, Vertex.class).addKey(username).unique().buildCompositeIndex();
        mgmt.commit();
        mgmt = (ManagementSystem) graph.openManagement();
        final JanusGraphIndex index = mgmt.getGraphIndex(USERNAME_INDEX_NAME);
        if (!index.getIndexStatus(username).equals(SchemaStatus.ENABLED)) {
            try {
                mgmt = (ManagementSystem) graph.openManagement();
                mgmt.updateIndex(mgmt.getGraphIndex(USERNAME_INDEX_NAME), SchemaAction.REINDEX);
                ManagementSystem.awaitGraphIndexStatus(graph, USERNAME_INDEX_NAME).status(SchemaStatus.ENABLED).call();
                mgmt.commit();
            } catch (InterruptedException rude) {
                mgmt.rollback();
                throw new RuntimeException("Timed out waiting for byUsername index to be created on credential graph", rude);
            }
        }
    }
    final String defaultUser = config.get(CONFIG_DEFAULT_USER).toString();
    if (credentialStore.findUser(defaultUser) == null) {
        credentialStore.createUser(defaultUser, config.get(CONFIG_DEFAULT_PASSWORD).toString());
    }
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraph(org.janusgraph.core.JanusGraph) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey)

Example 60 with PropertyKey

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

the class HMACAuthenticatorTest method testSetupEmptyCredGraphNoUserIndex.

@Test
public void testSetupEmptyCredGraphNoUserIndex() {
    final HMACAuthenticator authenticator = createMockBuilder(HMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").createMock();
    final Map<String, Object> configMap = new HashMap<String, Object>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(HMACAuthenticator.CONFIG_HMAC_SECRET, "secret");
    configMap.put(HMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(HMACAuthenticator.CONFIG_DEFAULT_USER, "user");
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final Transaction tx = createMock(Transaction.class);
    final PropertyKey pk = createMock(PropertyKey.class);
    final PropertyKeyMaker pkm = createMock(PropertyKeyMaker.class);
    final JanusGraphManagement.IndexBuilder indexBuilder = createMock(JanusGraphManagement.IndexBuilder.class);
    final JanusGraphIndex index = createMock(JanusGraphIndex.class);
    final PropertyKey[] pks = { pk };
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(credentialGraph.findUser("user")).andReturn(null);
    expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
    expect(graph.openManagement()).andReturn(mgmt).times(2);
    expect(graph.tx()).andReturn(tx);
    expect(index.getFieldKeys()).andReturn(pks);
    expect(index.getIndexStatus(eq(pk))).andReturn(SchemaStatus.ENABLED);
    tx.rollback();
    expectLastCall();
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(false);
    expect(mgmt.makePropertyKey(PROPERTY_USERNAME)).andReturn(pkm);
    expect(pkm.dataType(eq(String.class))).andReturn(pkm);
    expect(pkm.cardinality(Cardinality.SINGLE)).andReturn(pkm);
    expect(pkm.make()).andReturn(pk);
    expect(mgmt.buildIndex(eq("byUsername"), eq(Vertex.class))).andReturn(indexBuilder);
    expect(mgmt.getGraphIndex(eq("byUsername"))).andReturn(index);
    expect(indexBuilder.addKey(eq(pk))).andReturn(indexBuilder);
    expect(indexBuilder.unique()).andReturn(indexBuilder);
    expect(indexBuilder.buildCompositeIndex()).andReturn(index);
    mgmt.commit();
    expectLastCall();
    mgmt.rollback();
    expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Aggregations

PropertyKey (org.janusgraph.core.PropertyKey)84 Test (org.junit.Test)59 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)57 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)28 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)28 EdgeLabel (org.janusgraph.core.EdgeLabel)21 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 Edge (org.apache.tinkerpop.gremlin.structure.Edge)14 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)13 VertexLabel (org.janusgraph.core.VertexLabel)13 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)11 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)9 BaseVertexLabel (org.janusgraph.graphdb.types.system.BaseVertexLabel)9 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)8 JanusGraph (org.janusgraph.core.JanusGraph)8 JanusGraphException (org.janusgraph.core.JanusGraphException)8 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)8 Instant (java.time.Instant)6 ExecutionException (java.util.concurrent.ExecutionException)6