Search in sources :

Example 41 with MapValue

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

the class UserAggregationFunctionTest method shouldRunClassWithMultipleFunctionsDeclared.

@Test
void shouldRunClassWithMultipleFunctionsDeclared() throws Throwable {
    // Given
    List<CallableUserAggregationFunction> compiled = compile(MultiFunction.class);
    CallableUserAggregationFunction f1 = compiled.get(0);
    CallableUserAggregationFunction f2 = compiled.get(1);
    // When
    UserAggregator f1Aggregator = f1.create(prepareContext());
    f1Aggregator.update(new AnyValue[] { stringValue("Bonnie") });
    f1Aggregator.update(new AnyValue[] { stringValue("Clyde") });
    UserAggregator f2Aggregator = f2.create(prepareContext());
    f2Aggregator.update(new AnyValue[] { stringValue("Bonnie"), longValue(1337L) });
    f2Aggregator.update(new AnyValue[] { stringValue("Bonnie"), longValue(42L) });
    // Then
    assertThat(f1Aggregator.result()).isEqualTo(VirtualValues.list(stringValue("Bonnie"), stringValue("Clyde")));
    assertThat(((MapValue) f2Aggregator.result()).get("Bonnie")).isEqualTo(longValue(1337L));
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) UserAggregator(org.neo4j.internal.kernel.api.procs.UserAggregator) MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Example 42 with MapValue

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

the class DiscardMessageTest method shouldThrowExceptionIfFailedToParseTransactionMetadataCorrectly.

@Test
void shouldThrowExceptionIfFailedToParseTransactionMetadataCorrectly() throws Throwable {
    // Given
    Map<String, Object> msgMetadata = map("n", "invalid value type");
    MapValue meta = ValueUtils.asMapValue(msgMetadata);
    // When & Then
    BoltIOException exception = assertThrows(BoltIOException.class, () -> new DiscardMessage(meta));
    assertThat(exception.getMessage()).startsWith("Expecting DISCARD size n to be a Long value, but got: String(\"invalid value type\")");
}
Also used : BoltIOException(org.neo4j.bolt.messaging.BoltIOException) ValueUtils.asMapValue(org.neo4j.kernel.impl.util.ValueUtils.asMapValue) MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with MapValue

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

the class BoltRequestMessageV3Test method shouldHandleParameterizedStatements.

@Test
void shouldHandleParameterizedStatements() throws Throwable {
    // Given
    MapValue parameters = ValueUtils.asMapValue(map("n", 12L));
    // When
    RunMessage msg = serializeAndDeserialize(new RunMessage("asd", parameters));
    // Then
    MapValue params = msg.params();
    assertThat(params).isEqualTo(parameters);
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage) Test(org.junit.jupiter.api.Test)

Example 44 with MapValue

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

the class BoltResponseMessageWriterV3Test method shouldWriteSuccessMessage.

@Test
void shouldWriteSuccessMessage() throws Exception {
    PackOutput output = mock(PackOutput.class);
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    var writer = newWriter(output, packer);
    MapValue metadata = map(new String[] { "a", "b", "c" }, new AnyValue[] { intValue(1), stringValue("2"), date(2010, 02, 02) });
    writer.write(new SuccessMessage(metadata));
    InOrder inOrder = inOrder(output, packer);
    inOrder.verify(output).beginMessage();
    inOrder.verify(packer).pack(metadata);
    inOrder.verify(output).messageSucceeded();
}
Also used : InOrder(org.mockito.InOrder) SuccessMessage(org.neo4j.bolt.v3.messaging.response.SuccessMessage) MapValue(org.neo4j.values.virtual.MapValue) PackOutput(org.neo4j.bolt.packstream.PackOutput) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) Test(org.junit.jupiter.api.Test)

Example 45 with MapValue

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

the class PullMessageTest method shouldThrowExceptionIfFailedToParseTransactionMetadataCorrectly.

@Test
void shouldThrowExceptionIfFailedToParseTransactionMetadataCorrectly() throws Throwable {
    // Given
    Map<String, Object> msgMetadata = map("n", "invalid value type");
    MapValue meta = asMapValue(msgMetadata);
    // When & Then
    BoltIOException exception = assertThrows(BoltIOException.class, () -> new PullMessage(meta));
    assertThat(exception.getMessage()).startsWith("Expecting PULL size n to be a Long value, but got: String(\"invalid value type\")");
}
Also used : BoltIOException(org.neo4j.bolt.messaging.BoltIOException) ValueUtils.asMapValue(org.neo4j.kernel.impl.util.ValueUtils.asMapValue) MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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