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());
}
}
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();
}
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;
}
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\"]}");
}
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\"]");
}
Aggregations