Search in sources :

Example 81 with PropertyBlock

use of org.neo4j.kernel.impl.store.record.PropertyBlock in project neo4j by neo4j.

the class PropertyRecordTest method addingDuplicatePropertyBlockShouldOverwriteExisting.

@Test
public void addingDuplicatePropertyBlockShouldOverwriteExisting() {
    // Given these things...
    PropertyRecord record = new PropertyRecord(1);
    PropertyBlock blockA = new PropertyBlock();
    blockA.setValueBlocks(new long[1]);
    blockA.setKeyIndexId(2);
    PropertyBlock blockB = new PropertyBlock();
    blockB.setValueBlocks(new long[1]);
    // also 2, thus a duplicate
    blockB.setKeyIndexId(2);
    // When we set the property block twice that have the same key
    record.setPropertyBlock(blockA);
    record.setPropertyBlock(blockB);
    // Then the record should only contain a single block, because blockB overwrote blockA
    List<PropertyBlock> propertyBlocks = Iterables.asList((Iterable<PropertyBlock>) record);
    assertThat(propertyBlocks, hasItem(blockB));
    assertThat(propertyBlocks, hasSize(1));
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) Test(org.junit.Test)

Example 82 with PropertyBlock

use of org.neo4j.kernel.impl.store.record.PropertyBlock in project neo4j by neo4j.

the class PropertyRecordTest method shouldIterateOverBlocks.

@Test
public void shouldIterateOverBlocks() throws Exception {
    // GIVEN
    PropertyRecord record = new PropertyRecord(0);
    PropertyBlock[] blocks = new PropertyBlock[3];
    for (int i = 0; i < blocks.length; i++) {
        blocks[i] = new PropertyBlock();
        record.addPropertyBlock(blocks[i]);
    }
    // WHEN
    Iterator<PropertyBlock> iterator = record.iterator();
    // THEN
    for (int i = 0; i < blocks.length; i++) {
        assertTrue(iterator.hasNext());
        assertEquals(blocks[i], iterator.next());
    }
    assertFalse(iterator.hasNext());
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) Test(org.junit.Test)

Example 83 with PropertyBlock

use of org.neo4j.kernel.impl.store.record.PropertyBlock in project neo4j by neo4j.

the class PropertyRecordTest method addBlock.

private static void addBlock(PropertyRecord record, int key, int value) {
    PropertyBlock block = new PropertyBlock();
    PropertyStore.encodeValue(block, key, value, null, null);
    for (long valueBlock : block.getValueBlocks()) {
        record.addLoadedBlock(valueBlock);
    }
}
Also used : PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock)

Example 84 with PropertyBlock

use of org.neo4j.kernel.impl.store.record.PropertyBlock in project neo4j by neo4j.

the class PropertyRecordTest method shouldBeAbleToRemoveBlocksDuringIteration.

@Test
public void shouldBeAbleToRemoveBlocksDuringIteration() throws Exception {
    // GIVEN
    PropertyRecord record = new PropertyRecord(0);
    Set<PropertyBlock> blocks = new HashSet<>();
    for (int i = 0; i < 4; i++) {
        PropertyBlock block = new PropertyBlock();
        record.addPropertyBlock(block);
        blocks.add(block);
    }
    // WHEN
    Iterator<PropertyBlock> iterator = record.iterator();
    assertIteratorRemoveThrowsIllegalState(iterator);
    // THEN
    int size = blocks.size();
    for (int i = 0; i < size; i++) {
        assertTrue(iterator.hasNext());
        PropertyBlock block = iterator.next();
        if (i % 2 == 1) {
            iterator.remove();
            assertIteratorRemoveThrowsIllegalState(iterator);
            blocks.remove(block);
        }
    }
    assertFalse(iterator.hasNext());
    // and THEN there should only be the non-removed blocks left
    assertEquals(blocks, Iterables.asSet(record));
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 85 with PropertyBlock

use of org.neo4j.kernel.impl.store.record.PropertyBlock in project neo4j by neo4j.

the class PropertyRecordTest method addLoadedBlock.

@Test
public void addLoadedBlock() {
    PropertyRecord record = new PropertyRecord(42);
    addBlock(record, 1, 2);
    addBlock(record, 3, 4);
    List<PropertyBlock> blocks = Iterables.asList(record);
    assertEquals(2, blocks.size());
    assertEquals(1, blocks.get(0).getKeyIndexId());
    assertEquals(2, blocks.get(0).getSingleValueInt());
    assertEquals(3, blocks.get(1).getKeyIndexId());
    assertEquals(4, blocks.get(1).getSingleValueInt());
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) Test(org.junit.Test)

Aggregations

PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)90 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)57 Test (org.junit.Test)21 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)16 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)9 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)8 Pair (org.neo4j.helpers.collection.Pair)8 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)8 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)8 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)6 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)6 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)5 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)5 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)5 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)5 PrimitiveRecord (org.neo4j.kernel.impl.store.record.PrimitiveRecord)4 ChainCheck (org.neo4j.consistency.checking.ChainCheck)3 RecordAccessStub (org.neo4j.consistency.store.RecordAccessStub)3 DynamicRecordAllocator (org.neo4j.kernel.impl.store.DynamicRecordAllocator)3