Search in sources :

Example 6 with Cluster

use of org.apache.tinkerpop.gremlin.driver.Cluster in project janusgraph by JanusGraph.

the class AbstractJanusGraphAssemblyIT method runTraversalAgainstServer.

protected void runTraversalAgainstServer(MessageSerializer serializer) {
    Cluster cluster = Cluster.build("localhost").port(8182).serializer(serializer).create();
    GraphTraversalSource g = AnonymousTraversalSource.traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
    testServerUsingTraversalSource(g);
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Cluster(org.apache.tinkerpop.gremlin.driver.Cluster)

Example 7 with Cluster

use of org.apache.tinkerpop.gremlin.driver.Cluster in project janusgraph by JanusGraph.

the class JanusGraphChannelizerTest method bindingShouldExistAfterGraphIsCreated.

@Test
public void bindingShouldExistAfterGraphIsCreated() throws Exception {
    final Cluster cluster = TestClientFactory.open();
    final Client client = cluster.connect();
    try {
        // assert server is running correctly
        assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
        // assert ConfigurationManagementGraph is bound
        assertEquals(0, client.submit("ConfigurationManagementGraph.vertices().size()").all().get().get(0).getInt());
        // assert new graph is not bound
        thrown.expect(ExecutionException.class);
        thrown.expectMessage(equalTo("org.apache.tinkerpop.gremlin.driver.exception.ResponseException: No such property: " + "newGraph for class: Script3"));
        client.submit("newGraph").all().get();
        // create newGraph
        client.submit("Map<String, Object> map = new HashMap<String, Object>(); map.put(\"storage.backend\", \"inmemory\"); " + "org.janusgraph.core.ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));" + "org.janusgraph.core.ConfiguredGraphFactory.create(\"newGraph\")");
        // assert newGraph is indeed bound
        assertEquals(0, client.submit("newGraph.vertices().size()").all().get().get(0).getInt());
        // assert newGraph_traversal is bound and the graphs are equivalent
        assertEquals("newGraph", client.submit("newGraph_traversal.getGraph().getGraphName()").all().get().get(0).getString());
    } finally {
        cluster.close();
    }
}
Also used : Cluster(org.apache.tinkerpop.gremlin.driver.Cluster) Client(org.apache.tinkerpop.gremlin.driver.Client) Test(org.junit.Test)

Example 8 with Cluster

use of org.apache.tinkerpop.gremlin.driver.Cluster in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method multipleRows.

@Test
public void multipleRows() {
    Cluster cluster = Cluster.build().addContactPoints("localhost").port(server.getPort()).create();
    Driver driver = GremlinDatabase.driver(cluster);
    try (Session session = driver.session()) {
        StatementResult result = session.run("MATCH (p:person) RETURN p.name, p.age");
        List<String> rows = result.list(r -> r.get("p.name").asString() + r.get("p.age").asInt());
        assertThat(rows).containsExactly("marko29", "vadas27", "josh32", "peter35");
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Cluster(org.apache.tinkerpop.gremlin.driver.Cluster) Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 9 with Cluster

use of org.apache.tinkerpop.gremlin.driver.Cluster in project cypher-for-gremlin by opencypher.

the class CypherGremlinServerClient method translating.

@Test
public void translating() {
    BaseConfiguration configuration = new BaseConfiguration();
    configuration.setProperty("port", gremlinServer.getPort());
    configuration.setProperty("hosts", Arrays.asList("localhost"));
    Cluster cluster = Cluster.open(configuration);
    Client gremlinClient = cluster.connect();
    // freshReadmeSnippet: translating
    CypherGremlinClient cypherGremlinClient = CypherGremlinClient.translating(gremlinClient);
    // freshReadmeSnippet: translating
    List<Map<String, Object>> results = cypherGremlinClient.submit("MATCH (p:person) WHERE p.age > 25 RETURN p.name").all();
    assertThat(results).extracting("p.name").containsExactly("marko", "vadas", "josh", "peter");
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Cluster(org.apache.tinkerpop.gremlin.driver.Cluster) CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) Client(org.apache.tinkerpop.gremlin.driver.Client) Map(java.util.Map) Test(org.junit.Test)

Example 10 with Cluster

use of org.apache.tinkerpop.gremlin.driver.Cluster in project DataX by alibaba.

the class AbstractGdbGraph method initClient.

protected void initClient(final Configuration config, final boolean session) {
    this.updateMode = Key.UpdateMode.valueOf(config.getString(Key.UPDATE_MODE, "INSERT"));
    log.info("init graphdb client");
    final String host = config.getString(Key.HOST);
    final int port = config.getInt(Key.PORT);
    final String username = config.getString(Key.USERNAME);
    final String password = config.getString(Key.PASSWORD);
    int maxDepthPerConnection = config.getInt(Key.MAX_IN_PROCESS_PER_CONNECTION, GdbWriterConfig.DEFAULT_MAX_IN_PROCESS_PER_CONNECTION);
    int maxConnectionPoolSize = config.getInt(Key.MAX_CONNECTION_POOL_SIZE, GdbWriterConfig.DEFAULT_MAX_CONNECTION_POOL_SIZE);
    int maxSimultaneousUsagePerConnection = config.getInt(Key.MAX_SIMULTANEOUS_USAGE_PER_CONNECTION, GdbWriterConfig.DEFAULT_MAX_SIMULTANEOUS_USAGE_PER_CONNECTION);
    this.session = session;
    if (this.session) {
        maxConnectionPoolSize = GdbWriterConfig.DEFAULT_MAX_CONNECTION_POOL_SIZE;
        maxDepthPerConnection = GdbWriterConfig.DEFAULT_MAX_IN_PROCESS_PER_CONNECTION;
        maxSimultaneousUsagePerConnection = GdbWriterConfig.DEFAULT_MAX_SIMULTANEOUS_USAGE_PER_CONNECTION;
    }
    try {
        final Cluster cluster = Cluster.build(host).port(port).credentials(username, password).serializer(Serializers.GRAPHBINARY_V1D0).maxContentLength(1048576).maxInProcessPerConnection(maxDepthPerConnection).minInProcessPerConnection(0).maxConnectionPoolSize(maxConnectionPoolSize).minConnectionPoolSize(maxConnectionPoolSize).maxSimultaneousUsagePerConnection(maxSimultaneousUsagePerConnection).resultIterationBatchSize(64).create();
        this.client = session ? cluster.connect(UUID.randomUUID().toString()).init() : cluster.connect().init();
        warmClient(maxConnectionPoolSize * maxDepthPerConnection);
    } catch (final RuntimeException e) {
        log.error("Failed to connect to GDB {}:{}, due to {}", host, port, e);
        throw e;
    }
    this.propertiesBatchNum = config.getInt(Key.MAX_PROPERTIES_BATCH_NUM, DEFAULT_BATCH_PROPERTY_NUM);
    this.maxRequestLength = config.getInt(Key.MAX_GDB_REQUEST_LENGTH, MAX_REQUEST_LENGTH);
}
Also used : Cluster(org.apache.tinkerpop.gremlin.driver.Cluster)

Aggregations

Cluster (org.apache.tinkerpop.gremlin.driver.Cluster)11 Client (org.apache.tinkerpop.gremlin.driver.Client)7 Test (org.junit.Test)5 Test (org.junit.jupiter.api.Test)4 Map (java.util.Map)2 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)2 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)2 Driver (org.neo4j.driver.v1.Driver)2 CypherGremlinClient (org.opencypher.gremlin.client.CypherGremlinClient)2 ExecutionException (java.util.concurrent.ExecutionException)1 Session (org.neo4j.driver.v1.Session)1 StatementResult (org.neo4j.driver.v1.StatementResult)1 CypherResultSet (org.opencypher.gremlin.client.CypherResultSet)1