use of org.neo4j.bolt.v1.transport.socket.client.TransportConnection in project neo4j by neo4j.
the class ConcurrentAccessIT method newWorker.
private Callable<Void> newWorker(final int iterationsToRun) throws Exception {
return new Callable<Void>() {
private final byte[] init = chunk(InitMessage.init("TestClient", emptyMap()));
private final byte[] createAndRollback = chunk(run("BEGIN"), pullAll(), run("CREATE (n)"), pullAll(), run("ROLLBACK"), pullAll());
private final byte[] matchAll = chunk(run("MATCH (n) RETURN n"), pullAll());
@Override
public Void call() throws Exception {
// Connect
TransportConnection client = cf.newInstance();
client.connect(address).send(acceptedVersions(1, 0, 0, 0));
assertThat(client, eventuallyReceives(new byte[] { 0, 0, 0, 1 }));
init(client);
for (int i = 0; i < iterationsToRun; i++) {
createAndRollback(client);
}
return null;
}
private void init(TransportConnection client) throws Exception {
client.send(init);
assertThat(client, eventuallyReceives(msgSuccess()));
}
private void createAndRollback(TransportConnection client) throws Exception {
client.send(createAndRollback);
assertThat(client, eventuallyReceives(msgSuccess(allOf(hasEntry(is("fields"), equalTo(emptyList())), hasKey("result_available_after"))), msgSuccess(), msgSuccess(allOf(hasEntry(is("fields"), equalTo(emptyList())), hasKey("result_available_after"))), msgSuccess(), msgSuccess(allOf(hasEntry(is("fields"), equalTo(emptyList())), hasKey("result_available_after"))), msgSuccess()));
// Verify no visible data
client.send(matchAll);
assertThat(client, eventuallyReceives(msgSuccess(allOf(hasEntry(is("fields"), equalTo(singletonList("n"))), hasKey("result_available_after"))), msgSuccess()));
}
};
}
use of org.neo4j.bolt.v1.transport.socket.client.TransportConnection in project neo4j by neo4j.
the class BoltConnectionManagementIT method shouldTerminateOwnConnectionsIfNonAdmin.
//@Test
public void shouldTerminateOwnConnectionsIfNonAdmin() throws Throwable {
// Given
TransportConnection user2 = cf.newInstance();
authenticate(user, "Igor", "123", null);
authenticate(user2, "Igor", "123", null);
assertTerminateOwnConnections(user, user2, "Igor");
}
use of org.neo4j.bolt.v1.transport.socket.client.TransportConnection in project neo4j by neo4j.
the class ProcedureInteractionTestBase method startBoltSession.
@SuppressWarnings("unchecked")
TransportConnection startBoltSession(String username, String password) throws Exception {
TransportConnection connection = new SocketConnection();
HostnamePort address = new HostnamePort("localhost:7687");
Map<String, Object> authToken = map("principal", username, "credentials", password, "scheme", "basic");
connection.connect(address).send(TransportTestUtil.acceptedVersions(1, 0, 0, 0)).send(TransportTestUtil.chunk(init("TestClient/1.1", authToken)));
assertThat(connection, eventuallyReceives(new byte[] { 0, 0, 0, 1 }));
assertThat(connection, eventuallyReceives(msgSuccess()));
return connection;
}
use of org.neo4j.bolt.v1.transport.socket.client.TransportConnection in project neo4j by neo4j.
the class BoltInteraction method collectResults.
private static BoltResult collectResults(TransportConnection client) throws Exception {
ResponseMessage message = TransportTestUtil.receiveOneResponseMessage(client);
List<String> fieldNames = new ArrayList<>();
List<Map<String, Object>> result = new ArrayList<>();
if (message instanceof SuccessMessage) {
Map<String, Object> metadata = ((SuccessMessage) message).meta();
fieldNames = (List<String>) metadata.get("fields");
} else if (message instanceof FailureMessage) {
FailureMessage failMessage = (FailureMessage) message;
// drain ignoredMessage, ack failure, get successMessage
TransportTestUtil.receiveOneResponseMessage(client);
client.send(TransportTestUtil.chunk(reset()));
TransportTestUtil.receiveOneResponseMessage(client);
throw new AuthenticationException(failMessage.status(), failMessage.message());
}
do {
message = TransportTestUtil.receiveOneResponseMessage(client);
if (message instanceof RecordMessage) {
Object[] row = ((RecordMessage) message).record().fields();
Map<String, Object> rowMap = new HashMap<>();
for (int i = 0; i < row.length; i++) {
rowMap.put(fieldNames.get(i), row[i]);
}
result.add(rowMap);
}
} while (!(message instanceof SuccessMessage) && !(message instanceof FailureMessage));
if (message instanceof FailureMessage) {
FailureMessage failMessage = (FailureMessage) message;
// ack failure, get successMessage
client.send(TransportTestUtil.chunk(reset()));
TransportTestUtil.receiveOneResponseMessage(client);
throw new AuthenticationException(failMessage.status(), failMessage.message());
}
return new BoltResult(result);
}
use of org.neo4j.bolt.v1.transport.socket.client.TransportConnection in project neo4j by neo4j.
the class AuthProceduresInteractionTestBase method shouldTerminateConnectionsOnUserDeletion.
@Test
public void shouldTerminateConnectionsOnUserDeletion() throws Exception {
TransportConnection conn = startBoltSession("writeSubject", "abc");
Map<String, Long> boltConnections = countBoltConnectionsByUsername();
assertThat(boltConnections.get("writeSubject"), equalTo(IS_BOLT ? 2L : 1L));
assertEmpty(adminSubject, "CALL dbms.security.deleteUser( 'writeSubject' )");
boltConnections = countBoltConnectionsByUsername();
assertThat(boltConnections.get("writeSubject"), equalTo(null));
conn.disconnect();
}
Aggregations