@Override public long estimatedSize( DiagnosticsReporterProgress progress ) { return fs.getFileSize( source ); } }
@Override public boolean reached( File file, long version, LogFileInformation source ) { currentSize += fileSystem.getFileSize( file ); return currentSize >= maxSize; } }
@Override public long getFileSize( File fileName ) { return delegate.getFileSize( fileName ); }
@Override public long getFileSize( File fileName ) { return fs.getFileSize( fileName ); }
@Override public long getFileSize( File fileName ) { // Default adversarial might throw a java.lang.SecurityException here, which is an exception // that should not be survived return delegate.getFileSize( fileName ); } }
@Override public boolean hasAnyEntries( long version ) { return fileSystem.getFileSize( getLogFileForVersion( version ) ) > LOG_HEADER_SIZE; }
private boolean rotationThresholdExceeded() { return fileSystem.fileExists( outputFile ) && rotationThresholdBytes > 0 && fileSystem.getFileSize( outputFile ) >= rotationThresholdBytes; }
@Override public void addToArchive( Path archiveDestination, DiagnosticsReporterProgress progress ) throws IOException { long size = fs.getFileSize( source ); InputStream in = fs.openAsInputStream( source ); // Track progress of the file reading, source might be a very large file try ( ProgressAwareInputStream inStream = new ProgressAwareInputStream( in, size, progress::percentChanged ) ) { Files.copy( inStream, archiveDestination ); } }
private void create( File file, FileSystemAbstraction fileSystem, long indexVersion ) throws IOException { if ( fileSystem.fileExists( file ) && fileSystem.getFileSize( file ) > 0 ) { throw new IllegalArgumentException( file + " already exist" ); } try ( StoreChannel fileChannel = fileSystem.open( file, OpenMode.READ_WRITE ) ) { write( fileChannel, System.currentTimeMillis(), random.nextLong(), 0, 1, indexVersion ); } }
@Override public long getFileSize( File fileName ) { adversary.injectFailure( SecurityException.class ); return delegate.getFileSize( fileName ); }
@Override public long getFileSize( File fileName ) { return chooseFileSystem( fileName ).getFileSize( fileName ); }
@Test( expected = IllegalArgumentException.class ) public void shouldThrowWhenTryingToCreateFileThatAlreadyExists() { // Given FileSystemAbstraction fs = mock( FileSystemAbstraction.class ); when( fs.fileExists( file ) ).thenReturn( false ).thenReturn( true ); when( fs.getFileSize( file ) ).thenReturn( 42L ); // When new IndexProviderStore( file, fs, MetaDataStore.versionStringToLong( "3.5" ), false ); // Then // exception is thrown }
private int logFileSize() throws IOException { return aggregateLogData( from -> (int) fs.getFileSize( files.getLogFileForVersion( from ) ) ); }
private static void assertNumberOfFreeIdsEquals( File databaseDirectory, FileSystemAbstraction fs, long numberOfFreeIds ) { long fileSize = fs.getFileSize( new File( databaseDirectory, "neostore.propertystore.db.strings.id" ) ); long fileSizeWithoutHeader = fileSize - 9; long actualFreeIds = fileSizeWithoutHeader / 8; assertThat( "Id file should at least have a 9 byte header", fileSize, greaterThanOrEqualTo( 9L ) ); assertThat( "File should contain the expected number of free ids", actualFreeIds, is( numberOfFreeIds ) ); assertThat( "File size should not contain more bytes than expected", 8 * numberOfFreeIds, is( fileSizeWithoutHeader ) ); } }
static void changeVersionNumber( FileSystemAbstraction fileSystem, File storeFile, String versionString ) throws IOException { byte[] versionBytes = UTF8.encode( versionString ); try ( StoreChannel fileChannel = fileSystem.open( storeFile, OpenMode.READ_WRITE ) ) { fileChannel.position( fileSystem.getFileSize( storeFile ) - versionBytes.length ); fileChannel.write( ByteBuffer.wrap( versionBytes ) ); } }
@Test public void shouldReturnTrueWhenASingleFileSizeIsGreaterOrEqualThanMaxSize() { // given long sixteenGigabytes = 16L * 1024 * 1024 * 1024; final FileSizeThreshold threshold = new FileSizeThreshold( fs, sixteenGigabytes ); when( fs.getFileSize( file ) ).thenReturn( sixteenGigabytes ); // when threshold.init(); final boolean result = threshold.reached( file, version, source ); // then assertTrue( result ); }
@Test public void shouldReturnFalseWhenFileSizeIsLowerThanMaxSize() { // given final long maxSize = 10; final FileSizeThreshold threshold = new FileSizeThreshold( fs, maxSize ); when( fs.getFileSize( file ) ).thenReturn( 5L ); // when threshold.init(); final boolean result = threshold.reached( file, version, source ); // then assertFalse( result ); }
@Test public void shouldSumSizeWhenCalledMultipleTimes() { // given final long maxSize = 10; final FileSizeThreshold threshold = new FileSizeThreshold( fs, maxSize ); when( fs.getFileSize( file ) ).thenReturn( 5L ); // when threshold.init(); threshold.reached( file, version, source ); final boolean result = threshold.reached( file, version, source ); // then assertTrue( result ); }
@Test public void shouldWriteNewFileWhenExistingFileHasZeroLength() throws IOException { // Given file.createNewFile(); // When IndexProviderStore store = new IndexProviderStore( file, fileSystem, MetaDataStore.versionStringToLong( "3.5" ), false ); // Then assertTrue( fileSystem.getFileSize( file ) > 0 ); store.close(); } }
private int figureOutSampleTransactionSizeBytes() throws IOException { db = newDb( "true", 5 ); doTransaction(); db.shutdown(); return (int) fs.getFileSize( files.getLogFileForVersion( 0 ) ); }