Search in sources :

Example 1 with BoltChannel

use of org.neo4j.bolt.BoltChannel in project neo4j by neo4j.

the class BoltV4MachineRoom method newMachineWithTransactionSPI.

public static BoltStateMachine newMachineWithTransactionSPI(TransactionStateMachineSPI transactionSPI) throws BoltConnectionFatality, BoltIOException {
    BoltStateMachineSPI spi = mock(BoltStateMachineSPI.class, RETURNS_MOCKS);
    TransactionStateMachineSPIProvider transactionSPIProvider = mock(TransactionStateMachineSPIProvider.class);
    var memoryTracker = mock(MemoryTracker.class);
    when(transactionSPIProvider.getTransactionStateMachineSPI(any(String.class), any(StatementProcessorReleaseManager.class))).thenReturn(transactionSPI);
    when(spi.transactionStateMachineSPIProvider()).thenReturn(transactionSPIProvider);
    BoltChannel boltChannel = BoltTestUtil.newTestBoltChannel();
    BoltStateMachine machine = new BoltStateMachineV4(spi, boltChannel, Clock.systemUTC(), mock(DefaultDatabaseResolver.class), MapValue.EMPTY, memoryTracker);
    init(machine);
    return machine;
}
Also used : StatementProcessorReleaseManager(org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltChannel(org.neo4j.bolt.BoltChannel) BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) DefaultDatabaseResolver(org.neo4j.kernel.database.DefaultDatabaseResolver) BoltStateMachineSPI(org.neo4j.bolt.runtime.statemachine.BoltStateMachineSPI) TransactionStateMachineSPIProvider(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider)

Example 2 with BoltChannel

use of org.neo4j.bolt.BoltChannel in project neo4j by neo4j.

the class BoltStateMachineV4Test method shouldCloseBoltChannelWhenClosed.

@Test
void shouldCloseBoltChannelWhenClosed() {
    BoltStateMachineSPIImpl spi = mock(BoltStateMachineSPIImpl.class);
    BoltChannel boltChannel = mock(BoltChannel.class);
    var memoryTracker = mock(MemoryTracker.class);
    BoltStateMachine machine = new BoltStateMachineV4(spi, boltChannel, Clock.systemUTC(), mock(DefaultDatabaseResolver.class), MapValue.EMPTY, memoryTracker);
    machine.close();
    verify(boltChannel).close();
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltChannel(org.neo4j.bolt.BoltChannel) BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) DefaultDatabaseResolver(org.neo4j.kernel.database.DefaultDatabaseResolver) Test(org.junit.jupiter.api.Test)

Example 3 with BoltChannel

use of org.neo4j.bolt.BoltChannel in project neo4j by neo4j.

the class AbstractBoltProtocolTest method shouldInstallChannelHandlersInCorrectOrder.

@Test
void shouldInstallChannelHandlersInCorrectOrder() throws Throwable {
    // Given
    BoltChannel boltChannel = newTestBoltChannel(channel);
    BoltConnectionFactory connectionFactory = mock(BoltConnectionFactory.class);
    var memoryTracker = mock(MemoryTracker.class);
    when(connectionFactory.newConnection(eq(boltChannel), any(), any())).thenReturn(mock(BoltConnection.class));
    BoltProtocol boltProtocol = new TestAbstractBoltProtocol(boltChannel, connectionFactory, mock(BoltStateMachineFactory.class), Config.defaults(), NullLogService.getInstance(), mock(TransportThrottleGroup.class), mock(ChannelProtector.class), memoryTracker);
    // When
    boltProtocol.install();
    Iterator<Map.Entry<String, ChannelHandler>> handlers = channel.pipeline().iterator();
    assertThat(handlers.next().getValue()).isInstanceOf(ChunkDecoder.class);
    assertThat(handlers.next().getValue()).isInstanceOf(MessageAccumulator.class);
    assertThat(handlers.next().getValue()).isInstanceOf(MessageDecoder.class);
    assertThat(handlers.next().getValue()).isInstanceOf(HouseKeeper.class);
    assertFalse(handlers.hasNext());
}
Also used : ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) BoltConnectionFactory(org.neo4j.bolt.runtime.BoltConnectionFactory) BoltProtocol(org.neo4j.bolt.BoltProtocol) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) BoltStateMachineFactory(org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory) BoltChannel(org.neo4j.bolt.BoltChannel) BoltTestUtil.newTestBoltChannel(org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel) Test(org.junit.jupiter.api.Test)

Example 4 with BoltChannel

use of org.neo4j.bolt.BoltChannel in project neo4j by neo4j.

the class ListConnectionResultTest method buildResultOnConnectionWithoutClientAddress.

@Test
void buildResultOnConnectionWithoutClientAddress() {
    Channel channel = mock(Channel.class, RETURNS_MOCKS);
    when(channel.remoteAddress()).thenReturn(null);
    BoltChannel boltChannel = new BoltChannel("id", BoltConnector.NAME, channel, ChannelProtector.NULL);
    var result = new ListConnectionResult(boltChannel, ZoneId.systemDefault());
    assertEquals(StringUtils.EMPTY, result.clientAddress);
}
Also used : Channel(io.netty.channel.Channel) BoltChannel(org.neo4j.bolt.BoltChannel) BoltChannel(org.neo4j.bolt.BoltChannel) Test(org.junit.jupiter.api.Test)

Example 5 with BoltChannel

use of org.neo4j.bolt.BoltChannel in project neo4j by neo4j.

the class FragmentedMessageDeliveryTest method testPermutation.

private void testPermutation(byte[] unfragmented, ByteBuf[] fragments) throws Exception {
    // Given
    channel = new EmbeddedChannel();
    BoltChannel boltChannel = newTestBoltChannel(channel);
    BoltStateMachine machine = mock(BoltStateMachine.class);
    SynchronousBoltConnection boltConnection = new SynchronousBoltConnection(machine);
    NullLogService logging = NullLogService.getInstance();
    var bookmarksParser = mock(BookmarksParser.class);
    var memoryTracker = mock(MemoryTracker.class);
    BoltProtocol boltProtocol = new BoltProtocolV4(boltChannel, (ch, s, messageWriter) -> boltConnection, (v, ch, hints, mem) -> machine, Config.defaults(), bookmarksParser, logging, mock(TransportThrottleGroup.class), mock(ChannelProtector.class), memoryTracker);
    boltProtocol.install();
    // When data arrives split up according to the current permutation
    for (ByteBuf fragment : fragments) {
        channel.writeInbound(fragment.readerIndex(0).retain());
    }
    // Then the session should've received the specified messages, and the protocol should be in a nice clean state
    try {
        RequestMessage run = new RunMessage("Mjölnir", EMPTY_MAP);
        verify(machine).process(eq(run), any(BoltResponseHandler.class));
    } catch (AssertionError e) {
        throw new AssertionError("Failed to handle fragmented delivery.\n" + "Messages: " + Arrays.toString(messages) + "\n" + "Chunk size: " + chunkSize + "\n" + "Serialized data delivered in fragments: " + describeFragments(fragments) + "\n" + "Unfragmented data: " + HexPrinter.hex(unfragmented) + "\n", e);
    }
}
Also used : SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) BoltProtocolV4(org.neo4j.bolt.v4.BoltProtocolV4) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) NullLogService(org.neo4j.logging.internal.NullLogService) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) ByteBuf(io.netty.buffer.ByteBuf) RunMessage(org.neo4j.bolt.v4.messaging.RunMessage) ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) BoltProtocol(org.neo4j.bolt.BoltProtocol) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltChannel(org.neo4j.bolt.BoltChannel) BoltTestUtil.newTestBoltChannel(org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) TransportThrottleGroup(org.neo4j.bolt.transport.TransportThrottleGroup)

Aggregations

BoltChannel (org.neo4j.bolt.BoltChannel)10 Test (org.junit.jupiter.api.Test)6 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)5 BoltProtocol (org.neo4j.bolt.BoltProtocol)4 BoltTestUtil.newTestBoltChannel (org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel)4 BoltConnectionFactory (org.neo4j.bolt.runtime.BoltConnectionFactory)3 BoltStateMachineFactory (org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory)3 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)3 BoltStateMachineV4 (org.neo4j.bolt.v4.BoltStateMachineV4)3 DefaultDatabaseResolver (org.neo4j.kernel.database.DefaultDatabaseResolver)3 Channel (io.netty.channel.Channel)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 BoltProtocolVersion (org.neo4j.bolt.BoltProtocolVersion)2 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)2 TestDatabaseIdRepository (org.neo4j.kernel.database.TestDatabaseIdRepository)2 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)1