Search in sources :

Example 1 with InitMessage.init

use of org.neo4j.bolt.v1.messaging.message.InitMessage.init 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 InitMessage.init

use of org.neo4j.bolt.v1.messaging.message.InitMessage.init in project neo4j by neo4j.

the class BoltMetricsIT method shouldMonitorBolt.

@Test
public void shouldMonitorBolt() throws Throwable {
    // Given
    File metricsFolder = tmpDir.newFolder("metrics");
    db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(new BoltConnector("bolt").type, "BOLT").setConfig(new BoltConnector("bolt").enabled, "true").setConfig(GraphDatabaseSettings.auth_enabled, "false").setConfig(MetricsSettings.boltMessagesEnabled, "true").setConfig(MetricsSettings.csvEnabled, "true").setConfig(MetricsSettings.csvInterval, "100ms").setConfig(MetricsSettings.csvPath, metricsFolder.getAbsolutePath()).newGraphDatabase();
    // When
    conn = new SocketConnection().connect(new HostnamePort("localhost", 7687)).send(acceptedVersions(1, 0, 0, 0)).send(chunk(InitMessage.init("TestClient", map("scheme", "basic", "principal", "neo4j", "credentials", "neo4j"))));
    // Then
    assertEventually("session shows up as started", () -> readLongValue(metricsCsv(metricsFolder, SESSIONS_STARTED)), equalTo(1L), 5, SECONDS);
    assertEventually("init request shows up as received", () -> readLongValue(metricsCsv(metricsFolder, MESSAGES_RECIEVED)), equalTo(1L), 5, SECONDS);
    assertEventually("init request shows up as started", () -> readLongValue(metricsCsv(metricsFolder, MESSAGES_STARTED)), equalTo(1L), 5, SECONDS);
    assertEventually("init request shows up as done", () -> readLongValue(metricsCsv(metricsFolder, MESSAGES_DONE)), equalTo(1L), 5, SECONDS);
    assertEventually("queue time shows up", () -> readLongValue(metricsCsv(metricsFolder, TOTAL_QUEUE_TIME)), greaterThanOrEqualTo(0L), 5, SECONDS);
    assertEventually("processing time shows up", () -> readLongValue(metricsCsv(metricsFolder, TOTAL_PROCESSING_TIME)), greaterThanOrEqualTo(0L), 5, SECONDS);
}
Also used : BoltConnector(org.neo4j.kernel.configuration.BoltConnector) SocketConnection(org.neo4j.bolt.v1.transport.socket.client.SocketConnection) HostnamePort(org.neo4j.helpers.HostnamePort) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Callable (java.util.concurrent.Callable)1 Test (org.junit.Test)1 SocketConnection (org.neo4j.bolt.v1.transport.socket.client.SocketConnection)1 TransportConnection (org.neo4j.bolt.v1.transport.socket.client.TransportConnection)1 HostnamePort (org.neo4j.helpers.HostnamePort)1 BoltConnector (org.neo4j.kernel.configuration.BoltConnector)1 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)1