PartitionBuilder { public LogBufferPartition[] slicePartitions( final int partitionSize, final AllocatedBuffer allocatedBuffer) { final ByteBuffer buffer = allocatedBuffer.getRawBuffer(); final LogBufferPartition[] partitions = new LogBufferPartition[PARTITION_COUNT]; for (int i = 0; i < PARTITION_COUNT; i++) { final int dataSectionOffset = partitionDataSectionOffset(partitionSize, i); final int metaDataSectionOffset = partitionMetadataSectionOffset(partitionSize, i); final UnsafeBuffer dataSection = new UnsafeBuffer(buffer, dataSectionOffset, partitionSize); final UnsafeBuffer metadataSection = new UnsafeBuffer(buffer, metaDataSectionOffset, PARTITION_META_DATA_LENGTH); partitions[i] = new LogBufferPartition(dataSection, metadataSection, dataSectionOffset); } return partitions; }  LogBufferPartition[] slicePartitions(
      final int partitionSize, final AllocatedBuffer allocatedBuffer);  }
@Test public void shouldSlicePartitions() { final int partitionSize = 1024; final int capacity = (PARTITION_COUNT * partitionSize) + (PARTITION_COUNT * PARTITION_META_DATA_LENGTH); final AllocatedBuffer buffer = BufferAllocators.allocateDirect(capacity); final LogBufferPartition[] partitions = partitionBuilder.slicePartitions(partitionSize, buffer); assertThat(partitions.length).isEqualTo(PARTITION_COUNT); for (final LogBufferPartition logBufferPartition : partitions) { assertThat(logBufferPartition.getPartitionSize()).isEqualTo(partitionSize); assertThat(logBufferPartition.getDataBuffer().capacity()).isEqualTo(partitionSize); } }