Search in sources :

Example 41 with Session

use of ch.ethz.ssh2.Session in project neo4j by neo4j.

the class BoltFailuresIT method throwsWhenInitMessageFails.

private void throwsWhenInitMessageFails(Consumer<ThrowingSessionMonitor> monitorSetup, boolean shouldBeAbleToGetSession) {
    ThrowingSessionMonitor sessionMonitor = new ThrowingSessionMonitor();
    monitorSetup.accept(sessionMonitor);
    Monitors monitors = newMonitorsSpy(sessionMonitor);
    db = startTestDb(monitors);
    driver = createDriver();
    try (Session session = driver.session()) {
        if (shouldBeAbleToGetSession) {
            session.run("CREATE ()").consume();
        } else {
            fail("Exception expected");
        }
    } catch (Exception e) {
        assertThat(e, instanceOf(ConnectionFailureException.class));
    }
}
Also used : Monitors(org.neo4j.kernel.monitoring.Monitors) ConnectionFailureException(org.neo4j.driver.v1.exceptions.ConnectionFailureException) Session(org.neo4j.driver.v1.Session)

Example 42 with Session

use of ch.ethz.ssh2.Session in project neo4j by neo4j.

the class BoltCausalClusteringIT method shouldPickANewServerToWriteToOnLeaderSwitch.

@Test
public void shouldPickANewServerToWriteToOnLeaderSwitch() throws Throwable {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    LeaderSwitcher leaderSwitcher = new LeaderSwitcher(cluster);
    Config config = Config.build().withLogging(new JULogging(Level.OFF)).toConfig();
    Set<BoltServerAddress> seenAddresses = new HashSet<>();
    try (Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"), config)) {
        boolean success = false;
        long deadline = System.currentTimeMillis() + (30 * 1000);
        while (!success) {
            if (System.currentTimeMillis() > deadline) {
                fail("Failed to write to the new leader in time. Addresses seen: " + seenAddresses);
            }
            try (Session session = driver.session(AccessMode.WRITE)) {
                BoltServerAddress boltServerAddress = ((RoutingNetworkSession) session).address();
                session.run("CREATE (p:Person)");
                seenAddresses.add(boltServerAddress);
                success = seenAddresses.size() >= 2;
            } catch (Exception e) {
                Thread.sleep(100);
            }
            /*
                 * Having the latch release here ensures that we've done at least one pass through the loop, which means
                 * we've completed a connection before the forced master switch.
                 */
            if (seenAddresses.size() >= 1) {
                leaderSwitcher.start();
            }
        }
    } finally {
        leaderSwitcher.stop();
        assertTrue(leaderSwitcher.hadLeaderSwitch());
        assertThat(seenAddresses.size(), greaterThanOrEqualTo(2));
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Config(org.neo4j.driver.v1.Config) Driver(org.neo4j.driver.v1.Driver) TimeoutException(java.util.concurrent.TimeoutException) SessionExpiredException(org.neo4j.driver.v1.exceptions.SessionExpiredException) ServiceUnavailableException(org.neo4j.driver.v1.exceptions.ServiceUnavailableException) IOException(java.io.IOException) ClientException(org.neo4j.driver.v1.exceptions.ClientException) BoltServerAddress(org.neo4j.driver.internal.net.BoltServerAddress) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) JULogging(org.neo4j.driver.internal.logging.JULogging) HashSet(java.util.HashSet) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 43 with Session

use of ch.ethz.ssh2.Session in project neo4j by neo4j.

the class BoltCausalClusteringIT method bookmarksShouldWorkWithDriverPinnedToSingleServer.

// Ensure that Bookmarks work with single instances using a driver created using a bolt[not+routing] URI.
@Test
public void bookmarksShouldWorkWithDriverPinnedToSingleServer() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    try (Driver driver = GraphDatabase.driver(leader.directURI(), AuthTokens.basic("neo4j", "neo4j"))) {
        String bookmark = inExpirableSession(driver, Driver::session, (session) -> {
            try (Transaction tx = session.beginTransaction()) {
                tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Alistair"));
                tx.success();
            }
            return session.lastBookmark();
        });
        assertNotNull(bookmark);
        try (Session session = driver.session();
            Transaction tx = session.beginTransaction(bookmark)) {
            Record record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            assertEquals(1, record.get("count").asInt());
            tx.success();
        }
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 44 with Session

use of ch.ethz.ssh2.Session in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningDriverPeriodicCommitQuery.

@Test
public void terminateLongRunningDriverPeriodicCommitQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeoutCustomGuard();
    CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
    org.neo4j.driver.v1.Config driverConfig = getDriverConfig();
    try (Driver driver = GraphDatabase.driver("bolt://localhost:" + boltPortCustomGuard, driverConfig);
        Session session = driver.session()) {
        URL url = prepareTestImportFile(8);
        session.run("USING PERIODIC COMMIT 5 LOAD CSV FROM '" + url + "' AS line CREATE ();").consume();
        fail("Transaction should be already terminated by execution guard.");
    } catch (Exception expected) {
    //
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) Driver(org.neo4j.driver.v1.Driver) URL(java.net.URL) GuardTimeoutException(org.neo4j.kernel.guard.GuardTimeoutException) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) IOException(java.io.IOException) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 45 with Session

use of ch.ethz.ssh2.Session in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningDriverQuery.

@Test
public void terminateLongRunningDriverQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeout();
    CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
    org.neo4j.driver.v1.Config driverConfig = getDriverConfig();
    try (Driver driver = GraphDatabase.driver("bolt://localhost:" + boltPortDatabaseWithTimeout, driverConfig);
        Session session = driver.session()) {
        org.neo4j.driver.v1.Transaction transaction = session.beginTransaction();
        transaction.run("create (n)").consume();
        transaction.success();
        fakeClock.forward(3, TimeUnit.SECONDS);
        try {
            transaction.run("create (n)").consume();
            fail("Transaction should be already terminated by execution guard.");
        } catch (Exception expected) {
        // ignored
        }
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) Driver(org.neo4j.driver.v1.Driver) GuardTimeoutException(org.neo4j.kernel.guard.GuardTimeoutException) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) IOException(java.io.IOException) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Aggregations

Session (com.trilead.ssh2.Session)37 Connection (com.trilead.ssh2.Connection)31 IOException (java.io.IOException)25 InputStream (java.io.InputStream)24 Session (org.neo4j.driver.v1.Session)16 Test (org.junit.Test)15 Driver (org.neo4j.driver.v1.Driver)14 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)9 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 HttpException (org.apache.commons.httpclient.HttpException)8 Session (ch.ethz.ssh2.Session)6 SCPClient (com.trilead.ssh2.SCPClient)6 StreamGobbler (com.trilead.ssh2.StreamGobbler)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Transaction (org.neo4j.driver.v1.Transaction)5 Record (org.neo4j.driver.v1.Record)4 StreamGobbler (ch.ethz.ssh2.StreamGobbler)3 BufferedReader (java.io.BufferedReader)3