Search in sources :

Example 6 with WorkerFactory

use of org.neo4j.bolt.v1.runtime.WorkerFactory in project neo4j by neo4j.

the class MonitoredBoltWorkerFactoryTest method shouldSignalReceivedStartAndComplete.

@Test
public void shouldSignalReceivedStartAndComplete() throws Throwable {
    // given
    FakeClock clock = Clocks.fakeClock();
    WorkerFactory delegate = mock(WorkerFactory.class);
    BoltStateMachine machine = mock(BoltStateMachine.class);
    when(delegate.newWorker(anyObject(), anyObject())).thenReturn(new BoltWorker() {

        @Override
        public void enqueue(Job job) {
            clock.forward(1337, TimeUnit.MILLISECONDS);
            try {
                job.perform(machine);
            } catch (BoltConnectionFatality connectionFatality) {
                throw new RuntimeException(connectionFatality);
            }
        }

        @Override
        public void interrupt() {
            throw new RuntimeException();
        }

        @Override
        public void halt() {
            throw new RuntimeException();
        }
    });
    Monitors monitors = new Monitors();
    CountingSessionMonitor monitor = new CountingSessionMonitor();
    monitors.addMonitorListener(monitor);
    MonitoredWorkerFactory workerFactory = new MonitoredWorkerFactory(monitors, delegate, clock);
    BoltWorker worker = workerFactory.newWorker(CONNECTION_DESCRIPTOR);
    // when
    worker.enqueue((stateMachine) -> {
        stateMachine.run("hello", null, nullResponseHandler());
        clock.forward(1338, TimeUnit.MILLISECONDS);
    });
    // then
    assertEquals(1, monitor.messagesReceived);
    assertEquals(1337, monitor.queueTime);
    assertEquals(1338, monitor.processingTime);
}
Also used : FakeClock(org.neo4j.time.FakeClock) MonitoredBoltWorker(org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker) Monitors(org.neo4j.kernel.monitoring.Monitors) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Monitors (org.neo4j.kernel.monitoring.Monitors)4 MonitoredBoltWorker (org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker)3 HashMap (java.util.HashMap)2 BiFunction (java.util.function.BiFunction)2 BoltConnectionDescriptor (org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor)2 BoltWorker (org.neo4j.bolt.v1.runtime.BoltWorker)2 WorkerFactory (org.neo4j.bolt.v1.runtime.WorkerFactory)2 BoltProtocolV1 (org.neo4j.bolt.v1.transport.BoltProtocolV1)2 Channel (io.netty.channel.Channel)1 SslContext (io.netty.handler.ssl.SslContext)1 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)1 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)1 File (java.io.File)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Clock (java.time.Clock)1 List (java.util.List)1 Map (java.util.Map)1