Search in sources :

Example 1 with TransportConnection

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()));
        }
    };
}
Also used : TransportConnection(org.neo4j.bolt.v1.transport.socket.client.TransportConnection) Callable(java.util.concurrent.Callable)

Example 2 with TransportConnection

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");
}
Also used : TransportConnection(org.neo4j.bolt.v1.transport.socket.client.TransportConnection)

Example 3 with TransportConnection

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;
}
Also used : TransportConnection(org.neo4j.bolt.v1.transport.socket.client.TransportConnection) SocketConnection(org.neo4j.bolt.v1.transport.socket.client.SocketConnection) HostnamePort(org.neo4j.helpers.HostnamePort) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 4 with TransportConnection

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);
}
Also used : AuthenticationException(org.neo4j.bolt.security.auth.AuthenticationException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResponseMessage(org.neo4j.bolt.v1.messaging.message.ResponseMessage) SuccessMessage(org.neo4j.bolt.v1.messaging.message.SuccessMessage) FailureMessage(org.neo4j.bolt.v1.messaging.message.FailureMessage) RecordMessage(org.neo4j.bolt.v1.messaging.message.RecordMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with TransportConnection

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();
}
Also used : TransportConnection(org.neo4j.bolt.v1.transport.socket.client.TransportConnection) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

TransportConnection (org.neo4j.bolt.v1.transport.socket.client.TransportConnection)7 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2 ResponseMessage (org.neo4j.bolt.v1.messaging.message.ResponseMessage)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Description (org.hamcrest.Description)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1 AuthenticationException (org.neo4j.bolt.security.auth.AuthenticationException)1 FailureMessage (org.neo4j.bolt.v1.messaging.message.FailureMessage)1 RecordMessage (org.neo4j.bolt.v1.messaging.message.RecordMessage)1 SuccessMessage (org.neo4j.bolt.v1.messaging.message.SuccessMessage)1 SocketConnection (org.neo4j.bolt.v1.transport.socket.client.SocketConnection)1 HostnamePort (org.neo4j.helpers.HostnamePort)1