Search in sources :

Example 11 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 12 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 13 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)

Example 14 with BoltResponseRecorder

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

the class BoltStateMachineTest method testPublishingError.

@Test
public void testPublishingError() throws Throwable {
    // Given a new ready machine...
    BoltStateMachine machine = newMachine(READY);
    // ...and a result ready to be retrieved...
    machine.run("RETURN 1", null, nullResponseHandler());
    // ...and a handler guaranteed to break
    BoltResponseRecorder recorder = new BoltResponseRecorder() {

        @Override
        public void onRecords(BoltResult result, boolean pull) throws Exception {
            throw new RuntimeException("I've been expecting you, Mr Bond.");
        }
    };
    // When we pull using that handler
    machine.pullAll(recorder);
    // Then the breakage should surface as a FAILURE
    assertThat(recorder.nextResponse(), failedWithStatus(Status.General.UnknownError));
    // ...and the machine should have entered a FAILED state
    assertThat(machine, inState(FAILED));
}
Also used : BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) BoltResult(org.neo4j.bolt.v1.runtime.spi.BoltResult) Test(org.junit.Test)

Example 15 with BoltResponseRecorder

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

the class BoltConnectionAuthIT method shouldGiveKernelVersionOnInit.

@Test
public void shouldGiveKernelVersionOnInit() throws Throwable {
    // Given it is important for client applications to programmatically
    // identify expired credentials as the cause of not being authenticated
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    String version = "Neo4j/" + Version.getNeo4jVersion();
    // When
    machine.init(USER_AGENT, map("scheme", "basic", "principal", "neo4j", "credentials", "neo4j"), recorder);
    machine.run("CREATE ()", map(), recorder);
    // Then
    assertThat(recorder.nextResponse(), succeededWithMetadata("server", version));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) 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