@Test public void shouldGenerateDatabasePanicEvents() { // GIVEN DatabasePanicEventGenerator generator = mock( DatabasePanicEventGenerator.class ); DatabaseHealth databaseHealth = new DatabaseHealth( generator, NullLogProvider.getInstance().getLog( DatabaseHealth.class ) ); databaseHealth.healed(); // WHEN Exception cause = new Exception( "My own fault" ); databaseHealth.panic( cause ); databaseHealth.panic( cause ); // THEN verify( generator, times( 1 ) ).generateEvent( TX_MANAGER_NOT_OK, cause ); }
@Test public void databaseWithCriticalErrorsCanNotBeHealed() { AssertableLogProvider logProvider = new AssertableLogProvider(); DatabaseHealth databaseHealth = new DatabaseHealth( mock( DatabasePanicEventGenerator.class ), logProvider.getLog( DatabaseHealth.class ) ); assertTrue( databaseHealth.isHealthy() ); IOException criticalException = new IOException( "Space exception.", new OutOfMemoryError( "Out of memory." ) ); databaseHealth.panic( criticalException ); assertFalse( databaseHealth.isHealthy() ); assertFalse( databaseHealth.healed() ); logProvider.assertNoMessagesContaining( "Database health set to OK" ); logProvider.assertContainsLogCallContaining( "Database encountered a critical error and can't be healed. Restart required." ); } }
private static BatchingTransactionAppender createBatchingTransactionAppender( TransactionIdStore transactionIdStore, TransactionMetadataCache transactionMetadataCache, LogFiles logFiles ) { Log log = NullLog.getInstance(); KernelEventHandlers kernelEventHandlers = new KernelEventHandlers( log ); DatabasePanicEventGenerator panicEventGenerator = new DatabasePanicEventGenerator( kernelEventHandlers ); DatabaseHealth databaseHealth = new DatabaseHealth( panicEventGenerator, log ); LogRotationImpl logRotation = new LogRotationImpl( NOOP_LOGROTATION_MONITOR, logFiles, databaseHealth ); return new BatchingTransactionAppender( logFiles, logRotation, transactionMetadataCache, transactionIdStore, IdOrderingQueue.BYPASS, databaseHealth ); }
private static DatabaseHealth getDatabaseHealth() { DatabasePanicEventGenerator databasePanicEventGenerator = new DatabasePanicEventGenerator( new KernelEventHandlers( NullLog.getInstance() ) ); return new DatabaseHealth( databasePanicEventGenerator, NullLog.getInstance() ); }
@Test public void shouldLogDatabasePanicEvent() { // GIVEN AssertableLogProvider logProvider = new AssertableLogProvider(); DatabaseHealth databaseHealth = new DatabaseHealth( mock( DatabasePanicEventGenerator.class ), logProvider.getLog( DatabaseHealth.class ) ); databaseHealth.healed(); // WHEN String message = "Listen everybody... panic!"; Exception exception = new Exception( message ); databaseHealth.panic( exception ); // THEN logProvider.assertAtLeastOnce( inLog( DatabaseHealth.class ).error( is( "Database panic: The database has encountered a critical error, " + "and needs to be restarted. Please see database logs for more details." ), sameInstance( exception ) ) ); }
@Test public void healDatabaseWithoutCriticalErrors() { AssertableLogProvider logProvider = new AssertableLogProvider(); DatabaseHealth databaseHealth = new DatabaseHealth( mock( DatabasePanicEventGenerator.class ), logProvider.getLog( DatabaseHealth.class ) ); assertTrue( databaseHealth.isHealthy() ); databaseHealth.panic( new IOException( "Space exception." ) ); assertFalse( databaseHealth.isHealthy() ); assertTrue( databaseHealth.healed() ); logProvider.assertContainsLogCallContaining( "Database health set to OK" ); logProvider.assertNoMessagesContaining( "Database encountered a critical error and can't be healed. Restart required." ); }
@Test public void databaseHealthShouldBeHealedOnStart() throws Throwable { NeoStoreDataSource theDataSource = null; try { DatabaseHealth databaseHealth = new DatabaseHealth( mock( DatabasePanicEventGenerator.class ), NullLogProvider.getInstance().getLog( DatabaseHealth.class ) ); Dependencies dependencies = new Dependencies(); dependencies.satisfyDependency( databaseHealth ); theDataSource = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCacheRule.getPageCache( fs.get() ), dependencies ); databaseHealth.panic( new Throwable() ); theDataSource.start(); databaseHealth.assertHealthy( Throwable.class ); } finally { if ( theDataSource != null ) { theDataSource.stop(); theDataSource.shutdown(); } } }
IdTypeConfigurationProvider.class, deps -> new CommunityIdTypeConfigurationProvider() ); DatabaseHealth databaseHealth = dependency( mutableDependencies, DatabaseHealth.class, deps -> new DatabaseHealth( mock( DatabasePanicEventGenerator.class ), NullLog.getInstance() ) ); SystemNanoClock clock = dependency( mutableDependencies, SystemNanoClock.class, deps -> Clocks.nanoClock() ); TransactionMonitor transactionMonitor = dependency( mutableDependencies, TransactionMonitor.class,
FileSystemAbstraction fs = new AdversarialFileSystemAbstraction( adversary, efs ); life.add( new FileSystemLifecycleAdapter( fs ) ); DatabaseHealth databaseHealth = new DatabaseHealth( mock( DatabasePanicEventGenerator.class ), NullLog.getInstance() ); LogFiles logFiles = LogFilesBuilder.builder( testDirectory.databaseLayout(), fs ) .withLogVersionRepository( logVersionRepository )
this.fs = platformModule.fileSystem; this.transactionStats = editionContext.createTransactionMonitor(); this.databaseHealth = new DatabaseHealth( platformModule.panicEventGenerator, logService.getInternalLog( DatabaseHealth.class ) ); this.transactionHeaderInformationFactory = editionContext.getHeaderInformationFactory(); this.commitProcessFactory = editionContext.getCommitProcessFactory();
this.fs = platformModule.fileSystem; this.transactionStats = editionContext.createTransactionMonitor(); this.databaseHealth = new DatabaseHealth( platformModule.panicEventGenerator, logService.getInternalLog( DatabaseHealth.class ) ); this.transactionHeaderInformationFactory = editionContext.getHeaderInformationFactory(); this.commitProcessFactory = editionContext.getCommitProcessFactory();