Refine search
@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 }
@Test public void shouldReturnOldChannelWhenNextChannelHasntGottenCompleteHeaderYet() throws Exception { // given final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge( logFiles ); final StoreChannel nextVersionWithIncompleteHeader = mock( StoreChannel.class ); when( nextVersionWithIncompleteHeader.read( any( ByteBuffer.class ) ) ).thenReturn( LOG_HEADER_SIZE / 2 ); when( channel.getVersion() ).thenReturn( version ); when( fs.fileExists( any( File.class ) ) ).thenReturn( true ); when( fs.open( any( File.class ), eq( OpenMode.READ ) ) ).thenReturn( nextVersionWithIncompleteHeader ); // when final LogVersionedStoreChannel result = bridge.next( channel ); // then assertEquals( channel, result ); verify( channel, never() ).close(); }
@Test public void cleanupMigrationDirectory() throws IOException { when( fs.fileExists( migratedIndexStore ) ).thenReturn( true ); ExplicitIndexProvider indexProviders = getExplicitIndexProvider(); ExplicitIndexMigrator indexMigrator = new TestExplicitIndexMigrator( fs, indexProviders, logProvider, true ); indexMigrator.migrate( storeLayout, migrationLayout, progressMonitor, StandardV2_3.STORE_VERSION, StandardV3_0.STORE_VERSION ); indexMigrator.cleanup( migrationLayout ); verify( fs ).deleteRecursively( migratedIndexStore ); }
@Test public void shouldSetDefaultAdmin() throws Throwable { // Given assertFalse( fileSystem.fileExists( adminIniFile ) ); // When String[] arguments = {"jake"}; setDefaultAdmin.execute( arguments ); // Then assertAdminIniFile( "jake" ); }
@Test public void shouldSetInitialPassword() throws Throwable { // Given assertFalse( fileSystem.fileExists( authInitFile ) ); // When String[] arguments = {"123"}; setPasswordCommand.execute( arguments ); // Then assertAuthIniFile( "123" ); }
@Test public void shouldNotDeleteAnythingIfThresholdDoesNotAllow() when( files.getLogFileForVersion( 0 ) ).thenReturn( fileName0 ); when( fileSystem.fileExists( fileName6 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName5 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName4 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName3 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName2 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName1 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName0 ) ).thenReturn( true );
@Test public void shouldOpenTheNextChannelWhenItExists() throws IOException { // given final StoreChannel newStoreChannel = mock( StoreChannel.class ); final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge( logFiles ); when( channel.getVersion() ).thenReturn( version ); when( channel.getLogFormatVersion() ).thenReturn( CURRENT_LOG_VERSION ); when( fs.fileExists( any( File.class ) ) ).thenReturn( true ); when( fs.open( any( File.class ), eq( OpenMode.READ ) ) ).thenReturn( newStoreChannel ); when( newStoreChannel.read( ArgumentMatchers.<ByteBuffer>any() ) ).then( invocationOnMock -> { ByteBuffer buffer = invocationOnMock.getArgument( 0 ); buffer.putLong( encodeLogVersion( version + 1 ) ); buffer.putLong( 42 ); return LOG_HEADER_SIZE; } ); // when final LogVersionedStoreChannel result = bridge.next( channel ); // then PhysicalLogVersionedStoreChannel expected = new PhysicalLogVersionedStoreChannel( newStoreChannel, version + 1, CURRENT_LOG_VERSION ); assertEquals( expected, result ); verify( channel, times( 1 ) ).close(); }
@Test public void shouldDeleteJustWhatTheThresholdSays() when( files.getLogFileForVersion( 1 ) ).thenReturn( fileName1 ); when( fileSystem.fileExists( fileName6 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName5 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName4 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName3 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName2 ) ).thenReturn( true ); when( fileSystem.fileExists( fileName1 ) ).thenReturn( true );
@Test public void luceneLabelIndexRemovedAfterSuccessfulMigration() throws IOException { prepareEmpty23Database(); indexMigrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV2_3.STORE_VERSION, StandardV3_2.STORE_VERSION ); indexMigrator.moveMigratedFiles( migrationLayout, databaseLayout, StandardV2_3.STORE_VERSION, StandardV3_2.STORE_VERSION ); assertFalse( fileSystem.fileExists( luceneLabelScanStore ) ); }
@Test public void shouldCloseChannelInFailedAttemptToReadHeaderAfterOpen() throws Exception { // GIVEN a file which returns 1/2 log header size worth of bytes FileSystemAbstraction fs = mock( FileSystemAbstraction.class ); LogFiles logFiles = LogFilesBuilder.builder( directory.databaseLayout(), fs ) .withTransactionIdStore( transactionIdStore ) .withLogVersionRepository( logVersionRepository ).build(); int logVersion = 0; File logFile = logFiles.getLogFileForVersion( logVersion ); StoreChannel channel = mock( StoreChannel.class ); when( channel.read( any( ByteBuffer.class ) ) ).thenReturn( LogHeader.LOG_HEADER_SIZE / 2 ); when( fs.fileExists( logFile ) ).thenReturn( true ); when( fs.open( eq( logFile ), any( OpenMode.class ) ) ).thenReturn( channel ); // WHEN try { logFiles.openForVersion( logVersion ); fail( "Should have failed" ); } catch ( IncompleteLogHeaderException e ) { // THEN good verify( channel ).close(); } }
@Test public void noPruning() throws Exception { newDb( "true", 2 ); for ( int i = 0; i < 100; i++ ) { doTransaction(); } long currentVersion = files.getHighestLogVersion(); for ( long version = 0; version < currentVersion; version++ ) { assertTrue( "Version " + version + " has been unexpectedly pruned", fs.fileExists( files.getLogFileForVersion( version ) ) ); } }
@Test public void shouldSuppressFailureToCloseChannelInFailedAttemptToReadHeaderAfterOpen() throws Exception { // GIVEN a file which returns 1/2 log header size worth of bytes FileSystemAbstraction fs = mock( FileSystemAbstraction.class ); LogFiles logFiles = LogFilesBuilder.builder( directory.databaseLayout(), fs ) .withTransactionIdStore( transactionIdStore ) .withLogVersionRepository( logVersionRepository ).build(); int logVersion = 0; File logFile = logFiles.getLogFileForVersion( logVersion ); StoreChannel channel = mock( StoreChannel.class ); when( channel.read( any( ByteBuffer.class ) ) ).thenReturn( LogHeader.LOG_HEADER_SIZE / 2 ); when( fs.fileExists( logFile ) ).thenReturn( true ); when( fs.open( eq( logFile ), any( OpenMode.class ) ) ).thenReturn( channel ); doThrow( IOException.class ).when( channel ).close(); // WHEN try { logFiles.openForVersion( logVersion ); fail( "Should have failed" ); } catch ( IncompleteLogHeaderException e ) { // THEN good verify( channel ).close(); assertEquals( 1, e.getSuppressed().length ); assertTrue( e.getSuppressed()[0] instanceof IOException ); } }
@Test public void skipMigrationIfNativeIndexExist() throws Exception { ByteBuffer sourceBuffer = writeFile( nativeLabelIndex, new byte[]{1, 2, 3} ); indexMigrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV3_2.STORE_VERSION, StandardV3_2.STORE_VERSION ); indexMigrator.moveMigratedFiles( migrationLayout, databaseLayout, StandardV3_2.STORE_VERSION, StandardV3_2.STORE_VERSION ); ByteBuffer resultBuffer = readFileContent( nativeLabelIndex, 3 ); assertEquals( sourceBuffer, resultBuffer ); assertTrue( fileSystem.fileExists( luceneLabelScanStore ) ); }
@Test public void shouldDeleteIfClosed() { // GIVEN createEmptyFile(); IdContainer idContainer = new IdContainer( fs, file, 100, false ); idContainer.init(); idContainer.close( 0 ); // WHEN idContainer.delete(); // THEN assertFalse( fs.fileExists( file ) ); }
@Test public void shouldDeleteIfOpen() { // GIVEN createEmptyFile(); IdContainer idContainer = new IdContainer( fs, file, 100, false ); idContainer.init(); // WHEN idContainer.delete(); // THEN assertFalse( fs.fileExists( file ) ); idContainer.close( 0 ); }
@Test public void clearMigrationDirFromAnyLabelScanStoreBeforeMigrating() throws Exception { // given prepareEmpty23Database(); initializeNativeLabelScanStoreWithContent( migrationLayout ); File toBeDeleted = migrationLayout.labelScanStore(); assertTrue( fileSystem.fileExists( toBeDeleted ) ); // when indexMigrator.migrate( databaseLayout, migrationLayout, progressReporter, StandardV3_2.STORE_VERSION, StandardV3_2.STORE_VERSION ); // then assertNoContentInNativeLabelScanStore( migrationLayout ); }
@Test public void shouldDeleteOnCloseIfOpenOptionsSaysSo() { // GIVEN DatabaseLayout databaseLayout = dir.databaseLayout(); File nodeStore = databaseLayout.nodeStore(); File idFile = databaseLayout.idFile( DatabaseFile.NODE_STORE ).orElseThrow( () -> new IllegalStateException( "Node store id file not found." ) ); FileSystemAbstraction fs = fileSystemRule.get(); PageCache pageCache = pageCacheRule.getPageCache( fs, Config.defaults() ); TheStore store = new TheStore( nodeStore, databaseLayout.idNodeStore(), config, idType, new DefaultIdGeneratorFactory( fs ), pageCache, NullLogProvider.getInstance(), recordFormat, DELETE_ON_CLOSE ); store.initialise( true ); store.makeStoreOk(); assertTrue( fs.fileExists( nodeStore ) ); assertTrue( fs.fileExists( idFile ) ); // WHEN store.close(); // THEN assertFalse( fs.fileExists( nodeStore ) ); assertFalse( fs.fileExists( idFile ) ); }
@Test public void shouldRecoverIfCrashedDuringMove() throws Throwable assertFalse( crashingFileSystem.fileExists( authFile ) ); assertThat( crashingFileSystem.listFiles( authFile.getParentFile() ).length, equalTo( 0 ) );
@Test public void dropShouldDeleteEntireIndexFolder() { // given File root = storage.directory().directory( "root" ); IndexDirectoryStructure directoryStructure = IndexDirectoryStructure.directoriesByProvider( root ).forProvider( GenericNativeIndexProvider.DESCRIPTOR ); long indexId = 8; File indexDirectory = directoryStructure.directoryForIndex( indexId ); File indexFile = new File( indexDirectory, "my-index" ); StoreIndexDescriptor descriptor = IndexDescriptorFactory.forSchema( SchemaDescriptorFactory.forLabel( 1, 1 ) ).withId( indexId ); IndexSpecificSpaceFillingCurveSettingsCache spatialSettings = mock( IndexSpecificSpaceFillingCurveSettingsCache.class ); FileSystemAbstraction fs = storage.fileSystem(); GenericNativeIndexAccessor accessor = new GenericNativeIndexAccessor( storage.pageCache(), fs, indexFile, new GenericLayout( 1, spatialSettings ), immediate(), EMPTY, descriptor, spatialSettings, directoryStructure, mock( SpaceFillingCurveConfiguration.class ) ); // when accessor.drop(); // then assertFalse( fs.fileExists( indexDirectory ) ); } }
@Test public void shouldRotateCountsStoreWhenClosingTheDatabase() { // GIVEN GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase(); try ( Transaction tx = db.beginTx() ) { db.createNode( A ); tx.success(); } // WHEN db.shutdown(); // THEN assertTrue( fs.fileExists( alphaStoreFile() ) ); assertTrue( fs.fileExists( betaStoreFile() ) ); try ( Lifespan life = new Lifespan() ) { CountsTracker store = life.add( createCountsTracker( pageCache ) ); // a transaction for creating the label and a transaction for the node assertEquals( BASE_TX_ID + 1 + 1, store.txId() ); assertEquals( INITIAL_MINOR_VERSION, store.minorVersion() ); // one for all nodes and one for the created "A" label assertEquals( 1 + 1, store.totalEntriesStored() ); assertEquals( 1 + 1, allRecords( store ).size() ); } }