static long readDefragCount( FileSystemAbstraction fileSystem, File file ) throws IOException { try ( StoreChannel channel = fileSystem.open( file, OpenMode.READ ) ) { return FreeIdKeeper.countFreeIds( new OffsetChannel( channel, HEADER_SIZE ) ); } }
@Override public void writeAll( ByteBuffer src, long position ) throws IOException { delegate.writeAll( src, offset( position ) ); }
@Test void read() throws Exception { channel.read( buf ); verify( actual ).read( buf ); }
@Test void positionWithPosition() throws Exception { long position = 500; channel.position( position ); verify( actual ).position( 500 + offset ); }
@Test void force() throws Exception { channel.force( false ); verify( actual ).force( false ); }
@Test void truncate() throws Exception { long size = 256; channel.truncate( size ); verify( actual ).truncate( size + offset ); }
@Test void isOpen() { channel.isOpen(); verify( actual ).isOpen(); }
@Test void flush() throws Exception { channel.flush(); verify( actual ).flush(); }
@Test void close() throws Exception { channel.close(); verify( actual ).close(); } }
@Test void size() throws Exception { long size = 256; when( actual.size() ).thenReturn( size ); assertEquals( 256 - offset, channel.size() ); verify( actual ).size(); }
@Test void readWithPosition() throws Exception { long position = 500; channel.read( buf, position ); verify( actual ).read( buf, position + offset ); }
@Test void position() throws Exception { long position = 500; when( actual.position() ).thenReturn( position ); assertEquals( position - offset, channel.position() ); verify( actual ).position(); }
@Override public int read( ByteBuffer dst, long position ) throws IOException { return delegate.read( dst, offset( position ) ); }
/** * Initializes the id generator and performs a simple validation. Returns true if the initialization restored * properly on disk state, false otherwise (such as creating an id file from scratch). * Will throw {@link InvalidIdGeneratorException} if the id file is found to be damaged or unclean. */ public boolean init() { boolean result = true; try { if ( !fs.fileExists( file ) ) { createEmptyIdFile( fs, file, 0, false ); result = false; } fileChannel = fs.open( file, OpenMode.READ_WRITE ); initialHighId = readAndValidateHeader(); markAsSticky(); this.freeIdKeeper = new FreeIdKeeper( new OffsetChannel( fileChannel, HEADER_SIZE ), grabSize, aggressiveReuse ); closed = false; } catch ( IOException e ) { throw new UnderlyingStorageException( "Unable to init id file " + file, e ); } return result; }
@Test void readMultiple() throws Exception { channel.read( buffers ); verify( actual ).read( buffers ); }
@Override public StoreChannel truncate( long size ) throws IOException { return delegate.truncate( offset( size ) ); }
static long readDefragCount( FileSystemAbstraction fileSystem, File file ) throws IOException { try ( StoreChannel channel = fileSystem.open( file, OpenMode.READ ) ) { return FreeIdKeeper.countFreeIds( new OffsetChannel( channel, HEADER_SIZE ) ); } }
@Test void readMultipleExtended() throws Exception { int off = 16; int len = 32; channel.read( buffers, off, len ); verify( actual ).read( buffers, off, len ); }
@Override public StoreChannel position( long newPosition ) throws IOException { return delegate.position( offset( newPosition ) ); }
/** * Initializes the id generator and performs a simple validation. Returns true if the initialization restored * properly on disk state, false otherwise (such as creating an id file from scratch). * Will throw {@link InvalidIdGeneratorException} if the id file is found to be damaged or unclean. */ public boolean init() { boolean result = true; try { if ( !fs.fileExists( file ) ) { createEmptyIdFile( fs, file, 0, false ); result = false; } fileChannel = fs.open( file, OpenMode.READ_WRITE ); initialHighId = readAndValidateHeader(); markAsSticky(); this.freeIdKeeper = new FreeIdKeeper( new OffsetChannel( fileChannel, HEADER_SIZE ), grabSize, aggressiveReuse ); closed = false; } catch ( IOException e ) { throw new UnderlyingStorageException( "Unable to init id file " + file, e ); } return result; }