use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.
the class TransactionIT method shouldReadYourOwnWrites.
@Test
void shouldReadYourOwnWrites() throws Exception {
var latch = new BinaryLatch();
String bookmarkPrefix = null;
try (var machine = newStateMachineAfterAuth()) {
var recorder = new BoltResponseRecorder();
machine.process(run("CREATE (n:A {prop:'one'})"), nullResponseHandler());
machine.process(pullAll(), recorder);
var bookmark = ((TextValue) recorder.nextResponse().metadata("bookmark")).stringValue();
bookmarkPrefix = bookmark.split(":")[0];
}
var dbVersion = env.lastClosedTxId();
var thread = new Thread(() -> {
try (BoltStateMachine machine = newStateMachineAfterAuth()) {
latch.await();
var recorder = new BoltResponseRecorder();
machine.process(run("MATCH (n:A) SET n.prop = 'two'", EMPTY_MAP), nullResponseHandler());
machine.process(pullAll(), recorder);
} catch (Throwable connectionFatality) {
throw new RuntimeException(connectionFatality);
}
});
thread.start();
var dbVersionAfterWrite = dbVersion + 1;
try (var machine = newStateMachineAfterAuth()) {
var recorder = new BoltResponseRecorder();
latch.release();
var bookmark = bookmarkPrefix + ":" + dbVersionAfterWrite;
machine.process(begin(env.databaseIdRepository(), asMapValue(singletonMap("bookmarks", List.of(bookmark)))), recorder);
machine.process(run("MATCH (n:A) RETURN n.prop"), recorder);
machine.process(pullAll(), recorder);
machine.process(commit(), recorder);
assertThat(recorder.nextResponse()).satisfies(succeeded());
assertThat(recorder.nextResponse()).satisfies(succeeded());
assertThat(recorder.nextResponse()).satisfies(succeededWithRecord("two"));
assertThat(recorder.nextResponse()).satisfies(succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
}
thread.join();
}
Aggregations