use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method addingAnAlreadyAddedLabelWhenLabelsAreInDynamicRecordsShouldFail.
@Test
void addingAnAlreadyAddedLabelWhenLabelsAreInDynamicRecordsShouldFail() {
// GIVEN
long[] labels = oneByteLongs(20);
NodeRecord node = nodeRecordWithDynamicLabels(nodeStore, labels);
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
try {
nodeLabels.add(safeCastLongToInt(labels[0]), nodeStore, nodeStore.getDynamicLabelStore(), NULL, INSTANCE);
fail("Should have thrown exception");
} catch (IllegalStateException e) {
// THEN
}
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method shouldHandleRandomAddsAndRemoves.
/*
* There was this issue that DynamicNodeLabels#add would consider even unused dynamic records when
* reading existing label ids before making the change. Previously this would create a duplicate
* last label id (the one formerly being in the second record).
*
* This randomized test found this issue every time when it existed and it will potentially find other
* unforeseen issues as well.
*/
@Test
void shouldHandleRandomAddsAndRemoves() {
// GIVEN
Set<Integer> key = new HashSet<>();
NodeRecord node = new NodeRecord(0);
node.setInUse(true);
// WHEN
for (int i = 0; i < 100_000; i++) {
NodeLabels labels = NodeLabelsField.parseLabelsField(node);
int labelId = random.nextInt(200);
if (random.nextBoolean()) {
if (!key.contains(labelId)) {
labels.add(labelId, nodeStore, nodeStore.getDynamicLabelStore(), NULL, INSTANCE);
key.add(labelId);
}
} else {
if (key.remove(labelId)) {
labels.remove(labelId, nodeStore, NULL, INSTANCE);
}
}
}
// THEN
NodeLabels labels = NodeLabelsField.parseLabelsField(node);
long[] readLabelIds = labels.get(nodeStore, NULL);
for (long labelId : readLabelIds) {
assertTrue(key.remove((int) labelId), "Found an unexpected label " + labelId);
}
assertTrue(key.isEmpty());
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method maximumOfSevenInlinedLabels.
@Test
void maximumOfSevenInlinedLabels() {
// GIVEN
long[] labels = new long[] { 0, 1, 2, 3, 4, 5, 6 };
NodeRecord node = nodeRecordWithInlinedLabels(labels);
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
Iterable<DynamicRecord> changedDynamicRecords = nodeLabels.add(23, nodeStore, nodeStore.getDynamicLabelStore(), NULL, INSTANCE);
// THEN
assertEquals(dynamicLabelsLongRepresentation(changedDynamicRecords), node.getLabelField());
assertEquals(1, Iterables.count(changedDynamicRecords));
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class BatchInsertTest method shouldSortLabelIdsWhenGetOrCreate.
@ParameterizedTest
@MethodSource("params")
void shouldSortLabelIdsWhenGetOrCreate(int denseNodeThreshold) throws Exception {
// GIVEN
var inserter = newBatchInserter(denseNodeThreshold);
// WHEN
long nodeId = inserter.createNode(map("Item", 123456789123L), label("AA"), label("BB"), label("CC"), label("DD"));
inserter.setNodeLabels(nodeId, label("CC"), label("AA"), label("DD"), label("EE"), label("FF"));
// THEN
NodeStore nodeStore = getFlushedNeoStores(inserter).getNodeStore();
NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), NORMAL, NULL);
NodeLabels labels = NodeLabelsField.parseLabelsField(node);
long[] labelIds = labels.get(nodeStore, NULL);
long[] sortedLabelIds = Arrays.copyOf(labelIds, labelIds.length);
Arrays.sort(sortedLabelIds);
assertArrayEquals(sortedLabelIds, labelIds);
inserter.shutdown();
}
Aggregations