private void truncateBytesFromLastLogFile( long bytesToTrim ) throws IOException { File highestLogFile = logFiles.getHighestLogFile(); long fileSize = fileSystemRule.getFileSize( highestLogFile ); if ( bytesToTrim > fileSize ) { fileSystemRule.deleteFile( highestLogFile ); } else { fileSystemRule.truncate( highestLogFile, fileSize - bytesToTrim ); } }
private void openMustThrowMetadataMismatchExceptionIfStatePagesAreAllZeros( ThrowingConsumer<PageCache,IOException> opener ) throws Exception { // given an existing index with all-zero state pages PageCache pageCache = createPageCache( DEFAULT_PAGE_SIZE ); try ( GBPTree<MutableLong,MutableLong> ignored = index( pageCache ).build() ) { // Just for creating it } fs.truncate( indexFile, DEFAULT_PAGE_SIZE /*truncate right after the first page*/ ); try ( OutputStream out = fs.openAsOutputStream( indexFile, true ) ) { byte[] allZeroPage = new byte[DEFAULT_PAGE_SIZE]; out.write( allZeroPage ); // page A out.write( allZeroPage ); // page B } // when try { opener.accept( pageCache ); fail( "Should've thrown IOException" ); } catch ( MetadataMismatchException e ) { // then good } }
private void openMustThrowMetadataMismatchExceptionIfSomeMetaPageIsMissing( ThrowingConsumer<PageCache,IOException> opener ) throws Exception { // given an existing index with only the first page in it PageCache pageCache = createPageCache( DEFAULT_PAGE_SIZE ); try ( GBPTree<MutableLong,MutableLong> ignored = index( pageCache ).build() ) { // Just for creating it } fs.truncate( indexFile, DEFAULT_PAGE_SIZE /*truncate right after the first page*/ ); // when try { opener.accept( pageCache ); fail( "Should've thrown IOException" ); } catch ( MetadataMismatchException e ) { // then good } }