Search in sources :

Example 41 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class HeapTrackingListValueBuilderTest method streamAndCollectElements.

@Test
void streamAndCollectElements() {
    int iterations = rnd.nextInt(10, 1000);
    ArrayList<LongValue> list = new ArrayList<>(iterations);
    for (int i = 0; i < iterations; i++) {
        list.add(Values.longValue(i));
    }
    var collector = HeapTrackingListValueBuilder.collector(memoryTracker);
    ListValue listValue = list.stream().collect(collector);
    // Validate value size
    long memoryTrackerActualSize = meter.measureDeep(memoryTracker);
    long actualValueSize = meter.measureDeep(listValue) - memoryTrackerActualSize;
    long estimatedValueSize = listValue.estimatedHeapUsage();
    assertEquals(actualValueSize, estimatedValueSize);
    // Validate items
    Iterator<AnyValue> iterator = listValue.iterator();
    for (int i = 0; i < iterations; i++) {
        assertTrue(iterator.hasNext());
        assertEquals(i, ((LongValue) iterator.next()).longValue());
    }
    assertFalse(iterator.hasNext());
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) LongValue(org.neo4j.values.storable.LongValue) ArrayList(java.util.ArrayList) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 42 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class BuiltInProceduresIT method dbIndexesResult.

private static AnyValue[] dbIndexesResult(long id, String name, String state, Double populationPercent, String uniqueness, String type, String entityType, List<String> labelsOrTypes, List<String> properties, String provider) {
    ListValue labelsOrTypesList = VirtualValues.list(labelsOrTypes.stream().map(Values::stringValue).toArray(AnyValue[]::new));
    ListValue propertiesList = VirtualValues.list(properties.stream().map(Values::stringValue).toArray(AnyValue[]::new));
    return new AnyValue[] { longValue(id), stringValue(name), stringValue(state), doubleValue(populationPercent), stringValue(uniqueness), stringValue(type), stringValue(entityType), labelsOrTypesList, propertiesList, stringValue(provider) };
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) Values(org.neo4j.values.storable.Values) VirtualValues(org.neo4j.values.virtual.VirtualValues) AnyValue(org.neo4j.values.AnyValue)

Example 43 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class BoltRequestMessageV3Test method shouldSerializeNode.

// "B1 71 91 B3 4E 0C 92 |84 55 73 65 72 | 86 42 61 6E\n61 6E 61 A284 6E 61 6D 65 83 42 6F 62 83 61 67\n65 0E"
// "B1 71 91 B3 4E 0C 92 |86 42 61 6E 61 6E 61| 84 55\n73 65 72 A2 84 6E 61 6D 65 83 42 6F 62 83 61 67\n65 0E
@Test
void shouldSerializeNode() throws Throwable {
    NodeValue nodeValue = nodeValue(12L, stringArray("User", "Banana"), map(new String[] { "name", "age" }, new AnyValue[] { stringValue("Bob"), intValue(14) }));
    assertThat(serialized(nodeValue)).isEqualTo("B1 71 91 B3 4E 0C 92 84 55 73 65 72 86 42 61 6E" + lineSeparator() + "61 6E 61 A2 84 6E 61 6D 65 83 42 6F 62 83 61 67" + lineSeparator() + "65 0E");
}
Also used : NodeValue(org.neo4j.values.virtual.NodeValue) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 44 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class BoltResponseMessageWriterV3Test method shouldWriteRecordMessage.

@Test
void shouldWriteRecordMessage() throws Exception {
    PackOutput output = mock(PackOutput.class);
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    var writer = newWriter(output, packer);
    writer.write(new RecordMessage(new AnyValue[] { longValue(42), stringValue("42") }));
    InOrder inOrder = inOrder(output, packer);
    inOrder.verify(output).beginMessage();
    inOrder.verify(packer).pack(longValue(42));
    inOrder.verify(packer).pack(stringValue("42"));
    inOrder.verify(output).messageSucceeded();
}
Also used : InOrder(org.mockito.InOrder) AnyValue(org.neo4j.values.AnyValue) PackOutput(org.neo4j.bolt.packstream.PackOutput) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) RecordMessage(org.neo4j.bolt.v3.messaging.response.RecordMessage) Test(org.junit.jupiter.api.Test)

Example 45 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class TruncatedQuerySnapshotTest method shouldTruncateNode.

@Test
void shouldTruncateNode() {
    // when
    TruncatedQuerySnapshot x = new TruncatedQuerySnapshot(null, "", null, map("n", NODE), -1L, -1L, -1L, 100);
    // then
    AnyValue truncatedNode = x.queryParameters.get("n");
    assertTrue(truncatedNode instanceof NodeReference);
    assertEquals(NODE.id(), ((NodeReference) truncatedNode).id());
}
Also used : NodeReference(org.neo4j.values.virtual.NodeReference) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Aggregations

AnyValue (org.neo4j.values.AnyValue)95 Test (org.junit.jupiter.api.Test)58 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)19 ListValue (org.neo4j.values.virtual.ListValue)14 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)11 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)11 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)10 List (java.util.List)9 TextValue (org.neo4j.values.storable.TextValue)9 RawIterator (org.neo4j.collection.RawIterator)8 MapValue (org.neo4j.values.virtual.MapValue)8 Context (org.neo4j.kernel.api.procedure.Context)7 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)7 ArrayList (java.util.ArrayList)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Values.stringValue (org.neo4j.values.storable.Values.stringValue)6 LocalDate (java.time.LocalDate)5 LocalTime (java.time.LocalTime)5 ZonedDateTime (java.time.ZonedDateTime)5 Arrays (java.util.Arrays)5