private File file( File parent, String name, int size ) throws IOException { File file = new File( parent, name ); try ( StoreChannel channel = fs.create( file ) ) { ByteBuffer buffer = ByteBuffer.allocate( size ); buffer.position( size ).flip(); channel.write( buffer ); } return file; } }
private void createFile( File file ) throws IOException { fs.mkdirs( file.getParentFile() ); fs.create( file ).close(); } }
private byte[] fileWithContent() throws IOException { int size = 1000; fs.mkdirs( getIndexFile().getParentFile() ); try ( StoreChannel storeChannel = fs.create( getIndexFile() ) ) { byte[] someBytes = new byte[size]; random.nextBytes( someBytes ); storeChannel.writeAll( ByteBuffer.wrap( someBytes ) ); return someBytes; } } }
@Test public void shouldFailWhenUnableToReadALogHeaderFromAFile() throws IOException { // given final File file = testDirectory.file( "ReadLogHeader" ); fileSystemRule.create( file ).close(); try { // when readLogHeader( fileSystemRule.get(), file ); fail( "should have thrown" ); } catch ( IncompleteLogHeaderException ex ) { // then assertTrue( ex.getMessage(), ex.getMessage().contains( file.getName() ) ); } }
@Test public void shouldRestartPopulationIfIndexFileWasNeverFullyInitialized() throws IOException { // given File labelScanStoreFile = NativeLabelScanStore.getLabelScanStoreFile( testDirectory.databaseLayout() ); fileSystemRule.create( labelScanStoreFile ).close(); TrackingMonitor monitor = new TrackingMonitor(); LifeSupport life = new LifeSupport(); // when life.add( createLabelScanStore( fileSystemRule.get(), testDirectory.databaseLayout(), EMPTY, true, false, monitor ) ); life.start(); // then assertTrue( monitor.corruptedIndex ); assertTrue( monitor.rebuildingCalled ); life.shutdown(); } }