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));
}
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());
}
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);
}
}
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));
}
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());
}
Aggregations