use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method twoDynamicRecordsShouldShrinkToOneWhenRemoving.
@Test
public void twoDynamicRecordsShouldShrinkToOneWhenRemoving() throws Exception {
// GIVEN
// will occupy 61B of data, i.e. just two dynamic records
NodeRecord node = nodeRecordWithDynamicLabels(nodeStore, oneByteLongs(57));
Collection<DynamicRecord> initialRecords = node.getDynamicLabelRecords();
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
List<DynamicRecord> changedDynamicRecords = Iterables.addToCollection(nodeLabels.remove(255, /*Initial labels go from 255 and down to 255-58*/
nodeStore), new ArrayList<DynamicRecord>());
// THEN
assertEquals(initialRecords, changedDynamicRecords);
assertTrue(changedDynamicRecords.get(0).inUse());
assertFalse(changedDynamicRecords.get(1).inUse());
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method shouldReallocateAllOfPreviousDynamicRecordsAndThenSome.
@Test
public void shouldReallocateAllOfPreviousDynamicRecordsAndThenSome() throws Exception {
// GIVEN
NodeRecord node = nodeRecordWithDynamicLabels(nodeStore, fourByteLongs(100));
Set<DynamicRecord> initialRecords = Iterables.asSet(cloned(node.getDynamicLabelRecords(), DynamicRecord.class));
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
Set<DynamicRecord> reallocatedRecords = Iterables.asUniqueSet(nodeLabels.put(fourByteLongs(5), nodeStore, nodeStore.getDynamicLabelStore()));
// THEN
assertTrue("initial:" + initialRecords + ", reallocated:" + reallocatedRecords, initialRecords.containsAll(used(reallocatedRecords)));
assertTrue(used(reallocatedRecords).size() < initialRecords.size());
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method removingNonExistentLabelInDynamicRecordsShouldFail.
@Test
public void removingNonExistentLabelInDynamicRecordsShouldFail() throws Exception {
// GIVEN
long[] labels = oneByteLongs(20);
NodeRecord node = nodeRecordWithDynamicLabels(nodeStore, labels);
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
try {
nodeLabels.remove(123456, nodeStore);
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 shouldInlineFourSmallLabels.
@Test
public void shouldInlineFourSmallLabels() throws Exception {
// GIVEN
long labelId1 = 10, labelId2 = 30, labelId3 = 45, labelId4 = 60;
NodeRecord node = nodeRecordWithInlinedLabels(labelId1, labelId2, labelId3);
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
nodeLabels.add(labelId4, null, null);
// THEN
assertEquals(inlinedLabelsLongRepresentation(labelId1, labelId2, labelId3, labelId4), node.getLabelField());
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class BatchInsertTest method shouldSortLabelIdsWhenGetOrCreate.
@Test
public void shouldSortLabelIdsWhenGetOrCreate() throws Exception {
// GIVEN
BatchInserter inserter = globalInserter;
// 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(), RecordLoad.NORMAL);
NodeLabels labels = NodeLabelsField.parseLabelsField(node);
long[] labelIds = labels.get(nodeStore);
long[] sortedLabelIds = labelIds.clone();
Arrays.sort(sortedLabelIds);
assertArrayEquals(sortedLabelIds, labelIds);
}
Aggregations