use of org.neo4j.bolt.v1.runtime.BoltWorker in project neo4j by neo4j.
the class BoltKernelExtension method newVersions.
private Map<Long, BiFunction<Channel, Boolean, BoltProtocol>> newVersions(LogService logging, WorkerFactory workerFactory) {
Map<Long, BiFunction<Channel, Boolean, BoltProtocol>> availableVersions = new HashMap<>();
availableVersions.put((long) BoltProtocolV1.VERSION, (channel, isEncrypted) -> {
BoltConnectionDescriptor descriptor = new BoltConnectionDescriptor(channel.remoteAddress(), channel.localAddress());
BoltWorker worker = workerFactory.newWorker(descriptor, channel::close);
return new BoltProtocolV1(worker, channel, logging);
});
return availableVersions;
}
use of org.neo4j.bolt.v1.runtime.BoltWorker in project neo4j by neo4j.
the class ThreadedWorkerFactory method newWorker.
@Override
public BoltWorker newWorker(BoltConnectionDescriptor connectionDescriptor, Runnable onClose) {
BoltStateMachine machine = connector.newMachine(connectionDescriptor, onClose, clock);
RunnableBoltWorker worker = new RunnableBoltWorker(machine, logging);
scheduler.schedule(sessionWorker, worker, stringMap(THREAD_ID, machine.key()));
return worker;
}
use of org.neo4j.bolt.v1.runtime.BoltWorker in project neo4j by neo4j.
the class MonitoredBoltWorkerFactoryTest method shouldNotWrapWithMonitoredSessionIfNobodyIsListening.
@Test
public void shouldNotWrapWithMonitoredSessionIfNobodyIsListening() throws Throwable {
// Given
// Monitoring adds GC overhead, so we only want to do the work involved
// if someone has actually registered a listener. We still allow plugging
// monitoring in at runtime, but it will only apply to sessions started
// after monitor listeners are added
WorkerFactory workerFactory = mock(WorkerFactory.class);
BoltWorker innerSession = mock(BoltWorker.class);
when(workerFactory.newWorker(anyObject(), anyObject())).thenReturn(innerSession);
Monitors monitors = new Monitors();
MonitoredWorkerFactory monitoredWorkerFactory = new MonitoredWorkerFactory(monitors, workerFactory, Clocks.fakeClock());
// When
BoltWorker worker = monitoredWorkerFactory.newWorker(CONNECTION_DESCRIPTOR);
// Then
assertEquals(innerSession, worker);
// But when I register a listener
monitors.addMonitorListener(new CountingSessionMonitor());
// Then new sessions should be monitored
assertThat(monitoredWorkerFactory.newWorker(CONNECTION_DESCRIPTOR), instanceOf(MonitoredBoltWorker.class));
}
use of org.neo4j.bolt.v1.runtime.BoltWorker in project neo4j by neo4j.
the class ResetFuzzTest method shouldAlwaysReturnToReadyAfterReset.
@Test
public void shouldAlwaysReturnToReadyAfterReset() throws Throwable {
// given
life.start();
BoltWorker boltWorker = sessions.newWorker(CONNECTION_DESCRIPTOR);
boltWorker.enqueue(session -> session.init("ResetFuzzTest/0.0", map(), nullResponseHandler()));
BoltMessageRouter router = new BoltMessageRouter(NullLog.getInstance(), boltWorker, new BoltResponseMessageHandler<IOException>() {
@Override
public void onRecord(Record item) throws IOException {
}
@Override
public void onIgnored() throws IOException {
}
@Override
public void onFailure(Status status, String message) throws IOException {
}
@Override
public void onSuccess(Map metadata) throws IOException {
}
}, () -> {
});
// Test random combinations of messages within a small budget of testing time.
long deadline = System.currentTimeMillis() + 2 * 1000;
// when
while (System.currentTimeMillis() < deadline) {
dispatchRandomSequenceOfMessages(router);
assertWorkerWorks(boltWorker);
}
}
use of org.neo4j.bolt.v1.runtime.BoltWorker in project neo4j by neo4j.
the class MessageProcessingHandlerTest method shouldCallHaltOnUnexpectedFailures.
@Test
public void shouldCallHaltOnUnexpectedFailures() throws Exception {
// Given
BoltResponseMessageHandler msgHandler = mock(BoltResponseMessageHandler.class);
doThrow(new RuntimeException("Something went horribly wrong")).when(msgHandler).onSuccess(any(Map.class));
BoltWorker worker = mock(BoltWorker.class);
MessageProcessingHandler handler = new MessageProcessingHandler(msgHandler, mock(Runnable.class), worker, mock(Log.class));
// When
handler.onFinish();
// Then
verify(worker).halt();
}
Aggregations