use of iaik.pkcs.pkcs11.Session in project rdf2neo by Rothamsted.
the class Neo4jDataManager method runCypher.
/**
* <p>Runs a Cypher gommands against the current {@link #getNeo4jDriver()}.</p>
*
* <p>The keyVals parameter is passed to {@link Values#parameters(Object...)}.</p>
*
* <p>The command is wrapped into a single transaction, which is committed within the method.</p>
*
* <p>Because parallelism sometimes raises exceptions about race conditions, we use {@link MultipleAttemptsExecutor}
* to re-attempt the command execution a couple of times, after such exceptions.</p>
*/
public void runCypher(String cypher, Object... keyVals) {
if (log.isTraceEnabled())
log.trace("Cypher: {} params: {}", cypher, ArrayUtils.toString(keyVals));
// Re-attempt a couple of times, in case of exceptions due to deadlocks over locking nodes.
MultipleAttemptsExecutor attempter = new MultipleAttemptsExecutor(TransientException.class, DatabaseException.class, ServiceUnavailableException.class);
attempter.setMaxAttempts(10);
attempter.setMinPauseTime(30 * 1000);
attempter.setMaxPauseTime(3 * 60 * 1000);
attempter.execute(() -> {
try (Session session = this.neo4jDriver.session()) {
session.run(cypher, parameters(keyVals));
}
});
}
use of iaik.pkcs.pkcs11.Session in project rdf2neo by Rothamsted.
the class CypherHandlersIT method testNodes.
/**
* Test {@link CyNodeLoadingHandler} to see if nodes are mapped from RDF and loaded into Neo4J
*/
@Test
public void testNodes() throws Exception {
try (Driver neoDriver = GraphDatabase.driver("bolt://127.0.0.1:7687", AuthTokens.basic("neo4j", "test"))) {
Session session = neoDriver.session(AccessMode.READ);
StatementResult cursor = session.run("MATCH ( n:TestNode ) RETURN COUNT ( n ) AS ct");
Assert.assertEquals("Wrong count for TestNode", 2, cursor.next().get("ct").asLong());
cursor = session.run("MATCH ( n:TestNode { iri:'" + iri("ex:2") + "'} ) RETURN properties ( n ) AS props");
assertTrue("ex:2 not returned!", cursor.hasNext());
Map<String, Object> map = cursor.next().get("props").asMap();
assertEquals("Wrong property!", "another string", map.get("attrib3"));
}
}
use of iaik.pkcs.pkcs11.Session in project cypher-for-gremlin by opencypher.
the class GremlinNeo4jDriverTest method returnPath.
@Test
public void returnPath() {
Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
try (Session session = driver.session()) {
StatementResult setup = session.run("CREATE (n1:Person {name: 'Anders'})-[r:knows]->(n2:Person)" + "RETURN n1,r,n2");
Record createdNodes = setup.single();
Node n1 = createdNodes.get("n1").asNode();
Node n2 = createdNodes.get("n2").asNode();
Relationship r = createdNodes.get("r").asRelationship();
StatementResult result = session.run("MATCH p =(b1 { name: 'Anders' })-->()" + "RETURN p");
Path path = result.single().get("p").asPath();
assertThat(path.contains(n1)).isTrue();
assertThat(path.contains(n2)).isTrue();
assertThat(path.contains(r)).isTrue();
assertThat(path.relationships()).hasSize(1);
assertThat(path.nodes()).hasSize(2);
}
}
use of iaik.pkcs.pkcs11.Session in project nimbus by nimbus-org.
the class SCPClientImpl method mget.
public File[] mget(String remote, String localDir) throws SCPException {
if (remote == null || remote.length() == 0) {
throw new SCPException("Path is null.");
}
if (localDir == null) {
localDir = ".";
}
File localDirFile = new File(localDir);
if (homeDir != null && !localDirFile.isAbsolute()) {
localDirFile = new File(homeDir, localDir);
}
List localFiles = new ArrayList();
Session session = null;
final String cmd = "scp -f " + remote;
File localFile = null;
try {
session = connection.openSession();
session.execCommand(cmd);
byte[] buf = new byte[1024];
OutputStream os = new BufferedOutputStream(session.getStdin(), 512);
InputStream is = new BufferedInputStream(session.getStdout(), 40000);
os.write(0);
os.flush();
while (true) {
int c = checkAck(is);
if (c == -1) {
if (localFiles.size() == 0) {
throw new IOException("Remote SCP terminated unexpectedly.");
}
break;
}
if (c != 'C') {
break;
}
is.read(buf, 0, 5);
long fileSize = 0L;
while (true) {
if (is.read(buf, 0, 1) < 0) {
throw new SCPException("Unexpected EOF.");
}
if (buf[0] == ' ') {
break;
}
fileSize = fileSize * 10L + (long) (buf[0] - '0');
}
String fileName = null;
for (int i = 0; ; i++) {
is.read(buf, i, 1);
if (buf[i] == (byte) 0x0a) {
fileName = new String(buf, 0, i);
break;
}
}
buf[0] = 0;
os.write(buf, 0, 1);
os.flush();
localFile = new File(localDirFile, fileName);
localFiles.add(localFile);
FileOutputStream fos = new FileOutputStream(localFile);
try {
int readLen = 0;
while (true) {
if (buf.length < fileSize) {
readLen = buf.length;
} else {
readLen = (int) fileSize;
}
readLen = is.read(buf, 0, readLen);
if (readLen < 0) {
throw new SCPException("Unexpected EOF.");
}
fos.write(buf, 0, readLen);
fileSize -= readLen;
if (fileSize == 0L) {
break;
}
}
} finally {
fos.close();
fos = null;
}
checkAck(is);
localFile = null;
buf[0] = 0;
os.write(buf, 0, 1);
os.flush();
}
} catch (IOException e) {
throw new SCPException("It failed to mget! from=" + remote + ", to=" + (localFile == null ? localDirFile : localFile), e);
} finally {
if (session != null) {
session.close();
}
}
return (File[]) localFiles.toArray(new File[localFiles.size()]);
}
use of iaik.pkcs.pkcs11.Session in project cosmic by MissionCriticalCloud.
the class SshHelperTest method canEndTheSshConnectionTest.
@Test
public void canEndTheSshConnectionTest() throws Exception {
PowerMockito.spy(SshHelper.class);
final Session mockedSession = Mockito.mock(Session.class);
PowerMockito.doReturn(true).when(SshHelper.class, "isChannelConditionEof", Mockito.anyInt());
Mockito.when(mockedSession.waitForCondition(ChannelCondition.EXIT_STATUS, 1l)).thenReturn(0);
PowerMockito.doNothing().when(SshHelper.class, "throwSshExceptionIfConditionsTimeout", Mockito.anyInt());
SshHelper.canEndTheSshConnection(1, mockedSession, 0);
PowerMockito.verifyStatic();
SshHelper.isChannelConditionEof(Mockito.anyInt());
SshHelper.throwSshExceptionIfConditionsTimeout(Mockito.anyInt());
Mockito.verify(mockedSession).waitForCondition(ChannelCondition.EXIT_STATUS, 1l);
}
Aggregations