Search in sources :

Example 6 with TransportConnection

use of org.neo4j.bolt.testing.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 = util.defaultAuth();

        private final byte[] createAndRollback = util.defaultRunExplicitCommitTxAndRollBack("CREATE (n)");

        private final byte[] matchAll = util.defaultRunAutoCommitTx("MATCH (n) RETURN n");

        @Override
        public Void call() throws Exception {
            // Connect
            TransportConnection client = newConnection();
            client.connect(server.lookupDefaultConnector()).send(util.defaultAcceptedVersions());
            assertThat(client).satisfies(util.eventuallyReceivesSelectedProtocolVersion());
            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).satisfies(util.eventuallyReceives(msgSuccess()));
        }

        private void createAndRollback(TransportConnection client) throws Exception {
            client.send(createAndRollback);
            assertThat(client).satisfies(util.eventuallyReceives(// begin
            msgSuccess(), msgSuccess(message -> assertThat(message).containsKeys("t_first", "qid").containsEntry("fields", // run
            emptyList())), // pull_all
            msgSuccess(message -> assertThat(message).containsKeys("t_last", "db")), // roll_back
            msgSuccess()));
            client.send(matchAll);
            assertThat(client).satisfies(util.eventuallyReceives(msgSuccess(message -> assertThat(message).containsKey("t_first").containsEntry("fields", // run
            singletonList("n"))), // pull_all
            msgSuccess(message -> assertThat(message).containsKeys("t_last", "db"))));
        }
    };
}
Also used : TransportConnection(org.neo4j.bolt.testing.client.TransportConnection) Callable(java.util.concurrent.Callable)

Aggregations

TransportConnection (org.neo4j.bolt.testing.client.TransportConnection)6 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 Condition (org.assertj.core.api.Condition)1 HamcrestCondition (org.assertj.core.api.HamcrestCondition)1 AfterEach (org.junit.jupiter.api.AfterEach)1