Search in sources :

Example 31 with BoltStateMachine

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

the class BoltRequestMessageReaderV3Test method testMessageDecoding.

private static void testMessageDecoding(RequestMessage message) throws Exception {
    Neo4jPack neo4jPack = newNeo4jPack();
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    BoltRequestMessageReader reader = requestMessageReader(stateMachine);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, message));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    reader.read(unpacker);
    verify(stateMachine).process(eq(message), any());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)

Example 32 with BoltStateMachine

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

the class MessageDecoderTest method unpack.

private void unpack(byte[] input) {
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    SynchronousBoltConnection connection = new SynchronousBoltConnection(stateMachine);
    channel = new EmbeddedChannel(newDecoder(connection));
    channel.writeInbound(Unpooled.wrappedBuffer(input));
    channel.finishAndReleaseAll();
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 33 with BoltStateMachine

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

the class MessageDecoderTest method shouldDispatchRequestMessage.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void shouldDispatchRequestMessage(Neo4jPack packerUnderTest) throws Exception {
    this.packerUnderTest = packerUnderTest;
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    SynchronousBoltConnection connection = new SynchronousBoltConnection(stateMachine);
    channel = new EmbeddedChannel(newDecoder(connection));
    channel.writeInbound(Unpooled.wrappedBuffer(serialize(packerUnderTest, ResetMessage.INSTANCE)));
    channel.finishAndReleaseAll();
    verify(stateMachine).process(eq(ResetMessage.INSTANCE), any());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 34 with BoltStateMachine

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

the class MessageDecoderTest method testUnpackableStructParametersWithKnownType.

private void testUnpackableStructParametersWithKnownType(Neo4jPack packerForSerialization, AnyValue parameterValue, String expectedMessage) throws Exception {
    String statement = "RETURN $x";
    MapValue parameters = VirtualValues.map(new String[] { "x" }, new AnyValue[] { parameterValue });
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    SynchronousBoltConnection connection = new SynchronousBoltConnection(stateMachine);
    channel = new EmbeddedChannel(newDecoder(connection));
    channel.writeInbound(Unpooled.wrappedBuffer(serialize(packerForSerialization, new RunMessage(statement, parameters))));
    channel.finishAndReleaseAll();
    verify(stateMachine).handleExternalFailure(eq(Neo4jError.from(Status.Statement.TypeError, expectedMessage)), any());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) MapValue(org.neo4j.values.virtual.MapValue) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage)

Example 35 with BoltStateMachine

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

the class BoltStateMachineFactoryImplTest method shouldCreateBoltStateMachinesV42.

@Test
void shouldCreateBoltStateMachinesV42() {
    BoltStateMachineFactoryImpl factory = newBoltFactory();
    var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
    BoltStateMachine boltStateMachine = factory.newStateMachine(new BoltProtocolVersion(4, 2), CHANNEL, MapValue.EMPTY, memoryTracker);
    assertNotNull(boltStateMachine);
    assertThat(boltStateMachine).isInstanceOf(BoltStateMachineV42.class);
    verify(memoryTracker).getScopedMemoryTracker();
    verify(memoryTracker, times(3)).allocateHeap(anyLong());
    verifyNoMoreInteractions(memoryTracker);
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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