Search in sources :

Example 1 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class TransactionIT method shouldReadYourOwnWrites.

@Test
public void shouldReadYourOwnWrites() throws Exception {
    try (Transaction tx = env.graph().beginTx()) {
        Node node = env.graph().createNode(Label.label("A"));
        node.setProperty("prop", "one");
        tx.success();
    }
    BinaryLatch latch = new BinaryLatch();
    long dbVersion = env.lastClosedTxId();
    Thread thread = new Thread() {

        @Override
        public void run() {
            try (BoltStateMachine machine = env.newMachine(new BoltConnectionDescriptor(new InetSocketAddress("<testClient>", 56789), new InetSocketAddress("<writeServer>", 7468)))) {
                machine.init(USER_AGENT, emptyMap(), null);
                latch.await();
                machine.run("MATCH (n:A) SET n.prop = 'two'", emptyMap(), nullResponseHandler());
                machine.pullAll(nullResponseHandler());
            } catch (BoltConnectionFatality connectionFatality) {
                throw new RuntimeException(connectionFatality);
            }
        }
    };
    thread.start();
    long dbVersionAfterWrite = dbVersion + 1;
    try (BoltStateMachine machine = env.newMachine(new BoltConnectionDescriptor(new InetSocketAddress("<testClient>", 56789), new InetSocketAddress("<readServer>", 7468)))) {
        BoltResponseRecorder recorder = new BoltResponseRecorder();
        machine.init(USER_AGENT, emptyMap(), null);
        latch.release();
        final String bookmark = "neo4j:bookmark:v1:tx" + Long.toString(dbVersionAfterWrite);
        machine.run("BEGIN", singletonMap("bookmark", bookmark), nullResponseHandler());
        machine.pullAll(recorder);
        machine.run("MATCH (n:A) RETURN n.prop", emptyMap(), nullResponseHandler());
        machine.pullAll(recorder);
        machine.run("COMMIT", emptyMap(), nullResponseHandler());
        machine.pullAll(recorder);
        assertThat(recorder.nextResponse(), succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
        assertThat(recorder.nextResponse(), succeededWithRecord("two"));
        assertThat(recorder.nextResponse(), succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
    }
    thread.join();
}
Also used : BoltConnectionDescriptor(org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor) Transaction(org.neo4j.graphdb.Transaction) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) InetSocketAddress(java.net.InetSocketAddress) Node(org.neo4j.graphdb.Node) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) BoltConnectionFatality(org.neo4j.bolt.v1.runtime.BoltConnectionFatality) BinaryLatch(org.neo4j.concurrent.BinaryLatch) Test(org.junit.Test)

Example 2 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class TransactionIT method shouldReceiveBookmarkOnCommitAndPullAll.

@Test
public void shouldReceiveBookmarkOnCommitAndPullAll() throws Throwable {
    // Given
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    // When
    machine.run("BEGIN", emptyMap(), recorder);
    machine.discardAll(recorder);
    machine.run("CREATE (a:Person)", emptyMap(), recorder);
    machine.discardAll(recorder);
    machine.run("COMMIT", emptyMap(), recorder);
    machine.pullAll(recorder);
    // Then
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 3 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class ResetFuzzTest method assertWorkerWorks.

private void assertWorkerWorks(BoltWorker worker) throws InterruptedException {
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    worker.enqueue(machine -> machine.reset(recorder));
    try {
        RecordedBoltResponse response = recorder.nextResponse();
        assertThat(SUCCESS, equalTo(response.message()));
        assertThat(machine.state(), equalTo(BoltStateMachine.State.READY));
        assertThat(liveTransactions.get(), equalTo(0L));
    } catch (AssertionError e) {
        throw new AssertionError(String.format("Expected session to return to good state after RESET, but " + "assertion failed: %s.%n" + "Seed: %s%n" + "Messages sent:%n" + "%s", e.getMessage(), seed, Iterables.toString(sent, "\n")), e);
    }
}
Also used : BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RecordedBoltResponse(org.neo4j.bolt.testing.RecordedBoltResponse)

Example 4 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class BoltStateMachineTest method testUsingResetToAcknowledgeError.

@Test
public void testUsingResetToAcknowledgeError() throws Throwable {
    // Given
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // Given a FAILED machine
    BoltStateMachine machine = newMachine(FAILED);
    // When I RESET...
    machine.reset(recorder);
    // ...successfully
    assertThat(recorder.nextResponse(), succeeded());
    // Then if I RUN a statement...
    machine.run("RETURN 1", EMPTY_PARAMS, recorder);
    // ...everything should be fine again
    assertThat(recorder.nextResponse(), succeeded());
}
Also used : BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 5 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class BoltStateMachineTest method multipleInterruptsShouldBeMatchedWithMultipleResets.

@Test
public void multipleInterruptsShouldBeMatchedWithMultipleResets() throws Throwable {
    // Given
    final BoltStateMachine machine = newMachine(READY);
    // When
    machine.interrupt();
    machine.interrupt();
    // ...and
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.run("RETURN 1", EMPTY_PARAMS, recorder);
    machine.reset(recorder);
    machine.run("RETURN 1", EMPTY_PARAMS, recorder);
    // Then
    assertThat(recorder.nextResponse(), wasIgnored());
    assertThat(recorder.nextResponse(), wasIgnored());
    assertThat(recorder.nextResponse(), wasIgnored());
    // But when
    recorder.reset();
    machine.reset(recorder);
    machine.run("RETURN 1", EMPTY_PARAMS, recorder);
    // Then
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
}
Also used : BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Aggregations

BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)36 Test (org.junit.Test)34 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)30 InetSocketAddress (java.net.InetSocketAddress)2 RecordedBoltResponse (org.neo4j.bolt.testing.RecordedBoltResponse)2 BoltConnectionDescriptor (org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor)2 HashMap (java.util.HashMap)1 BoltConnectionFatality (org.neo4j.bolt.v1.runtime.BoltConnectionFatality)1 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)1 BinaryLatch (org.neo4j.concurrent.BinaryLatch)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1