use of com.facebook.presto.common.block.IntArrayBlockBuilder in project presto by prestodb.
the class TestBlockBigArray method testRetainedSizeWithOverlappingBlocks.
@Test
public void testRetainedSizeWithOverlappingBlocks() {
int entries = 123;
BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, entries);
for (int i = 0; i < entries; i++) {
blockBuilder.writeInt(i);
}
Block block = blockBuilder.build();
// Verify we do not over count
int arraySize = 456;
int blocks = 7890;
BlockBigArray blockBigArray = new BlockBigArray();
blockBigArray.ensureCapacity(arraySize);
for (int i = 0; i < blocks; i++) {
blockBigArray.set(i % arraySize, block.getRegion(0, entries));
}
ReferenceCountMap referenceCountMap = new ReferenceCountMap();
referenceCountMap.incrementAndGet(block);
long expectedSize = ClassLayout.parseClass(BlockBigArray.class).instanceSize() + referenceCountMap.sizeOf() + (new ObjectBigArray()).sizeOf() + block.getRetainedSizeInBytes() + (arraySize - 1) * ClassLayout.parseClass(block.getClass()).instanceSize();
assertEquals(blockBigArray.sizeOf(), expectedSize);
}
Aggregations