use of ch.ethz.ssh2.Session in project neo4j by neo4j.
the class BoltCausalClusteringIT method sessionShouldExpireOnFailingReadQuery.
@Test
public void sessionShouldExpireOnFailingReadQuery() throws Exception {
// given
cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
CoreClusterMember coreServer = cluster.getCoreMemberById(0);
Driver driver = GraphDatabase.driver(coreServer.routingURI(), AuthTokens.basic("neo4j", "neo4j"));
inExpirableSession(driver, Driver::session, (session) -> {
session.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
return null;
});
try (Session readSession = driver.session(AccessMode.READ)) {
// when
connectedServer(readSession).shutdown();
// then
readSession.run("MATCH (n) RETURN n LIMIT 1").consume();
fail("Should have thrown an exception as the read replica went away mid query");
} catch (SessionExpiredException sep) {
// then
assertThat(sep.getMessage(), containsString("is no longer available"));
} finally {
driver.close();
}
}
use of ch.ethz.ssh2.Session in project neo4j by neo4j.
the class BoltCausalClusteringIT method shouldNotBeAbleToWriteOnAReadSession.
@Test
public void shouldNotBeAbleToWriteOnAReadSession() throws Exception {
// given
cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
assertEventually("Failed to execute write query on read server", () -> {
switchLeader(cluster.awaitLeader());
CoreClusterMember leader = cluster.awaitLeader();
Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"));
try (Session session = driver.session(AccessMode.READ)) {
// when
session.run("CREATE (n:Person {name: 'Jim'})").consume();
return false;
} catch (ClientException ex) {
assertEquals("Write queries cannot be performed in READ access mode.", ex.getMessage());
return true;
} finally {
driver.close();
}
}, is(true), 30, SECONDS);
}
use of ch.ethz.ssh2.Session in project jstorm by alibaba.
the class MyScpClient method get.
/**
* Download a set of files from the remote server to a local directory.
*
* @param remoteFiles Paths and names of the remote files.
* @param localTargetDirectory Local directory to put the downloaded files.
* @throws IOException
*/
public void get(String[] remoteFiles, String localTargetDirectory) throws IOException {
Session sess = null;
if ((remoteFiles == null) || (localTargetDirectory == null))
throw new IllegalArgumentException("Null argument.");
if (remoteFiles.length == 0)
return;
// String cmd = "scp -f -r";
String cmd = "scp -f ";
for (int i = 0; i < remoteFiles.length; i++) {
if (remoteFiles[i] == null)
throw new IllegalArgumentException("Cannot accept null filename.");
cmd += (" " + remoteFiles[i]);
}
try {
sess = conn.openSession();
sess.execCommand(cmd);
receiveFiles(sess, remoteFiles, localTargetDirectory);
sess.close();
} catch (IOException e) {
if (sess != null)
sess.close();
throw (IOException) new IOException("Error during SCP transfer.").initCause(e);
}
}
use of ch.ethz.ssh2.Session in project jstorm by alibaba.
the class MyScpClient method put.
/**
* Create a remote file and copy the contents of the passed byte array into it.
* The method use the specified mode when creating the file on the remote side.
*
* @param data the data to be copied into the remote file.
* @param remoteFileName The name of the file which will be created in the remote target directory.
* @param remoteTargetDirectory Remote target directory.
* @param mode a four digit string (e.g., 0644, see "man chmod", "man open")
* @throws IOException
*/
public void put(byte[] data, String remoteFileName, String remoteTargetDirectory, String mode) throws IOException {
Session sess = null;
if ((remoteFileName == null) || (remoteTargetDirectory == null) || (mode == null))
throw new IllegalArgumentException("Null argument.");
if (mode.length() != 4)
throw new IllegalArgumentException("Invalid mode.");
for (int i = 0; i < mode.length(); i++) if (Character.isDigit(mode.charAt(i)) == false)
throw new IllegalArgumentException("Invalid mode.");
String cmd = "scp -t -d " + remoteTargetDirectory;
try {
sess = conn.openSession();
sess.execCommand(cmd);
sendBytes(sess, data, remoteFileName, mode);
sess.close();
} catch (IOException e) {
if (sess != null)
sess.close();
throw (IOException) new IOException("Error during SCP transfer.").initCause(e);
}
}
use of ch.ethz.ssh2.Session in project jstorm by alibaba.
the class MyScpClient method put.
/**
* Copy a set of local files to a remote directory, uses the specified mode
* when creating the files on the remote side.
*
* @param localFiles Paths and names of the local files.
* @param remoteTargetDirectory Remote target directory.
* @param mode a four digit string (e.g., 0644, see "man chmod", "man open")
* @throws IOException
*/
public void put(String[] localFiles, String remoteTargetDirectory, String mode) throws IOException {
Session sess = null;
if ((localFiles == null) || (remoteTargetDirectory == null) || (mode == null))
throw new IllegalArgumentException("Null argument.");
if (mode.length() != 4)
throw new IllegalArgumentException("Invalid mode.");
for (int i = 0; i < mode.length(); i++) if (Character.isDigit(mode.charAt(i)) == false)
throw new IllegalArgumentException("Invalid mode.");
if (localFiles.length == 0)
return;
String cmd = "scp -t -d " + remoteTargetDirectory;
for (int i = 0; i < localFiles.length; i++) {
if (localFiles[i] == null)
throw new IllegalArgumentException("Cannot accept null filename.");
}
try {
sess = conn.openSession();
sess.execCommand(cmd);
sendFiles(sess, localFiles, mode);
sess.close();
} catch (IOException e) {
if (sess != null)
sess.close();
throw (IOException) new IOException("Error during SCP transfer.").initCause(e);
}
}
Aggregations