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();
}
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));
}
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);
}
}
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());
}
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());
}
Aggregations