Search in sources :

Example 21 with BoltStateMachine

use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.

the class AbstractBoltProtocol method install.

/**
 * Install chunker, packstream, message reader, message handler, message encoder for protocol v1
 */
@Override
public void install() {
    BoltStateMachine stateMachine = stateMachineFactory.newStateMachine(version(), channel, connectionHints, memoryTracker);
    var neo4jPack = createPack(memoryTracker);
    var messageWriter = createMessageWriter(neo4jPack, logging, memoryTracker);
    var connection = connectionFactory.newConnection(channel, stateMachine, messageWriter);
    var messageReader = createMessageReader(connection, messageWriter, bookmarksParser, logging, channelProtector, memoryTracker);
    memoryTracker.allocateHeap(ChunkDecoder.SHALLOW_SIZE + MessageAccumulator.SHALLOW_SIZE + MessageDecoder.SHALLOW_SIZE + HouseKeeper.SHALLOW_SIZE);
    channel.installBoltProtocol(new ChunkDecoder(), new MessageAccumulator(config), new MessageDecoder(neo4jPack, messageReader, logging), new HouseKeeper(connection, logging.getInternalLog(HouseKeeper.class)));
}
Also used : MessageDecoder(org.neo4j.bolt.transport.pipeline.MessageDecoder) ChunkDecoder(org.neo4j.bolt.transport.pipeline.ChunkDecoder) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) MessageAccumulator(org.neo4j.bolt.transport.pipeline.MessageAccumulator) HouseKeeper(org.neo4j.bolt.transport.pipeline.HouseKeeper)

Example 22 with BoltStateMachine

use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.

the class SessionExtension method newMachine.

public BoltStateMachine newMachine(BoltProtocolVersion version, BoltChannel boltChannel, MemoryTracker memoryTracker) {
    assertTestStarted();
    BoltStateMachine machine = boltFactory.newStateMachine(version, boltChannel, MapValue.EMPTY, memoryTracker);
    runningMachines.add(machine);
    return machine;
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine)

Example 23 with BoltStateMachine

use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.

the class BoltConnectionAuthIT method shouldGiveKernelVersionOnInit.

@Test
void shouldGiveKernelVersionOnInit() throws Throwable {
    // Given it is important for client applications to programmatically
    // identify expired credentials as the cause of not being authenticated
    BoltStateMachine machine = newStateMachine();
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    String version = "Neo4j/" + Version.getNeo4jVersion();
    // When
    var hello = BoltV4Messages.hello(newBasicAuthToken("neo4j", "neo4j"));
    machine.process(hello, recorder);
    machine.process(BoltV4Messages.run("CREATE ()"), recorder);
    // Then
    assertThat(recorder.nextResponse()).satisfies(succeededWithMetadata("server", stringValue(version)));
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.jupiter.api.Test)

Example 24 with BoltStateMachine

use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.

the class BoltConnectionAuthIT method shouldCloseConnectionAfterAuthenticationFailure.

@Test
void shouldCloseConnectionAfterAuthenticationFailure() throws Throwable {
    // Given
    BoltStateMachine machine = newStateMachine();
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // When... then
    var hello = BoltV4Messages.hello(newBasicAuthToken("neo4j", "j4oen"));
    verifyKillsConnection(() -> machine.process(hello, recorder));
    // ...and
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.Security.Unauthorized));
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.jupiter.api.Test)

Example 25 with BoltStateMachine

use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine 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

BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)61 Test (org.junit.jupiter.api.Test)40 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)11 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)10 FailedState (org.neo4j.bolt.v4.runtime.FailedState)10 BoltRequestMessageReader (org.neo4j.bolt.messaging.BoltRequestMessageReader)8 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)8 PackedInputArray (org.neo4j.bolt.packstream.PackedInputArray)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Neo4jError (org.neo4j.bolt.runtime.Neo4jError)7 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)7 BoltProtocolVersion (org.neo4j.bolt.BoltProtocolVersion)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 BoltChannel (org.neo4j.bolt.BoltChannel)5 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)4 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)3 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)3 BoltStateMachineSPI (org.neo4j.bolt.runtime.statemachine.BoltStateMachineSPI)3 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)3 BoltStateMachineV4 (org.neo4j.bolt.v4.BoltStateMachineV4)3