Refine search
@Test public void shouldNotWantToRecoverIntactStore() throws Exception { PageCache pageCache = pageCacheRule.getPageCache( fileSystem ); RecoveryRequiredChecker recoverer = getRecoveryCheckerWithDefaultConfig( fileSystem, pageCache ); assertThat( recoverer.isRecoveryRequiredAt( databaseLayout ), is( false ) ); }
@Test public void shouldNotThrowIfIntactStore() throws RecoveryRequiredException, IOException { PageCache pageCache = pageCacheRule.getPageCache( fileSystem ); RecoveryRequiredChecker.assertRecoveryIsNotRequired( fileSystem, pageCache, Config.defaults(), databaseLayout, new Monitors() ); }
@Test public void shouldWantToRecoverBrokenStore() throws Exception { try ( FileSystemAbstraction fileSystemAbstraction = createAndCrashWithDefaultConfig() ) { PageCache pageCache = pageCacheRule.getPageCache( fileSystemAbstraction ); RecoveryRequiredChecker recoverer = getRecoveryCheckerWithDefaultConfig( fileSystemAbstraction, pageCache ); assertThat( recoverer.isRecoveryRequiredAt( databaseLayout ), is( true ) ); } }
@Test public void notParticipatingParticipantsAreNotPartOfMigration() throws IOException { PageCache pageCache = pageCacheRule.getPageCache( fileSystem ); UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache ); StoreUpgrader storeUpgrader = newUpgrader( upgradableDatabase, pageCache ); assertThat( storeUpgrader.getParticipants(), hasSize( 3 ) ); }
@Test public void flushOfThePageCacheHappensOnlyOnceDuringShutdown() throws Throwable { PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) ); NeoStoreDataSource ds = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCache ); ds.start(); verify( pageCache, never() ).flushAndForce(); verify( pageCache, never() ).flushAndForce( any( IOLimiter.class ) ); ds.stop(); ds.shutdown(); verify( pageCache ).flushAndForce( IOLimiter.UNLIMITED ); }
@Test public void flushOfThePageCacheOnShutdownHappensIfTheDbIsHealthy() throws Throwable { PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) ); NeoStoreDataSource ds = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCache ); ds.start(); verify( pageCache, never() ).flushAndForce(); ds.stop(); ds.shutdown(); verify( pageCache ).flushAndForce( IOLimiter.UNLIMITED ); }
@Test public void flushOfThePageCacheOnShutdownDoesNotHappenIfTheDbIsUnhealthy() throws Throwable { DatabaseHealth health = mock( DatabaseHealth.class ); when( health.isHealthy() ).thenReturn( false ); PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) ); Dependencies dependencies = new Dependencies(); dependencies.satisfyDependency( health ); NeoStoreDataSource ds = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCache, dependencies ); ds.start(); verify( pageCache, never() ).flushAndForce(); ds.stop(); ds.shutdown(); verify( pageCache, never() ).flushAndForce( IOLimiter.UNLIMITED ); }
@Test public void verifyPageCacheLongArray() throws Exception { PageCache pageCache = pageCacheRule.getPageCache( fs ); PagedFile file = pageCache.map( dir.file( "file" ), pageCache.pageSize(), CREATE, DELETE_ON_CLOSE ); try ( LongArray array = new PageCacheLongArray( file, COUNT, 0, 0 ) ) { verifyBehaviour( array ); } }
@Test( expected = RecoveryRequiredException.class ) public void shouldThrowIfBrokenStore() throws IOException, RecoveryRequiredException { try ( FileSystemAbstraction fileSystemAbstraction = createAndCrashWithDefaultConfig() ) { PageCache pageCache = pageCacheRule.getPageCache( fileSystemAbstraction ); RecoveryRequiredChecker.assertRecoveryIsNotRequired( fileSystemAbstraction, pageCache, Config.defaults(), databaseLayout, new Monitors() ); fail(); } }
@Test public void shouldBeAbleToRecoverBrokenStore() throws Exception { try ( FileSystemAbstraction fileSystemAbstraction = createAndCrashWithDefaultConfig() ) { PageCache pageCache = pageCacheRule.getPageCache( fileSystemAbstraction ); RecoveryRequiredChecker recoverer = getRecoveryCheckerWithDefaultConfig( fileSystemAbstraction, pageCache ); assertThat( recoverer.isRecoveryRequiredAt( databaseLayout ), is( true ) ); new TestGraphDatabaseFactory().setFileSystem( fileSystemAbstraction ).newImpermanentDatabase( storeDir ).shutdown(); assertThat( recoverer.isRecoveryRequiredAt( databaseLayout ), is( false ) ); } }
@Test public void mustFlushStoresWithGivenIOLimiter() { IOLimiter limiter = IOLimiter.UNLIMITED; FileSystemAbstraction fs = fsRule.get(); AtomicReference<IOLimiter> observedLimiter = new AtomicReference<>(); PageCache pageCache = new DelegatingPageCache( pageCacheRule.getPageCache( fs ) ) { @Override public void flushAndForce( IOLimiter limiter ) throws IOException { super.flushAndForce( limiter ); observedLimiter.set( limiter ); } }; RecordStorageEngine engine = storageEngineRule.getWith( fs, pageCache, testDirectory.databaseLayout() ).build(); engine.flushAndForce( limiter ); assertThat( observedLimiter.get(), sameInstance( limiter ) ); }
@Test public void upgradeShouldNotLeaveLeftoverAndMigrationDirs() throws Exception { // Given fileSystem.deleteFile( databaseLayout.file( INTERNAL_LOG_FILE ) ); PageCache pageCache = pageCacheRule.getPageCache( fileSystem ); UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache ); // When newUpgrader( upgradableDatabase, allowMigrateConfig, pageCache ).migrateIfNeeded( databaseLayout ); // Then assertThat( migrationHelperDirs(), is( emptyCollectionOf( File.class ) ) ); }
@Test public void shouldFailIfFileDoesNotExist() { // given File missingFile = new File( directory.directory(), "missing-file" ); PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache ); // when StoreVersionCheck.Result result = storeVersionCheck.hasVersion( missingFile, "version" ); // then assertFalse( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.missingStoreFile, result.outcome ); assertNull( result.actualVersion ); }
@Test public void shouldHaltUpgradeIfUpgradeConfigurationVetoesTheProcess() throws IOException { PageCache pageCache = pageCacheRule.getPageCache( fileSystem ); Config deniedMigrationConfig = Config.defaults( GraphDatabaseSettings.allow_upgrade, "false" ); deniedMigrationConfig.augment( GraphDatabaseSettings.record_format, Standard.LATEST_NAME ); UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache ); try { newUpgrader( upgradableDatabase, deniedMigrationConfig, pageCache ).migrateIfNeeded( databaseLayout ); fail( "Should throw exception" ); } catch ( UpgradeNotAllowedByConfigurationException e ) { // expected } }
@Test public void shouldAlwaysShutdownLifeEvenWhenCheckPointingFails() throws Exception { // Given FileSystemAbstraction fs = this.fs.get(); PageCache pageCache = pageCacheRule.getPageCache( fs ); DatabaseHealth databaseHealth = mock( DatabaseHealth.class ); when( databaseHealth.isHealthy() ).thenReturn( true ); IOException ex = new IOException( "boom!" ); doThrow( ex ).when( databaseHealth ) .assertHealthy( IOException.class ); // <- this is a trick to simulate a failure during checkpointing Dependencies dependencies = new Dependencies(); dependencies.satisfyDependencies( databaseHealth ); NeoStoreDataSource dataSource = dsRule.getDataSource( dir.databaseLayout(), fs, pageCache, dependencies ); dataSource.start(); try { // When dataSource.stop(); fail( "it should have thrown" ); } catch ( LifecycleException e ) { // Then assertEquals( ex, e.getCause() ); } }
@Test public void panicOnExceptionDuringCommandsApply() { IllegalStateException failure = new IllegalStateException( "Too many open files" ); RecordStorageEngine engine = storageEngineRule.getWith( fsRule.get(), pageCacheRule.getPageCache( fsRule.get() ), testDirectory.databaseLayout() ) .databaseHealth( databaseHealth ) .transactionApplierTransformer( facade -> transactionApplierFacadeTransformer( facade, failure ) ) .build(); CommandsToApply commandsToApply = mock( CommandsToApply.class ); try { engine.apply( commandsToApply, TransactionApplicationMode.INTERNAL ); fail( "Exception expected" ); } catch ( Exception exception ) { assertSame( failure, Exceptions.rootCause( exception ) ); } verify( databaseHealth ).panic( any( Throwable.class ) ); }
@Test public void checkingIfRecordIsInUseMustHappenAfterConsistentRead() { AtomicBoolean nextReadIsInconsistent = new AtomicBoolean( false ); PageCache pageCache = pageCacheRule.getPageCache( fs, config().withInconsistentReads( nextReadIsInconsistent ) ); StoreFactory factory = factory( null, pageCache ); try ( NeoStores neoStores = factory.openAllNeoStores( true ) ) { RecordStore<RelationshipGroupRecord> relationshipGroupStore = neoStores.getRelationshipGroupStore(); RelationshipGroupRecord record = new RelationshipGroupRecord( 1 ).initialize( true, 2, 3, 4, 5, 6, Record.NO_NEXT_RELATIONSHIP.intValue() ); relationshipGroupStore.updateRecord( record ); nextReadIsInconsistent.set( true ); // Now the following should not throw any RecordNotInUse exceptions RelationshipGroupRecord readBack = relationshipGroupStore.getRecord( 1, relationshipGroupStore.newRecord(), NORMAL ); assertThat( readBack.toString(), equalTo( record.toString() ) ); } }
@Test public void shouldReportShortFileDoesNotHaveSpecifiedVersion() throws IOException { // given File shortFile = fileContaining( fileSystemRule.get(), "nothing interesting" ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCacheRule.getPageCache( fileSystemRule.get() ) ); // when StoreVersionCheck.Result result = storeVersionCheck.hasVersion( shortFile, "version" ); // then assertFalse( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.storeVersionNotFound, result.outcome ); assertNull( result.actualVersion ); }
@Test public void openingThroughStoreAccessShouldNotTriggerRecovery() throws Throwable { try ( EphemeralFileSystemAbstraction snapshot = produceUncleanStore() ) { assertTrue( "Store should be unclean", isUnclean( snapshot ) ); PageCache pageCache = pageCacheRule.getPageCache( snapshot ); new StoreAccess( snapshot, pageCache, testDirectory.databaseLayout(), Config.defaults() ).initialize().close(); assertTrue( "Store should be unclean", isUnclean( snapshot ) ); } }
@Test public void indexMustBeDirtyWhenCrashedWithChangesSinceLastCheckpoint() throws Exception { // GIVEN try ( EphemeralFileSystemAbstraction ephemeralFs = new EphemeralFileSystemAbstraction() ) { ephemeralFs.mkdirs( indexFile.getParentFile() ); PageCache pageCache = pageCacheRule.getPageCache( ephemeralFs ); EphemeralFileSystemAbstraction snapshot; try ( GBPTree<MutableLong, MutableLong> index = index( pageCache ).build() ) { insert( index, 0, 1 ); // WHEN // crash snapshot = ephemeralFs.snapshot(); } pageCache.close(); // THEN MonitorDirty monitorDirty = new MonitorDirty(); pageCache = pageCacheRule.getPageCache( snapshot ); try ( GBPTree<MutableLong, MutableLong> ignored = index( pageCache ).with( monitorDirty ).build() ) { } assertFalse( "Expected to be dirty on start after crash", monitorDirty.cleanOnStart() ); } }