ByteArrayOutputStream baos = new ByteArrayOutputStream(getBlockSizeBytes());
ByteArrayOutputStream baos = new ByteArrayOutputStream(getBlockSizeBytes());
Integer.valueOf(this.dataFile.getBlockSizeBytes()) ) ); elems.add(new StatElement<Integer>( "Number Of Blocks", Integer.valueOf(this.dataFile.getNumberOfBlocks()) ) );
Integer.valueOf(this.dataFile.getBlockSizeBytes()) ) ); elems.add(new StatElement<Integer>( "Number Of Blocks", Integer.valueOf(this.dataFile.getNumberOfBlocks()) ) );
/** * Verify that it says we need two blocks if the total size will fit. * <p> * @throws Exception */ public void testCalculateBlocksNeededDouble() throws Exception { // SETUP String fileName = "testCalculateBlocksNeededDouble"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int result = disk.calculateTheNumberOfBlocksNeeded( new byte[disk.getBlockSizeBytes() * 2 - ( 2 * BlockDisk.HEADER_SIZE_BYTES )] ); // Verify assertEquals( "Wrong number of blocks", 2, result ); }
/** * Verify that it says we need two blocks if the total size will fit. * <p> * @throws Exception */ public void testCalculateBlocksNeededDouble() throws Exception { // SETUP String fileName = "testCalculateBlocksNeededDouble"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int result = disk.calculateTheNumberOfBlocksNeeded( new byte[disk.getBlockSizeBytes() * 2 - ( 2 * BlockDisk.HEADER_SIZE_BYTES )] ); // Verify assertEquals( "Wrong number of blocks", 2, result ); }
int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocksPerElement );
int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocksPerElement );
/** * Test writing and reading elements that do not fit within a single block. * <p> * @throws Exception */ public void testWriteAndReadMultipleMultiBlockElement() throws Exception { // SETUP String fileName = "testWriteAndReadSingleBlockElement"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int numBlocksPerElement = 4; int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocksPerElement ); int numElements = 100; for ( int i = 0; i < numElements; i++ ) { int[] blocks = disk.write( new byte[bytes] ); byte[] result = (byte[]) disk.read( blocks ); // VERIFY assertEquals( "Wrong item retured.", new byte[bytes].length, result.length ); assertEquals( "Wrong number of blocks returned.", numBlocksPerElement, blocks.length ); } }
/** * Test writing and reading elements that do not fit within a single block. * <p> * @throws Exception */ public void testWriteAndReadMultipleMultiBlockElement() throws Exception { // SETUP String fileName = "testWriteAndReadSingleBlockElement"; File file = new File( rafDir, fileName + ".data" ); file.delete(); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK int numBlocksPerElement = 4; int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocksPerElement ); int numElements = 100; for ( int i = 0; i < numElements; i++ ) { int[] blocks = disk.write( new byte[bytes] ); byte[] result = (byte[]) disk.read( blocks ); // VERIFY assertEquals( "Wrong item retured.", new byte[bytes].length, result.length ); assertEquals( "Wrong number of blocks returned.", numBlocksPerElement, blocks.length ); } }
/** * Test writing an element that takes two blocks. * <p> * @throws Exception */ public void testWrite_DoubleBlockElement() throws Exception { // SETUP String fileName = "testWriteDoubleBlockElement"; File file = new File( rafDir, fileName + ".data" ); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK // byte arrays encur 27 bytes of serialization overhead. int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), 2 ); int[] blocks = disk.write( new byte[bytes] ); // VERIFY assertEquals( "Wrong number of blocks recorded.", 2, disk.getNumberOfBlocks() ); assertEquals( "Wrong number of blocks returned.", 2, blocks.length ); assertEquals( "Wrong block returned.", 0, blocks[0] ); }
/** * Test writing an element that takes 128 blocks. There was a byte in a for loop that limited the number to 127. I fixed this. * <p> * @throws Exception */ public void testWrite_128BlockElement() throws Exception { // SETUP int numBlocks = 128; String fileName = "testWrite_128BlockElement"; File file = new File( rafDir, fileName + ".data" ); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK // byte arrays encur 27 bytes of serialization overhead. int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocks ); int[] blocks = disk.write( new byte[bytes] ); // VERIFY assertEquals( "Wrong number of blocks recorded.", numBlocks, disk.getNumberOfBlocks() ); assertEquals( "Wrong number of blocks returned.", numBlocks, blocks.length ); assertEquals( "Wrong block returned.", 0, blocks[0] ); }
/** * Test writing an element that takes two blocks. * <p> * @throws Exception */ public void testWrite_DoubleBlockElement() throws Exception { // SETUP String fileName = "testWriteDoubleBlockElement"; File file = new File( rafDir, fileName + ".data" ); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK // byte arrays encur 27 bytes of serialization overhead. int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), 2 ); int[] blocks = disk.write( new byte[bytes] ); // VERIFY assertEquals( "Wrong number of blocks recorded.", 2, disk.getNumberOfBlocks() ); assertEquals( "Wrong number of blocks returned.", 2, blocks.length ); assertEquals( "Wrong block returned.", 0, blocks[0] ); }
/** * Test writing an element that takes 128 blocks. There was a byte in a for loop that limited the number to 127. I fixed this. * <p> * @throws Exception */ public void testWrite_128BlockElement() throws Exception { // SETUP int numBlocks = 128; String fileName = "testWrite_128BlockElement"; File file = new File( rafDir, fileName + ".data" ); BlockDisk disk = new BlockDisk( file, new StandardSerializer() ); // DO WORK // byte arrays encur 27 bytes of serialization overhead. int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocks ); int[] blocks = disk.write( new byte[bytes] ); // VERIFY assertEquals( "Wrong number of blocks recorded.", numBlocks, disk.getNumberOfBlocks() ); assertEquals( "Wrong number of blocks returned.", numBlocks, blocks.length ); assertEquals( "Wrong block returned.", 0, blocks[0] ); }