use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method shouldInlineFiveSmallLabels.
@Test
public void shouldInlineFiveSmallLabels() throws Exception {
// GIVEN
long labelId1 = 10, labelId2 = 30, labelId3 = 45, labelId4 = 60, labelId5 = 61;
NodeRecord node = nodeRecordWithInlinedLabels(labelId1, labelId2, labelId3, labelId4);
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
nodeLabels.add(labelId5, null, null);
// THEN
assertEquals(inlinedLabelsLongRepresentation(labelId1, labelId2, labelId3, labelId4, labelId5), node.getLabelField());
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method oneDynamicRecordShouldShrinkIntoInlinedWhenRemoving.
@Test
public void oneDynamicRecordShouldShrinkIntoInlinedWhenRemoving() throws Exception {
// GIVEN
NodeRecord node = nodeRecordWithDynamicLabels(nodeStore, oneByteLongs(5));
Collection<DynamicRecord> initialRecords = node.getDynamicLabelRecords();
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
Collection<DynamicRecord> changedDynamicRecords = Iterables.asCollection(nodeLabels.remove(255, nodeStore));
// THEN
assertEquals(initialRecords, changedDynamicRecords);
assertFalse(Iterables.single(changedDynamicRecords).inUse());
assertEquals(inlinedLabelsLongRepresentation(251, 252, 253, 254), node.getLabelField());
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method addingAnAlreadyAddedLabelWhenLabelsAreInDynamicRecordsShouldFail.
@Test
public void addingAnAlreadyAddedLabelWhenLabelsAreInDynamicRecordsShouldFail() throws Exception {
// 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());
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
public void shouldHandleRandomAddsAndRemoves() throws Exception {
// 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());
key.add(labelId);
}
} else {
if (key.remove(labelId)) {
labels.remove(labelId, nodeStore);
}
}
}
// THEN
NodeLabels labels = NodeLabelsField.parseLabelsField(node);
long[] readLabelIds = labels.get(nodeStore);
for (long labelId : readLabelIds) {
assertTrue("Found an unexpected label " + labelId, key.remove((int) labelId));
}
assertTrue(key.isEmpty());
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method removingNonExistentInlinedLabelShouldFail.
@Test
public void removingNonExistentInlinedLabelShouldFail() throws Exception {
// GIVEN
int labelId1 = 1, labelId2 = 2;
NodeRecord node = nodeRecordWithInlinedLabels(labelId1);
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
try {
nodeLabels.remove(labelId2, nodeStore);
fail("Should have thrown exception");
} catch (IllegalStateException e) {
// THEN
}
}
Aggregations