Search in sources :

Example 1 with TextArray

use of org.neo4j.values.storable.TextArray in project neo4j by neo4j.

the class GenericKeyStateTest method assertTextArraySize.

private static void assertTextArraySize(Value value, int actualSizeOfData, int normalArrayOverhead, String typeName) {
    if (value instanceof TextArray) {
        int sumOfStrings = 0;
        TextArray stringArray = (TextArray) value;
        for (int i = 0; i < stringArray.length(); i++) {
            String string = stringArray.stringValue(i);
            sumOfStrings += 2 + string.getBytes(UTF_8).length;
        }
        int totalTextArraySize = normalArrayOverhead + sumOfStrings;
        assertKeySize(totalTextArraySize, actualSizeOfData, typeName);
    } else {
        throw new RuntimeException("Unexpected class for value in value group " + TEXT_ARRAY + ", was " + value.getClass());
    }
}
Also used : TextArray(org.neo4j.values.storable.TextArray)

Example 2 with TextArray

use of org.neo4j.values.storable.TextArray in project neo4j by neo4j.

the class CommunityProcedureITBase method listProcedures.

@Test
void listProcedures() throws Throwable {
    // When
    ProcedureHandle procedures = procs().procedureGet(procedureName("dbms", "procedures"));
    RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procedures.id(), new AnyValue[0], ProcedureCallContext.EMPTY);
    // Then
    List<AnyValue[]> actual = asList(stream);
    List<Object[]> expected = getExpectedCommunityProcs();
    Map<String, AnyValue[]> resultMap = actual.stream().collect(toMap(row -> ((StringValue) row[0]).stringValue(), Function.identity()));
    Map<String, Object[]> expectedMap = expected.stream().collect(toMap(row -> ((StringValue) row[0]).stringValue(), Function.identity()));
    assertThat(resultMap.keySet(), containsInAnyOrder(expectedMap.keySet().toArray()));
    for (String procName : resultMap.keySet()) {
        AnyValue[] actualArray = resultMap.get(procName);
        Object[] expectedArray = expectedMap.get(procName);
        assertNotNull(expectedArray, "Got an unexpected entry for " + procName + " =>\n" + printElementsOfArray(actualArray));
        assertEquals(expectedArray.length, actualArray.length, "Count of columns for " + procName + " does not match");
        for (int i = 1; i < actualArray.length; i++) {
            Matcher matcher;
            if (expectedArray[i] instanceof TextArray) {
                // this has to be a list of roles, we ignore those in community and expect a null here
                matcher = equalTo(NO_VALUE);
            } else if (expectedArray[i] instanceof Matcher) {
                matcher = (Matcher) expectedArray[i];
            } else {
                matcher = equalTo(expectedArray[i]);
            }
            assertThat("Column " + i + " for " + procName + " does not match", actualArray[i], matcher);
        }
    }
    commit();
}
Also used : AnyValue(org.neo4j.values.AnyValue) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) NO_VALUE(org.neo4j.values.storable.Values.NO_VALUE) Arrays(java.util.Arrays) TextArray(org.neo4j.values.storable.TextArray) RawIterator(org.neo4j.collection.RawIterator) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureSignature.procedureName(org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName) Function(java.util.function.Function) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) StringValue(org.neo4j.values.storable.StringValue) Collectors.toMap(java.util.stream.Collectors.toMap) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) Matcher(org.hamcrest.Matcher) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Matcher(org.hamcrest.Matcher) ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) StringValue(org.neo4j.values.storable.StringValue) TextArray(org.neo4j.values.storable.TextArray) Test(org.junit.jupiter.api.Test)

Example 3 with TextArray

use of org.neo4j.values.storable.TextArray in project neo4j by neo4j.

the class NodeEntityWrappingNodeValue method labels.

@Override
public TextArray labels() {
    TextArray l = labels;
    if (l == null) {
        try {
            synchronized (this) {
                l = labels;
                if (l == null) {
                    List<String> ls = new ArrayList<>();
                    for (Label label : node.getLabels()) {
                        ls.add(label.name());
                    }
                    l = labels = Values.stringArray(ls.toArray(new String[0]));
                }
            }
        } catch (NotFoundException | IllegalStateException | StoreFailureException e) {
            throw new ReadAndDeleteTransactionConflictException(NodeEntity.isDeletedInCurrentTransaction(node), e);
        }
    }
    return l;
}
Also used : StoreFailureException(org.neo4j.exceptions.StoreFailureException) ArrayList(java.util.ArrayList) Label(org.neo4j.graphdb.Label) NotFoundException(org.neo4j.graphdb.NotFoundException) TextArray(org.neo4j.values.storable.TextArray)

Example 4 with TextArray

use of org.neo4j.values.storable.TextArray in project neo4j by neo4j.

the class PrettyPrinterTest method shouldHandleArraysInMaps.

@Test
void shouldHandleArraysInMaps() {
    // Given
    PrettyPrinter printer = new PrettyPrinter();
    TextArray array = Values.stringArray("a", "b", "c");
    MapValue map = props("k1", array, "k2", array);
    // When
    map.writeTo(printer);
    // Then
    assertThat(printer.value()).isEqualTo("{k1: [\"a\", \"b\", \"c\"], k2: [\"a\", \"b\", \"c\"]}");
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) TextArray(org.neo4j.values.storable.TextArray) Test(org.junit.jupiter.api.Test)

Example 5 with TextArray

use of org.neo4j.values.storable.TextArray in project neo4j by neo4j.

the class PrettyPrinterTest method shouldHandleArrays.

@Test
void shouldHandleArrays() {
    // Given
    PrettyPrinter printer = new PrettyPrinter();
    TextArray array = Values.stringArray("a", "b", "c");
    // When
    array.writeTo(printer);
    // Then
    assertThat(printer.value()).isEqualTo("[\"a\", \"b\", \"c\"]");
}
Also used : TextArray(org.neo4j.values.storable.TextArray) Test(org.junit.jupiter.api.Test)

Aggregations

TextArray (org.neo4j.values.storable.TextArray)11 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)3 AnyValue (org.neo4j.values.AnyValue)3 StoreFailureException (org.neo4j.exceptions.StoreFailureException)2 Label (org.neo4j.graphdb.Label)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 MapValue (org.neo4j.values.virtual.MapValue)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Matcher (org.hamcrest.Matcher)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)1 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1