Search in sources :

Example 26 with BoltConnection

use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.

the class ExecutorBoltSchedulerConcurrencyTest method newConnection.

private BoltConnection newConnection(String id) {
    BoltConnection result = mock(BoltConnection.class);
    when(result.id()).thenReturn(id);
    when(result.remoteAddress()).thenReturn(new InetSocketAddress("localhost", 32_000));
    return result;
}
Also used : BoltConnection(org.neo4j.bolt.runtime.BoltConnection) InetSocketAddress(java.net.InetSocketAddress)

Example 27 with BoltConnection

use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.

the class ExecutorBoltSchedulerTest method newConnection.

private static BoltConnection newConnection(String id) {
    BoltConnection result = mock(BoltConnection.class);
    when(result.id()).thenReturn(id);
    when(result.remoteAddress()).thenReturn(new InetSocketAddress("localhost", 32_000));
    return result;
}
Also used : BoltConnection(org.neo4j.bolt.runtime.BoltConnection) InetSocketAddress(java.net.InetSocketAddress)

Example 28 with BoltConnection

use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.

the class ExecutorBoltSchedulerTest method failingJobShouldLogAndStopConnection.

@Test
void failingJobShouldLogAndStopConnection() throws Throwable {
    AtomicBoolean stopped = new AtomicBoolean();
    String id = UUID.randomUUID().toString();
    BoltConnection connection = newConnection(id);
    var unexpectedError = new RuntimeException("some unexpected error");
    doThrow(unexpectedError).when(connection).processNextBatch();
    doAnswer(inv -> stopped.getAndSet(true)).when(connection).stop();
    boltScheduler.init();
    boltScheduler.start();
    boltScheduler.created(connection);
    boltScheduler.enqueued(connection, Jobs.noop());
    Predicates.await(stopped::get, 1, MINUTES);
    assertFalse(boltScheduler.isActive(connection));
    verify(connection).processNextBatch();
    verify(connection).stop();
    assertThat(logProvider).forClass(ExecutorBoltScheduler.class).forLevel(ERROR).assertExceptionForLogMessage("Unexpected error during job scheduling for session").hasCause(unexpectedError);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) Test(org.junit.jupiter.api.Test)

Example 29 with BoltConnection

use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.

the class ExecutorBoltSchedulerTest method enqueuedShouldScheduleJob.

@Test
void enqueuedShouldScheduleJob() throws Throwable {
    String id = UUID.randomUUID().toString();
    AtomicBoolean exitCondition = new AtomicBoolean();
    BoltConnection connection = newConnection(id);
    when(connection.processNextBatch()).thenAnswer(inv -> awaitExit(exitCondition));
    boltScheduler.init();
    boltScheduler.start();
    boltScheduler.created(connection);
    boltScheduler.enqueued(connection, Jobs.noop());
    Predicates.await(() -> boltScheduler.isActive(connection), 1, MINUTES);
    exitCondition.set(true);
    Predicates.await(() -> !boltScheduler.isActive(connection), 1, MINUTES);
    verify(connection).processNextBatch();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) Test(org.junit.jupiter.api.Test)

Example 30 with BoltConnection

use of org.neo4j.bolt.runtime.BoltConnection in project neo4j by neo4j.

the class ExecutorBoltSchedulerTest method destroyedShouldRemoveConnectionFromActiveConnections.

@Test
void destroyedShouldRemoveConnectionFromActiveConnections() throws Throwable {
    String id = UUID.randomUUID().toString();
    BoltConnection connection = newConnection(id);
    boltScheduler.init();
    boltScheduler.start();
    boltScheduler.created(connection);
    boltScheduler.closed(connection);
    assertFalse(boltScheduler.isRegistered(connection));
}
Also used : BoltConnection(org.neo4j.bolt.runtime.BoltConnection) 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