ReadOnlyIdGenerator( LongSupplier highId, FileSystemAbstraction fs, File filename ) { if ( fs != null && fs.fileExists( filename ) ) { try { this.highId = IdGeneratorImpl.readHighId( fs, filename ); defragCount = IdGeneratorImpl.readDefragCount( fs, filename ); } catch ( IOException e ) { throw new UnderlyingStorageException( "Failed to read id counts of the id file: " + filename, e ); } } else { this.highId = highId.getAsLong(); defragCount = 0; } }
@Test public void shouldReadDefragCountUsingStaticMethod() throws Exception { EphemeralFileSystemAbstraction fs = fsr.get(); IdGeneratorImpl.createGenerator( fs, file, 0, false ); IdGeneratorImpl idGenerator = new IdGeneratorImpl( fs, file, 1, 10000, false, IdType.NODE, () -> 0L ); idGenerator.nextId(); long a = idGenerator.nextId(); idGenerator.nextId(); long b = idGenerator.nextId(); idGenerator.nextId(); idGenerator.freeId( a ); idGenerator.freeId( b ); long expectedDefragCount = idGenerator.getDefragCount(); idGenerator.close(); long actualDefragCount = IdGeneratorImpl.readDefragCount( fs, file ); assertEquals( 2, expectedDefragCount ); assertEquals( expectedDefragCount, actualDefragCount ); }
ReadOnlyIdGenerator( LongSupplier highId, FileSystemAbstraction fs, File filename ) { if ( fs != null && fs.fileExists( filename ) ) { try { this.highId = IdGeneratorImpl.readHighId( fs, filename ); defragCount = IdGeneratorImpl.readDefragCount( fs, filename ); } catch ( IOException e ) { throw new UnderlyingStorageException( "Failed to read id counts of the id file: " + filename, e ); } } else { this.highId = highId.getAsLong(); defragCount = 0; } }