Search in sources :

Example 11 with BoltConnection

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);
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) MessageDecoder(org.neo4j.bolt.transport.pipeline.MessageDecoder) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) Log(org.neo4j.logging.Log) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BoltRequestMessageReaderV3(org.neo4j.bolt.v3.messaging.BoltRequestMessageReaderV3) NullLogService(org.neo4j.logging.internal.NullLogService) LogService(org.neo4j.logging.internal.LogService) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with BoltConnection

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) Test(org.junit.jupiter.api.Test)

Example 13 with BoltConnection

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) Test(org.junit.jupiter.api.Test)

Example 14 with BoltConnection

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

Example 15 with BoltConnection

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();
}
Also used : BoltConnection(org.neo4j.bolt.runtime.BoltConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test)

Aggregations

BoltConnection (org.neo4j.bolt.runtime.BoltConnection)31 Test (org.junit.jupiter.api.Test)24 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 InetSocketAddress (java.net.InetSocketAddress)3 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)3 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)3 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)3 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)3 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)3 Bootstrap (io.netty.bootstrap.Bootstrap)2 Channel (io.netty.channel.Channel)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelInboundHandler (io.netty.channel.ChannelInboundHandler)2 SocketChannel (io.netty.channel.socket.SocketChannel)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 ServerSocket (java.net.ServerSocket)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2