Search in sources :

Example 86 with Session

use of com.trilead.ssh2.Session in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method invalidSyntaxInTranslation.

@Test
public void invalidSyntaxInTranslation() {
    Config config = Config.build().withTranslation(TranslatorFlavor.gremlinServer()).toConfig();
    Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort(), config);
    try (Session session = driver.session()) {
        StatementResult result = session.run("INVALID");
        Throwable throwable = catchThrowable(result::list);
        assertThat(throwable).hasMessageContaining("Invalid input");
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Config(org.opencypher.Config) Driver(org.neo4j.driver.v1.Driver) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 87 with Session

use of com.trilead.ssh2.Session in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method simple.

@Test
public void simple() {
    Driver adam = GremlinDatabase.driver("//localhost:" + server.getPort());
    try (Session session = adam.session()) {
        StatementResult result = session.run("MATCH (n:person) RETURN count(n) as count");
        int count = result.single().get("count").asInt();
        assertThat(count).isEqualTo(4);
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 88 with Session

use of com.trilead.ssh2.Session 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 89 with Session

use of com.trilead.ssh2.Session in project cypher-for-gremlin by opencypher.

the class CypherGremlinNeo4jDriver method createUseDriver.

@Test
public void createUseDriver() throws Exception {
    int port = gremlinServer.getPort();
    // freshReadmeSnippet: createConfiguration
    Config config = Config.build().withTranslation().toConfig();
    String uri = "//localhost:" + port;
    Driver driver = GremlinDatabase.driver(uri, config);
    // freshReadmeSnippet: useDriver
    try (Session session = driver.session()) {
        StatementResult result = session.run("CREATE (a:Greeting) " + "SET a.message = $message " + "RETURN a.message", parameters("message", "Hello"));
        String message = result.single().get(0).asString();
        assertThat(message).isEqualTo("Hello");
    }
// freshReadmeSnippet: useDriver
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Config(org.opencypher.Config) Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 90 with Session

use of com.trilead.ssh2.Session in project open-kilda by telstra.

the class NeoDriver method getFlowInfo.

/**
 * {@inheritDoc}
 */
@Override
public List<FlowInfo> getFlowInfo() {
    List<FlowInfo> flows = new ArrayList<>();
    String subject = "MATCH (:switch)-[f:flow]->(:switch) " + "RETURN f.flowid as flow_id, " + " f.cookie as cookie, " + " f.meter_id as meter_id, " + " f.transit_vlan as transit_vlan, " + " f.src_switch as src_switch";
    Session session = driver.session();
    StatementResult result = session.run(subject);
    for (Record record : result.list()) {
        flows.add(new FlowInfo().setFlowId(record.get("flow_id").asString()).setSrcSwitchId(record.get("src_switch").asString()).setCookie(record.get("cookie").asLong()).setMeterId(record.get("meter_id").asInt()).setTransitVlanId(record.get("transit_vlan").asInt()));
    }
    return flows;
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Record(org.neo4j.driver.v1.Record) Session(org.neo4j.driver.v1.Session)

Aggregations

Session (com.trilead.ssh2.Session)43 Session (org.neo4j.driver.v1.Session)38 Connection (com.trilead.ssh2.Connection)32 IOException (java.io.IOException)31 Test (org.junit.Test)29 InputStream (java.io.InputStream)28 Driver (org.neo4j.driver.v1.Driver)27 StatementResult (org.neo4j.driver.v1.StatementResult)20 Record (org.neo4j.driver.v1.Record)12 Session (iaik.pkcs.pkcs11.Session)10 TokenException (iaik.pkcs.pkcs11.TokenException)10 P11TokenException (org.xipki.security.exception.P11TokenException)10 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)9 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 Session (ch.ethz.ssh2.Session)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 HttpException (org.apache.commons.httpclient.HttpException)8 Transaction (org.neo4j.driver.v1.Transaction)7 SCPClient (com.trilead.ssh2.SCPClient)6