Search in sources :

Example 1 with Cluster

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

the class CypherGremlinServerClient method gremlinStyle.

@Test
public void gremlinStyle() throws Exception {
    BaseConfiguration configuration = new BaseConfiguration();
    configuration.setProperty("port", gremlinServer.getPort());
    configuration.setProperty("hosts", Arrays.asList("localhost"));
    // freshReadmeSnippet: gremlinStyle
    Cluster cluster = Cluster.open(configuration);
    Client gremlinClient = cluster.connect();
    CypherGremlinClient cypherGremlinClient = CypherGremlinClient.plugin(gremlinClient);
    String cypher = "MATCH (p:person) WHERE p.age > 25 RETURN p.name";
    CypherResultSet resultSet = cypherGremlinClient.submit(cypher);
    List<Map<String, Object>> results = resultSet.all();
    // freshReadmeSnippet: gremlinStyle
    assertThat(results).extracting("p.name").containsExactly("marko", "vadas", "josh", "peter");
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CypherResultSet(org.opencypher.gremlin.client.CypherResultSet) 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 2 with Cluster

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

the class CypherGremlinNeo4jDriver method createDriver.

@Test
public void createDriver() throws Exception {
    String pathToGremlinConfiguration = "../../tinkerpop/cypher-gremlin-server-plugin/src/main/resources/local-gremlin-server.yaml";
    // freshReadmeSnippet: createDriver
    Cluster cluster1 = Cluster.build().enableSsl(true).addContactPoints("192.168.0.145").create();
    Driver driver1 = GremlinDatabase.driver(cluster1);
    // Or:
    Cluster cluster2 = Cluster.open(pathToGremlinConfiguration);
    Driver driver2 = GremlinDatabase.driver(cluster2);
// freshReadmeSnippet: createDriver
}
Also used : Cluster(org.apache.tinkerpop.gremlin.driver.Cluster) Driver(org.neo4j.driver.v1.Driver) Test(org.junit.Test)

Example 3 with Cluster

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

the class ConfigurationManagementGraphServerTest method bindingShouldExistAfterGraphIsCreated.

@Test
public void bindingShouldExistAfterGraphIsCreated() throws Exception {
    final Cluster cluster = TestClientFactory.open();
    final Client client = cluster.connect();
    // create newGraph
    client.submit("Map<String, Object> map = new HashMap<String, Object>(); map.put(\"storage.backend\", \"inmemory\"); " + "org.janusgraph.core.ConfiguredGraphFactory.createTemplateConfiguration(" + "org.janusgraph.util.system.ConfigurationUtil.loadMapConfiguration(map));" + "org.janusgraph.core.ConfiguredGraphFactory.create(\"newGraph\")");
    Thread.sleep(1000, 0);
    // 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());
    // Ensure that we can open a remote graph traversal source against the created graph, and execute traversals
    GraphTraversalSource newGraphTraversal = traversal().withRemote(DriverRemoteConnection.using(cluster, "newGraph_traversal"));
    assertEquals(0, newGraphTraversal.V().count().next().longValue());
    cluster.close();
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Cluster(org.apache.tinkerpop.gremlin.driver.Cluster) Client(org.apache.tinkerpop.gremlin.driver.Client) Test(org.junit.jupiter.api.Test)

Example 4 with Cluster

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

the class ConfigurationManagementGraphServerTest method bindingForConfigurationManagementGraphShouldExists.

@Test
public void bindingForConfigurationManagementGraphShouldExists() throws Exception {
    final Cluster cluster = TestClientFactory.open();
    final Client client = cluster.connect();
    assertEquals(0, client.submit("ConfigurationManagementGraph.vertices().size()").all().get().get(0).getInt());
}
Also used : Cluster(org.apache.tinkerpop.gremlin.driver.Cluster) Client(org.apache.tinkerpop.gremlin.driver.Client) Test(org.junit.jupiter.api.Test)

Example 5 with Cluster

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

the class ConfigurationManagementGraphServerTest method newGraphDoesntExistsBeforeCreation.

@Test
public void newGraphDoesntExistsBeforeCreation() throws Exception {
    final Cluster cluster = TestClientFactory.open();
    final Client client = cluster.connect();
    // assert ConfigurationManagementGraph is bound
    assertEquals(0, client.submit("ConfigurationManagementGraph.vertices().size()").all().get().get(0).getInt());
    // assert new graph is not bound
    ExecutionException executionException = assertThrows(ExecutionException.class, () -> {
        client.submit("newGraph").all().get();
    });
    assertEquals("org.apache.tinkerpop.gremlin.driver.exception.ResponseException: No such property: newGraph for class: Script3", executionException.getMessage());
}
Also used : Cluster(org.apache.tinkerpop.gremlin.driver.Cluster) Client(org.apache.tinkerpop.gremlin.driver.Client) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

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