use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class ExecutorBoltSchedulerConcurrencyTest method shouldInvokeHandleSchedulingErrorIfNoThreadsAvailable.
@Test
void shouldInvokeHandleSchedulingErrorIfNoThreadsAvailable() throws Throwable {
AtomicInteger handleSchedulingErrorCounter = new AtomicInteger(0);
BoltConnection newConnection = newConnection(UUID.randomUUID().toString());
doAnswer(newCountingAnswer(handleSchedulingErrorCounter)).when(newConnection).handleSchedulingError(any());
blockAllThreads();
// register connection
boltScheduler.created(newConnection);
// send a job and wait for it to enter handleSchedulingError and block there
CompletableFuture.runAsync(() -> boltScheduler.enqueued(newConnection, Jobs.noop()));
Predicates.awaitForever(() -> handleSchedulingErrorCounter.get() > 0, 500, MILLISECONDS);
// verify that handleSchedulingError is called once
assertEquals(1, handleSchedulingErrorCounter.get());
// allow all threads to complete
afterExecuteEvent.countDown();
afterExecuteBarrier.await();
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class ExecutorBoltSchedulerConcurrencyTest method blockAllThreads.
private void blockAllThreads() throws InterruptedException {
for (int i = 0; i < maxPoolSize; i++) {
BoltConnection connection = newConnection(UUID.randomUUID().toString());
boltScheduler.created(connection);
boltScheduler.enqueued(connection, Jobs.noop());
}
beforeExecuteEvent.countDown();
beforeExecuteBarrier.await();
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class ExecutorBoltSchedulerConcurrencyTest method shouldNotScheduleNewJobIfHandlingSchedulingError.
@Test
void shouldNotScheduleNewJobIfHandlingSchedulingError() throws Throwable {
AtomicInteger handleSchedulingErrorCounter = new AtomicInteger(0);
AtomicBoolean exitCondition = new AtomicBoolean();
BoltConnection newConnection = newConnection(UUID.randomUUID().toString());
doAnswer(newBlockingAnswer(handleSchedulingErrorCounter, exitCondition)).when(newConnection).handleSchedulingError(any());
blockAllThreads();
// register connection
boltScheduler.created(newConnection);
// send a job and wait for it to enter handleSchedulingError and block there
CompletableFuture.runAsync(() -> boltScheduler.enqueued(newConnection, Jobs.noop()));
Predicates.awaitForever(() -> handleSchedulingErrorCounter.get() > 0, 500, MILLISECONDS);
// allow all threads to complete
afterExecuteEvent.countDown();
afterExecuteBarrier.await();
// post a job
boltScheduler.enqueued(newConnection, Jobs.noop());
// exit handleSchedulingError
exitCondition.set(true);
// verify that handleSchedulingError is called once and processNextBatch never.
assertEquals(1, handleSchedulingErrorCounter.get());
verify(newConnection, never()).processNextBatch();
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class BoltRequestMessageReaderTest method shouldHandleErrorThatCausesFailureMessage.
@Test
void shouldHandleErrorThatCausesFailureMessage() throws Exception {
Unpacker unpacker = mock(Unpacker.class);
BoltIOException error = new BoltIOException(Status.General.UnknownError, "Hello");
when(unpacker.unpackStructHeader()).thenThrow(error);
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
BoltConnection connection = new SynchronousBoltConnection(stateMachine);
BoltResponseHandler externalErrorResponseHandler = responseHandlerMock();
BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connection, externalErrorResponseHandler, emptyList(), mock(ChannelProtector.class));
reader.read(unpacker);
verify(stateMachine).handleExternalFailure(Neo4jError.from(error), externalErrorResponseHandler);
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class BoltRequestMessageReaderTest method shouldDecodeKnownMessage.
@Test
void shouldDecodeKnownMessage() throws Exception {
Unpacker unpacker = mock(Unpacker.class);
when(unpacker.unpackStructSignature()).thenReturn('a');
RequestMessage message = mock(RequestMessage.class);
BoltResponseHandler responseHandler = responseHandlerMock();
RequestMessageDecoder decoder = new TestRequestMessageDecoder('a', responseHandler, message);
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
BoltConnection connection = new SynchronousBoltConnection(stateMachine);
BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connection, responseHandlerMock(), singletonList(decoder), mock(ChannelProtector.class));
reader.read(unpacker);
verify(stateMachine).process(message, responseHandler);
}
Aggregations