Search in sources :

Example 31 with NodeLabels

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());
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) Test(org.junit.Test)

Example 32 with NodeLabels

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
    }
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) Test(org.junit.Test)

Example 33 with NodeLabels

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());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) Test(org.junit.Test)

Example 34 with NodeLabels

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);
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.Test)

Example 35 with NodeLabels

use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.

the class BatchInsertTest method shouldNotCreateSameLabelTwiceOnSameNode.

@Test
public void shouldNotCreateSameLabelTwiceOnSameNode() throws Exception {
    // GIVEN
    BatchInserter inserter = globalInserter;
    // WHEN
    long nodeId = inserter.createNode(map("itemId", 1000L), label("Item"), label("Item"));
    // THEN
    NodeStore nodeStore = getFlushedNeoStores(inserter).getNodeStore();
    NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), NORMAL);
    NodeLabels labels = NodeLabelsField.parseLabelsField(node);
    long[] labelIds = labels.get(nodeStore);
    assertEquals(1, labelIds.length);
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.Test)

Aggregations

NodeLabels (org.neo4j.kernel.impl.store.NodeLabels)49 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)46 DynamicNodeLabels (org.neo4j.kernel.impl.store.DynamicNodeLabels)40 Test (org.junit.Test)23 Test (org.junit.jupiter.api.Test)21 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)18 NodeStore (org.neo4j.kernel.impl.store.NodeStore)4 HashSet (java.util.HashSet)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Command (org.neo4j.kernel.impl.transaction.command.Command)2 BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)2 CheckerEngine (org.neo4j.consistency.checking.CheckerEngine)1 LabelChainWalker (org.neo4j.consistency.checking.LabelChainWalker)1 RecordAccess (org.neo4j.consistency.store.RecordAccess)1 InlineNodeLabels (org.neo4j.kernel.impl.store.InlineNodeLabels)1