use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.
the class NeoStoreDataSourceTest method databaseHealthShouldBeHealedOnStart.
@Test
public void databaseHealthShouldBeHealedOnStart() throws Throwable {
NeoStoreDataSource theDataSource = null;
try {
DatabaseHealth databaseHealth = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLogProvider.getInstance().getLog(DatabaseHealth.class));
theDataSource = dsRule.getDataSource(dir.graphDbDir(), fs.get(), pageCacheRule.getPageCache(fs.get()), stringMap(), databaseHealth);
databaseHealth.panic(new Throwable());
theDataSource.start();
databaseHealth.assertHealthy(Throwable.class);
} finally {
if (theDataSource != null) {
theDataSource.stop();
theDataSource.shutdown();
}
}
}
use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.
the class NeoStoreDataSourceTest method flushOfThePageCacheOnShutdownDoesNotHappenIfTheDbIsUnhealthy.
@Test
public void flushOfThePageCacheOnShutdownDoesNotHappenIfTheDbIsUnhealthy() throws IOException {
DatabaseHealth health = mock(DatabaseHealth.class);
when(health.isHealthy()).thenReturn(false);
PageCache pageCache = spy(pageCacheRule.getPageCache(fs.get()));
NeoStoreDataSource ds = dsRule.getDataSource(dir.graphDbDir(), fs.get(), pageCache, stringMap(), health);
ds.init();
ds.start();
verify(pageCache, never()).flushAndForce();
ds.stop();
ds.shutdown();
verify(pageCache, never()).flushAndForce(IOLimiter.unlimited());
}
use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.
the class NeoStoreDataSourceTest method flushOfThePageCacheOnShutdownHappensIfTheDbIsHealthy.
@Test
public void flushOfThePageCacheOnShutdownHappensIfTheDbIsHealthy() throws IOException {
DatabaseHealth health = mock(DatabaseHealth.class);
when(health.isHealthy()).thenReturn(true);
PageCache pageCache = spy(pageCacheRule.getPageCache(fs.get()));
NeoStoreDataSource ds = dsRule.getDataSource(dir.graphDbDir(), fs.get(), pageCache, stringMap(), health);
ds.init();
ds.start();
verify(pageCache, never()).flushAndForce();
ds.stop();
ds.shutdown();
verify(pageCache).flushAndForce(IOLimiter.unlimited());
}
use of org.neo4j.kernel.internal.DatabaseHealth in project neo4j by neo4j.
the class TransactionLogAppendAndRotateIT method shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending.
@Test
public void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable {
// GIVEN
PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory().getAbsoluteFile(), fileSystemRule.get());
long rotationThreshold = mebiBytes(1);
LogVersionRepository logVersionRepository = new DeadSimpleLogVersionRepository(0);
final AtomicBoolean end = new AtomicBoolean();
AllTheMonitoring monitoring = new AllTheMonitoring(end, 100);
TransactionIdStore txIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache metadataCache = new TransactionMetadataCache(100);
LogHeaderCache logHeaderCache = new LogHeaderCache(10);
LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, rotationThreshold, () -> txIdStore.getLastCommittedTransactionId(), logVersionRepository, monitoring, logHeaderCache));
monitoring.setLogFile(logFile);
DatabaseHealth health = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLog.getInstance());
LogRotation rotation = new LogRotationImpl(monitoring, logFile, health);
final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, rotation, metadataCache, txIdStore, BYPASS, health));
// WHEN
Race race = new Race();
for (int i = 0; i < 10; i++) {
race.addContestant(new Runnable() {
@Override
public void run() {
while (!end.get()) {
try {
appender.append(new TransactionToApply(sillyTransaction(1_000)), NULL);
} catch (Exception e) {
e.printStackTrace(System.out);
end.set(true);
fail(e.getMessage());
}
}
}
});
}
race.addContestant(endAfterMax(10, SECONDS, end));
race.go();
// THEN
assertTrue(monitoring.numberOfRotations() > 0);
}
Aggregations