Search in sources :

Example 36 with JanusGraph

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

the class JanusGraphSimpleAuthenticatorTest method testSetupEmptyNoUserDefault.

@Test(expected = IllegalStateException.class)
public void testSetupEmptyNoUserDefault() {
    final JanusGraphSimpleAuthenticator authenticator = createMockBuilder(JanusGraphSimpleAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").createMock();
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final Map<String, Object> configMap = new HashMap<String, Object>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(credentialGraph.countUsers()).andReturn(0l);
    authenticator.setup(configMap);
}
Also used : CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph) Test(org.junit.Test)

Example 37 with JanusGraph

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

the class JanusGraphSimpleAuthenticatorTest method testPassEmptyCredGraphUserIndex.

@Test
public void testPassEmptyCredGraphUserIndex() {
    final JanusGraphSimpleAuthenticator authenticator = createMockBuilder(JanusGraphSimpleAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").createMock();
    final Map<String, Object> configMap = new HashMap<>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_USER, "user");
    final SimpleAuthenticator sa = createMock(SimpleAuthenticator.class);
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final Transaction tx = createMock(Transaction.class);
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(authenticator.createSimpleAuthenticator()).andReturn(sa);
    expect(credentialGraph.findUser("user")).andReturn(null);
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(true);
    expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
    expect(graph.openManagement()).andReturn(mgmt);
    expect(graph.tx()).andReturn(tx);
    sa.setup(configMap);
    EasyMock.expectLastCall();
    graph.close();
    EasyMock.expectLastCall();
    tx.rollback();
    EasyMock.expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) HashMap(java.util.HashMap) SimpleAuthenticator(org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator) JanusGraph(org.janusgraph.core.JanusGraph) Test(org.junit.Test)

Example 38 with JanusGraph

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

the class VertexIDAssignerTest method testIDAssignment.

@Test
public void testIDAssignment() {
    LongSet vertexIds = new LongHashSet();
    LongSet relationIds = new LongHashSet();
    int totalRelations = 0;
    int totalVertices = 0;
    for (int trial = 0; trial < 10; trial++) {
        for (boolean flush : new boolean[] { true, false }) {
            final JanusGraph graph = getInMemoryGraph(false, false);
            int numVertices = 1000;
            final List<JanusGraphVertex> vertices = new ArrayList<>(numVertices);
            final List<InternalRelation> relations = new ArrayList<>();
            JanusGraphVertex old = null;
            totalRelations += 2 * numVertices;
            totalVertices += numVertices;
            try {
                for (int i = 0; i < numVertices; i++) {
                    JanusGraphVertex next = graph.addVertex();
                    InternalRelation edge = null;
                    if (old != null) {
                        edge = (InternalRelation) old.addEdge("knows", next);
                    }
                    InternalRelation property = (InternalRelation) next.property("age", 25);
                    if (flush) {
                        idAssigner.assignID((InternalVertex) next, next.vertexLabel());
                        idAssigner.assignID(property);
                        if (edge != null)
                            idAssigner.assignID(edge);
                    }
                    relations.add(property);
                    if (edge != null)
                        relations.add(edge);
                    vertices.add(next);
                    old = next;
                }
                if (!flush)
                    idAssigner.assignIDs(relations);
                // Check if we should have exhausted the id pools
                if (totalRelations > maxIDAssignments || totalVertices > maxIDAssignments)
                    fail();
                // Verify that ids are set and unique
                for (JanusGraphVertex v : vertices) {
                    assertTrue(v.hasId());
                    long id = v.longId();
                    assertTrue(id > 0 && id < Long.MAX_VALUE);
                    assertTrue(vertexIds.add(id));
                }
                for (InternalRelation r : relations) {
                    assertTrue(r.hasId());
                    long id = r.longId();
                    assertTrue(id > 0 && id < Long.MAX_VALUE);
                    assertTrue(relationIds.add(id));
                }
            } catch (IDPoolExhaustedException e) {
                // Since the id assignment process is randomized, we divide by 3/2 to account for minor variations
                assertTrue("Max Avail: " + maxIDAssignments + " vs. [" + totalVertices + "," + totalRelations + "]", totalRelations >= maxIDAssignments / 3 * 2 || totalVertices >= maxIDAssignments / 3 * 2);
            } finally {
                graph.tx().rollback();
                graph.close();
            }
        }
    }
}
Also used : LongHashSet(com.carrotsearch.hppc.LongHashSet) LongSet(com.carrotsearch.hppc.LongSet) JanusGraph(org.janusgraph.core.JanusGraph) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) ArrayList(java.util.ArrayList) IDPoolExhaustedException(org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException) InternalRelation(org.janusgraph.graphdb.internal.InternalRelation) Test(org.junit.Test)

Aggregations

JanusGraph (org.janusgraph.core.JanusGraph)38 Test (org.junit.Test)23 HashMap (java.util.HashMap)20 CredentialGraph (org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph)20 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)15 Transaction (org.apache.tinkerpop.gremlin.structure.Transaction)14 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)12 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)9 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)7 SimpleAuthenticator (org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator)5 PropertyKey (org.janusgraph.core.PropertyKey)5 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)5 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)4 PropertyKeyMaker (org.janusgraph.core.schema.PropertyKeyMaker)3 LongHashSet (com.carrotsearch.hppc.LongHashSet)2 LongSet (com.carrotsearch.hppc.LongSet)2 ArrayList (java.util.ArrayList)2 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)2 AuthenticationException (org.apache.tinkerpop.gremlin.server.auth.AuthenticationException)2 Graph (org.apache.tinkerpop.gremlin.structure.Graph)2