use of org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory in project neo4j by neo4j.
the class MonitoredBoltWorkerFactoryTest method shouldReportStartedSessions.
@Test
public void shouldReportStartedSessions() {
int workersCount = 42;
Monitors monitors = new Monitors();
CountingSessionMonitor monitor = new CountingSessionMonitor();
monitors.addMonitorListener(monitor);
WorkerFactory mockWorkers = mock(WorkerFactory.class);
when(mockWorkers.newWorker(anyObject(), any())).thenReturn(mock(BoltWorker.class));
MonitoredWorkerFactory workerFactory = new MonitoredWorkerFactory(monitors, mockWorkers, systemClock());
for (int i = 0; i < workersCount; i++) {
workerFactory.newWorker(CONNECTION_DESCRIPTOR);
}
assertEquals(workersCount, monitor.sessionsStarted);
}
use of org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory 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.MonitoredWorkerFactory 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);
}
Aggregations