Search in sources :

Example 26 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method shouldIncludeSystemUpdates.

@Test
void shouldIncludeSystemUpdates() throws Throwable {
    // Given
    QueryStatistics queryStatistics = mock(QueryStatistics.class);
    when(queryStatistics.containsSystemUpdates()).thenReturn(true);
    when(queryStatistics.getSystemUpdates()).thenReturn(11);
    QueryExecution result = mock(QueryExecution.class);
    BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
    when(result.fieldNames()).thenReturn(new String[0]);
    when(result.executionType()).thenReturn(query(READ_WRITE));
    subscriber.onResultCompleted(queryStatistics);
    when(result.getNotifications()).thenReturn(Collections.emptyList());
    Clock clock = mock(Clock.class);
    when(clock.millis()).thenReturn(0L, 1337L);
    var stream = new TestAbstractCypherAdapterStream(result, subscriber, clock);
    // When
    MapValue meta = metadataOf(stream);
    // Then
    assertThat(meta.get("type")).isEqualTo(stringValue("rw"));
    assertThat(meta.get("stats")).isEqualTo(mapValues("system-updates", intValue(11)));
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) MapValue(org.neo4j.values.virtual.MapValue) Clock(java.time.Clock) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 27 with MapValue

use of org.neo4j.values.virtual.MapValue 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 28 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class AbstractTransactionInitiatingMessage method shouldParseWriteAccessModeCorrectly.

@Test
void shouldParseWriteAccessModeCorrectly() throws Throwable {
    // Given
    Map<String, Object> msgMetadata = map("mode", "w");
    MapValue meta = ValueUtils.asMapValue(msgMetadata);
    // When
    TransactionInitiatingMessage beginMessage = createMessage(meta);
    // Then
    assertThat(beginMessage.getAccessMode()).isEqualTo(AccessMode.WRITE);
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Example 29 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class AbstractTransactionInitiatingMessage method shouldThrowExceptionIfFailedToParseAccessModeCorrectly.

@Test
void shouldThrowExceptionIfFailedToParseAccessModeCorrectly() throws Throwable {
    // Given
    Map<String, Object> msgMetadata = map("mode", 666);
    MapValue meta = ValueUtils.asMapValue(msgMetadata);
    // When & Then
    BoltIOException exception = assertThrows(BoltIOException.class, () -> createMessage(meta));
    assertThat(exception.getMessage()).startsWith("Expecting access mode value to be a String value");
}
Also used : BoltIOException(org.neo4j.bolt.messaging.BoltIOException) MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Example 30 with MapValue

use of org.neo4j.values.virtual.MapValue in project neo4j by neo4j.

the class AbstractTransactionInitiatingMessage method shouldParseTransactionMetadataCorrectly.

@Test
void shouldParseTransactionMetadataCorrectly() throws Throwable {
    // Given
    Map<String, Object> txMetadata = map("creation-time", Duration.ofMillis(4321L));
    Map<String, Object> msgMetadata = map("tx_metadata", txMetadata);
    MapValue meta = ValueUtils.asMapValue(msgMetadata);
    // When
    TransactionInitiatingMessage beginMessage = createMessage(meta);
    // Then
    assertThat(beginMessage.transactionMetadata().toString()).isEqualTo(txMetadata.toString());
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Aggregations

MapValue (org.neo4j.values.virtual.MapValue)48 Test (org.junit.jupiter.api.Test)30 AnyValue (org.neo4j.values.AnyValue)7 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)6 QueryExecution (org.neo4j.kernel.impl.query.QueryExecution)6 BoltAdapterSubscriber (org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber)5 QueryStatistics (org.neo4j.graphdb.QueryStatistics)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 RunMessage (org.neo4j.bolt.v3.messaging.request.RunMessage)3 ValueUtils.asMapValue (org.neo4j.kernel.impl.util.ValueUtils.asMapValue)3 Clock (java.time.Clock)2 LocalDate (java.time.LocalDate)2 HashMap (java.util.HashMap)2 SuccessMessage (org.neo4j.bolt.v3.messaging.response.SuccessMessage)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 RelationshipEntity (org.neo4j.kernel.impl.core.RelationshipEntity)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 DateTimeException (java.time.DateTimeException)1