Search in sources :

Example 1 with BoltWorker

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;
}
Also used : BoltConnectionDescriptor(org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor) HashMap(java.util.HashMap) BiFunction(java.util.function.BiFunction) BoltWorker(org.neo4j.bolt.v1.runtime.BoltWorker) BoltProtocolV1(org.neo4j.bolt.v1.transport.BoltProtocolV1)

Example 2 with BoltWorker

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;
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine)

Example 3 with BoltWorker

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));
}
Also used : MonitoredBoltWorker(org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker) Monitors(org.neo4j.kernel.monitoring.Monitors) MonitoredBoltWorker(org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker) Test(org.junit.Test)

Example 4 with BoltWorker

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);
    }
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) Record(org.neo4j.bolt.v1.runtime.spi.Record) BoltMessageRouter(org.neo4j.bolt.v1.messaging.BoltMessageRouter) IOException(java.io.IOException) Map(java.util.Map) Test(org.junit.Test)

Example 5 with 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();
}
Also used : Log(org.neo4j.logging.Log) BoltWorker(org.neo4j.bolt.v1.runtime.BoltWorker) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Map (java.util.Map)2 BoltWorker (org.neo4j.bolt.v1.runtime.BoltWorker)2 MonitoredBoltWorker (org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker)2 Monitors (org.neo4j.kernel.monitoring.Monitors)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 BiFunction (java.util.function.BiFunction)1 BoltMessageRouter (org.neo4j.bolt.v1.messaging.BoltMessageRouter)1 BoltConnectionDescriptor (org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor)1 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)1 Record (org.neo4j.bolt.v1.runtime.spi.Record)1 BoltProtocolV1 (org.neo4j.bolt.v1.transport.BoltProtocolV1)1 Status (org.neo4j.kernel.api.exceptions.Status)1 Log (org.neo4j.logging.Log)1 FakeClock (org.neo4j.time.FakeClock)1