}
@Test
public void testLotsOfStuff()
{
Block block = VARCHAR.createBlockBuilder(new BlockBuilderStatus())
.appendSlice(Slices.utf8Slice("alice"))
.appendSlice(Slices.utf8Slice("bob"))
.appendSlice(Slices.utf8Slice("charlie"))
.appendSlice(Slices.utf8Slice("dave"))
.build();
DynamicSliceOutput encoderOutput = new DynamicSliceOutput(1024);
Encoder encoder = BlocksFileEncoding.SNAPPY.createBlocksWriter(encoderOutput);
BlockBuilder expectedBlockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus());
int count = 1000;
for (int i = 0; i < count; i++) {
// select a random position
int position = ThreadLocalRandom.current().nextInt(block.getPositionCount());
// add to expected block
block.appendTo(position, expectedBlockBuilder);
// create block with single value and add to encoder
encoder.append(block.getSingleValueBlock(position));
}
Block expectedBlock = expectedBlockBuilder.build();
BlockEncoding snappyEncoding = encoder.finish();
assertTrue(encoderOutput.size() < expectedBlock.getSizeInBytes());
Block actualBlock = snappyEncoding.readBlock(encoderOutput.slice().getInput());
BlockAssertions.assertBlockEquals(actualBlock, expectedBlock);
}