use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.
the class BoltConnectionIT method shouldCloseConnectionOnDiscardAllBeforeInit.
@Test
public void shouldCloseConnectionOnDiscardAllBeforeInit() throws Throwable {
// Given
BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
// when
BoltResponseRecorder recorder = new BoltResponseRecorder();
verifyKillsConnection(() -> machine.discardAll(recorder));
// then
assertThat(recorder.nextResponse(), failedWithStatus(Status.Request.Invalid));
}
use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.
the class SocketTransportHandlerTest method shouldCloseProtocolOnChannelInactive.
@Test
public void shouldCloseProtocolOnChannelInactive() throws Throwable {
// Given
BoltStateMachine machine = mock(BoltStateMachine.class);
ChannelHandlerContext ctx = channelHandlerContextMock();
SocketTransportHandler handler = newSocketTransportHandler(protocolChooser(machine));
// And Given a session has been established
handler.channelRead(ctx, handshake());
// When
handler.channelInactive(ctx);
// Then
verify(machine).close();
}
use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.
the class SocketTransportHandlerTest method protocolChooser.
private ProtocolChooser protocolChooser(final BoltStateMachine machine) {
Map<Long, BiFunction<Channel, Boolean, BoltProtocol>> availableVersions = new HashMap<>();
availableVersions.put((long) BoltProtocolV1.VERSION, (channel, isSecure) -> new BoltProtocolV1(new SynchronousBoltWorker(machine), channel, NullLogService.getInstance()));
return new ProtocolChooser(availableVersions, false, true);
}
use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.
the class SessionRule method apply.
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
Map<Setting<?>, String> config = new HashMap<>();
config.put(GraphDatabaseSettings.auth_enabled, Boolean.toString(authEnabled));
gdb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase(config);
DependencyResolver resolver = gdb.getDependencyResolver();
Authentication authentication = authentication(resolver.resolveDependency(AuthManager.class), resolver.resolveDependency(UserManagerSupplier.class));
boltFactory = new BoltFactoryImpl(gdb, new UsageData(null), NullLogService.getInstance(), resolver.resolveDependency(ThreadToStatementContextBridge.class), authentication, BoltConnectionTracker.NOOP, Config.defaults());
boltFactory.start();
try {
base.evaluate();
} finally {
try {
if (runningMachines != null) {
runningMachines.forEach(BoltStateMachine::close);
}
} catch (Throwable e) {
e.printStackTrace();
}
gdb.shutdown();
}
}
};
}
use of org.neo4j.bolt.v1.runtime.BoltStateMachine 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();
}
Aggregations