use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class MessageDecoderTest method shouldLogContentOfTheMessageOnIOError.
@ParameterizedTest
@MethodSource("argumentsProvider")
public void shouldLogContentOfTheMessageOnIOError(Neo4jPack packerUnderTest) throws Exception {
this.packerUnderTest = packerUnderTest;
BoltConnection connection = mock(BoltConnection.class);
BoltResponseMessageWriter responseMessageHandler = mock(BoltResponseMessageWriter.class);
BoltRequestMessageReader requestMessageReader = new BoltRequestMessageReaderV3(connection, responseMessageHandler, mock(ChannelProtector.class), NullLogService.getInstance());
LogService logService = mock(LogService.class);
Log log = mock(Log.class);
when(logService.getInternalLog(MessageDecoder.class)).thenReturn(log);
channel = new EmbeddedChannel(new MessageDecoder(packerUnderTest::newUnpacker, requestMessageReader, logService));
byte invalidMessageSignature = Byte.MAX_VALUE;
byte[] messageBytes = packMessageWithSignature(invalidMessageSignature);
assertThrows(BoltIOException.class, () -> channel.writeInbound(Unpooled.wrappedBuffer(messageBytes)));
assertMessageHexDumpLogged(log, messageBytes);
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class ExecutorBoltSchedulerWithQueueTest method shouldStartQueueingWorkIfThreadPoolIsOccupied.
@Test
void shouldStartQueueingWorkIfThreadPoolIsOccupied() throws Throwable {
AtomicInteger handleSchedulingErrorCounter = new AtomicInteger(0);
BoltConnection newConnection = newConnection(UUID.randomUUID().toString());
doAnswer(newCountingAnswer(handleSchedulingErrorCounter)).when(newConnection).handleSchedulingError(any());
submitWork(threadPoolSize);
// register connection
boltSchedulerWithQueue.created(newConnection);
// send a job which we expect to be queued
assertDoesNotThrow(() -> boltSchedulerWithQueue.enqueued(newConnection, Jobs.noop()));
// verify that handleSchedulingError is not called
assertEquals(0, 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 ExecutorBoltSchedulerWithQueueTest method shouldInvokeHandleSchedulingErrorIfNoThreadsAvailableAndFullQueue.
@Test
void shouldInvokeHandleSchedulingErrorIfNoThreadsAvailableAndFullQueue() throws Throwable {
AtomicInteger handleSchedulingErrorCounter = new AtomicInteger(0);
BoltConnection newConnection = newConnection(UUID.randomUUID().toString());
doAnswer(newCountingAnswer(handleSchedulingErrorCounter)).when(newConnection).handleSchedulingError(any());
submitWork(threadPoolSize + queueSize);
// register connection
boltSchedulerWithQueue.created(newConnection);
// send a job and wait for it to enter handleSchedulingError and block there
CompletableFuture.runAsync(() -> boltSchedulerWithQueue.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 ExecutorBoltSchedulerWithQueueTest method submitWork.
private void submitWork(int noOfWorkItemsToSubmit) throws InterruptedException {
for (int i = 0; i < noOfWorkItemsToSubmit; i++) {
BoltConnection connection = newConnection(UUID.randomUUID().toString());
boltSchedulerWithQueue.created(connection);
boltSchedulerWithQueue.enqueued(connection, Jobs.noop());
}
beforeExecuteEvent.countDown();
beforeExecuteBarrier.await();
}
use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.
the class HouseKeeperTest method shouldStopConnectionOnExceptionCaught.
@Test
void shouldStopConnectionOnExceptionCaught() {
BoltConnection connection = mock(BoltConnection.class);
channel = new EmbeddedChannel(new HouseKeeper(connection, NullLog.getInstance()));
channel.pipeline().fireExceptionCaught(new RuntimeException("some exception"));
verify(connection).stop();
}
Aggregations