private File idGeneratorFile() { return testDirectory.file( "testIdGenerator.id" ); } }
private void existenceOfFile( String name ) throws IOException { directory.file( name ).createNewFile(); } }
private File compressWithGZip( String text ) throws IOException { File file = directory.file( "compressed" ); try ( GZIPOutputStream out = new GZIPOutputStream( new FileOutputStream( file ) ) ) { out.write( text.getBytes() ); } return file; }
private File file( String filename ) throws IOException { File file = testDir.file( filename ); mkdirs( file.getParentFile() ); return file; }
@BeforeEach void setUp() throws Exception { homeDir = testDirectory.directory( "home-dir" ).toPath(); configDir = testDirectory.directory( "config-dir" ).toPath(); archive = testDirectory.file( "some-archive.dump" ).toPath(); dumper = mock( Dumper.class ); putStoreInDirectory( homeDir.resolve( "data/databases/foo.db" ) ); databaseDirectory = homeDir.resolve( "data/databases/foo.db" ); }
@Test void shouldGiveAClearErrorMessageIfTheArchiveIsNotInGzipFormat() throws IOException { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Files.write( archive, singletonList( "some incorrectly formatted data" ) ); Path destination = testDirectory.file( "the-destination" ).toPath(); IncorrectFormat incorrectFormat = assertThrows( IncorrectFormat.class, () -> new Loader().load( archive, destination, destination ) ); assertEquals( archive.toString(), incorrectFormat.getMessage() ); }
@Before public void setUp() { fs = fileSystemRule.get(); file = testDirectory.file( "ids" ); }
@Test void shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryDoesntExist() { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = testDirectory.file( "destination" ).toPath(); Path txLogsDestination = Paths.get( testDirectory.absolutePath().getAbsolutePath(), "subdir", "txLogs" ); NoSuchFileException noSuchFileException = assertThrows( NoSuchFileException.class, () -> new Loader().load( archive, destination, txLogsDestination ) ); assertEquals( txLogsDestination.getParent().toString(), noSuchFileException.getMessage() ); }
@Test void shouldGiveAClearErrorMessageIfTheArchiveDoesntExist() { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = testDirectory.file( "the-destination" ).toPath(); NoSuchFileException exception = assertThrows( NoSuchFileException.class, () -> new Loader().load( archive, destination, destination ) ); assertEquals( archive.toString(), exception.getMessage() ); }
@Test void shouldGiveAClearErrorIfTheDestinationTxLogAlreadyExists() { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = testDirectory.file( "the-destination" ).toPath(); Path txLogsDestination = testDirectory.directory( "txLogsDestination" ).toPath(); FileAlreadyExistsException exception = assertThrows( FileAlreadyExistsException.class, () -> new Loader().load( archive, destination, txLogsDestination ) ); assertEquals( txLogsDestination.toString(), exception.getMessage() ); }
@Test void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsAFile() throws IOException { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = Paths.get( testDirectory.absolutePath().getAbsolutePath(), "subdir", "the-destination" ); Files.write( destination.getParent(), new byte[0] ); FileSystemException exception = assertThrows( FileSystemException.class, () -> new Loader().load( archive, destination, destination ) ); assertEquals( destination.getParent().toString() + ": Not a directory", exception.getMessage() ); }
@Before public void createWorkingDirectoryAndTestFile() throws IOException { Thread.interrupted(); fs.mkdirs( testdir.directory() ); file = testdir.file( "a" ); fs.create( file ).close(); channel = null; channelShouldBeClosed = false; Thread.currentThread().interrupt(); }
@Test( expected = ConfigLoadIOException.class ) public void mustThrowIfConfigFileCouldNotBeFound() { File confFile = testDirectory.file( "test.conf" ); Config.fromFile( confFile ).build(); }
@Test void shouldGiveAClearErrorIfTheArchiveAlreadyExists() throws IOException { Path directory = testDirectory.directory( "a-directory" ).toPath(); Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Files.write( archive, new byte[0] ); FileAlreadyExistsException exception = assertThrows( FileAlreadyExistsException.class, () -> new Dumper().dump( directory, directory, archive, Predicates.alwaysFalse() ) ); assertEquals( archive.toString(), exception.getMessage() ); }
@Test void shouldGiveAClearErrorIfTheDestinationAlreadyExists() { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = testDirectory.directory( "the-destination" ).toPath(); FileAlreadyExistsException exception = assertThrows( FileAlreadyExistsException.class, () -> new Loader().load( archive, destination, destination ) ); assertEquals( destination.toString(), exception.getMessage() ); }
@Test void archiveFile() throws IOException { File archiveFile = testDirectory.file( "fileArchive.zip" ); File aFile = testDirectory.file( "a" ); fileSystem.create( aFile ).close(); ZipUtils.zip( fileSystem, aFile, archiveFile ); assertTrue( fileSystem.fileExists( archiveFile ) ); assertEquals( 1, countArchiveEntries( archiveFile ) ); }
@Test( expected = ToolFailureException.class ) public void failOnNotCleanlyShutdownStoreWithLogsInCustomAbsoluteLocation() throws Exception { File customConfigFile = testDirectory.file( "customConfig" ); File otherLocation = testDirectory.directory( "otherLocation" ); Config customConfig = Config.defaults( logical_logs_location, otherLocation.getAbsolutePath() ); createGraphDbAndKillIt( customConfig ); MapUtil.store( customConfig.getRaw(), customConfigFile ); String[] args = {testDirectory.databaseDir().getPath(), "-config", customConfigFile.getPath()}; runConsistencyCheckToolWith( fs.get(), args ); }
@Test( expected = ToolFailureException.class ) public void failOnNotCleanlyShutdownStoreWithLogsInCustomRelativeLocation() throws Exception { File customConfigFile = testDirectory.file( "customConfig" ); Config customConfig = Config.defaults( logical_logs_location, "otherLocation" ); createGraphDbAndKillIt( customConfig ); MapUtil.store( customConfig.getRaw(), fs.openAsOutputStream( customConfigFile, false ) ); String[] args = {testDirectory.databaseDir().getPath(), "-config", customConfigFile.getPath()}; runConsistencyCheckToolWith( fs.get(), args ); }
@Before public void setupPagedFile() throws IOException { PageCache pageCache = pageCacheRule .getPageCache( fileSystemRule.get(), config().withPageSize( PAGE_SIZE ).withAccessChecks( true ) ); pagedFile = pageCache .map( testDirectory.file( FILE_NAME ), PAGE_SIZE, CREATE, DELETE_ON_CLOSE ); }
private GBPTree<KEY,VALUE> createIndex() throws IOException { int pageSize = 512; layout = getLayout( random ); PageCache pageCache = pageCacheRule.getPageCache( fs.get(), config().withPageSize( pageSize ).withAccessChecks( true ) ); return index = new GBPTreeBuilder<>( pageCache, directory.file( "index" ), layout ).build(); }