use of iaik.pkcs.pkcs11.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 iaik.pkcs.pkcs11.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 iaik.pkcs.pkcs11.Session in project CloudStack-archive by CloudStack-extras.
the class StressTestDirectAttach method sshTest.
private static String sshTest(String host, String password) {
int i = 0;
if (host == null) {
s_logger.info("Did not receive a host back from test, ignoring ssh test");
return null;
}
if (password == null) {
s_logger.info("Did not receive a password back from test, ignoring ssh test");
return null;
}
// We will retry 5 times before quitting
String result = null;
int retry = 0;
while (true) {
try {
if (retry > 0) {
s_logger.info("Retry attempt : " + retry + " ...sleeping 120 seconds before next attempt. Account is " + _account.get());
Thread.sleep(120000);
}
s_logger.info("Attempting to SSH into linux host " + host + " with retry attempt: " + retry + ". Account is " + _account.get());
Connection conn = new Connection(host);
conn.connect(null, 60000, 60000);
s_logger.info("User + " + _account.get() + " ssHed successfully into linux host " + host);
boolean isAuthenticated = conn.authenticateWithPassword("root", password);
if (isAuthenticated == false) {
s_logger.info("Authentication failed for root with password" + password);
return "Authentication failed";
}
boolean success = false;
String linuxCommand = null;
if (i % 10 == 0)
linuxCommand = "rm -rf *; wget http://192.168.1.250/dump.bin && ls -al dump.bin";
else
linuxCommand = "wget http://192.168.1.250/dump.bin && ls -al dump.bin";
Session sess = conn.openSession();
s_logger.info("User " + _account.get() + " executing : " + linuxCommand);
sess.execCommand(linuxCommand);
InputStream stdout = sess.getStdout();
InputStream stderr = sess.getStderr();
byte[] buffer = new byte[8192];
while (true) {
if ((stdout.available() == 0) && (stderr.available() == 0)) {
int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
if ((conditions & ChannelCondition.TIMEOUT) != 0) {
s_logger.info("Timeout while waiting for data from peer.");
return null;
}
if ((conditions & ChannelCondition.EOF) != 0) {
if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
break;
}
}
}
while (stdout.available() > 0) {
success = true;
int len = stdout.read(buffer);
if (// this check is somewhat paranoid
len > 0)
s_logger.info(new String(buffer, 0, len));
}
while (stderr.available() > 0) {
/* int len = */
stderr.read(buffer);
}
}
sess.close();
conn.close();
if (!success) {
retry++;
if (retry == MAX_RETRY_LINUX) {
result = "SSH Linux Network test fail";
}
}
return result;
} catch (Exception e) {
retry++;
s_logger.error("SSH Linux Network test fail with error");
if (retry == MAX_RETRY_LINUX) {
return "SSH Linux Network test fail with error " + e.getMessage();
}
}
i++;
}
}
use of iaik.pkcs.pkcs11.Session in project CloudStack-archive by CloudStack-extras.
the class TestClient method sshTest.
private static String sshTest(String host) {
if (host == null) {
s_logger.info("Did not receive a host back from test, ignoring ssh test");
return null;
}
// We will retry 5 times before quitting
int retry = 0;
while (true) {
try {
if (retry > 0) {
s_logger.info("Retry attempt : " + retry + " ...sleeping 120 seconds before next attempt");
Thread.sleep(120000);
}
s_logger.info("Attempting to SSH into linux host " + host + " with retry attempt: " + retry);
Connection conn = new Connection(host);
conn.connect(null, 60000, 60000);
s_logger.info("SSHed successfully into linux host " + host);
boolean isAuthenticated = conn.authenticateWithPassword("root", "password");
if (isAuthenticated == false) {
return "Authentication failed";
}
boolean success = false;
Session sess = conn.openSession();
s_logger.info("Executing : wget http://172.16.0.220/dump.bin");
sess.execCommand("wget http://172.16.0.220/dump.bin && ls -al dump.bin");
InputStream stdout = sess.getStdout();
InputStream stderr = sess.getStderr();
byte[] buffer = new byte[8192];
while (true) {
if ((stdout.available() == 0) && (stderr.available() == 0)) {
int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
if ((conditions & ChannelCondition.TIMEOUT) != 0) {
s_logger.info("Timeout while waiting for data from peer.");
return null;
}
if ((conditions & ChannelCondition.EOF) != 0) {
if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
break;
}
}
}
while (stdout.available() > 0) {
success = true;
int len = stdout.read(buffer);
if (// this check is somewhat paranoid
len > 0)
s_logger.info(new String(buffer, 0, len));
}
while (stderr.available() > 0) {
int len = stderr.read(buffer);
}
}
sess.close();
conn.close();
if (success) {
return null;
} else {
retry++;
if (retry == MAX_RETRY_LINUX) {
return "SSH Linux Network test fail";
}
}
} catch (Exception e) {
retry++;
if (retry == MAX_RETRY_LINUX) {
return "SSH Linux Network test fail with error " + e.getMessage();
}
}
}
}
use of iaik.pkcs.pkcs11.Session in project CloudStack-archive by CloudStack-extras.
the class TestClient method sshWinTest.
private static String sshWinTest(String host) {
if (host == null) {
s_logger.info("Did not receive a host back from test, ignoring win ssh test");
return null;
}
// We will retry 5 times before quitting
int retry = 0;
while (true) {
try {
if (retry > 0) {
s_logger.info("Retry attempt : " + retry + " ...sleeping 300 seconds before next attempt");
Thread.sleep(300000);
}
s_logger.info("Attempting to SSH into windows host " + host + " with retry attempt: " + retry);
Connection conn = new Connection(host);
conn.connect(null, 60000, 60000);
s_logger.info("SSHed successfully into windows host " + host);
boolean success = false;
boolean isAuthenticated = conn.authenticateWithPassword("vmops", "vmops");
if (isAuthenticated == false) {
return "Authentication failed";
}
SCPClient scp = new SCPClient(conn);
scp.put("wget.exe", "");
Session sess = conn.openSession();
s_logger.info("Executing : wget http://172.16.0.220/dump.bin");
sess.execCommand("wget http://172.16.0.220/dump.bin && dir dump.bin");
InputStream stdout = sess.getStdout();
InputStream stderr = sess.getStderr();
byte[] buffer = new byte[8192];
while (true) {
if ((stdout.available() == 0) && (stderr.available() == 0)) {
int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
if ((conditions & ChannelCondition.TIMEOUT) != 0) {
s_logger.info("Timeout while waiting for data from peer.");
return null;
}
if ((conditions & ChannelCondition.EOF) != 0) {
if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
break;
}
}
}
while (stdout.available() > 0) {
success = true;
int len = stdout.read(buffer);
if (// this check is somewhat paranoid
len > 0)
s_logger.info(new String(buffer, 0, len));
}
while (stderr.available() > 0) {
int len = stderr.read(buffer);
}
}
sess.close();
conn.close();
if (success) {
return null;
} else {
retry++;
if (retry == MAX_RETRY_WIN) {
return "SSH Windows Network test fail";
}
}
} catch (Exception e) {
retry++;
if (retry == MAX_RETRY_WIN) {
return "SSH Windows Network test fail with error " + e.getMessage();
}
}
}
}
Aggregations