public static void constructFakeRaidFile ( DistributedFileSystem dfs , String filePath , RaidCodec codec ) throws IOException { long blockSize = 512L ; byte [ ] buffer = new byte [ ( int ) ( codec . numDataBlocks * blockSize ) ] ; int [ ] checksum = new int [ codec . numDataBlocks ] ; OutputStream out = dfs . create ( new Path ( filePath ) , true , 1 , codec . parityReplication , blockSize ) ; random . nextBytes ( buffer ) ; out . write ( buffer ) ; out . close ( ) ; Path parityTmp = new Path ( filePath + "_parity" ) ; buffer = new byte [ ( int ) ( codec . numParityBlocks * blockSize ) ] ; out = dfs . create ( parityTmp , true , 1 , codec . parityReplication , blockSize ) ; random . nextBytes ( buffer ) ; out . write ( buffer ) ; out . close ( ) ; FileStatus stat = dfs . getFileStatus ( new Path ( filePath ) ) ; dfs . setTimes ( parityTmp , stat . getModificationTime ( ) , stat . getAccessTime ( ) ) ; dfs . merge ( parityTmp , new Path ( filePath ) , codec . id , checksum ) ; }
This function create two mock source and parity files and merge them .