Search in sources :

Example 16 with DatabaseHealth

use of org.neo4j.monitoring.DatabaseHealth in project neo4j by neo4j.

the class LogFilesBuilderTest method buildDefaultContextWithDependencies.

@Test
void buildDefaultContextWithDependencies() throws IOException {
    SimpleLogVersionRepository logVersionRepository = new SimpleLogVersionRepository(2);
    SimpleTransactionIdStore transactionIdStore = new SimpleTransactionIdStore();
    DatabaseHealth databaseHealth = new DatabaseHealth(PanicEventGenerator.NO_OP, NullLog.getInstance());
    Dependencies dependencies = new Dependencies();
    dependencies.satisfyDependency(logVersionRepository);
    dependencies.satisfyDependency(transactionIdStore);
    dependencies.satisfyDependency(databaseHealth);
    TransactionLogFilesContext context = builder(databaseLayout, fileSystem).withDependencies(dependencies).withLogEntryReader(logEntryReader()).buildContext();
    assertEquals(fileSystem, context.getFileSystem());
    assertNotNull(context.getLogEntryReader());
    assertEquals(ByteUnit.mebiBytes(250), context.getRotationThreshold().get());
    assertEquals(databaseHealth, context.getDatabaseHealth());
    assertEquals(1, context.getLastCommittedTransactionId());
    assertEquals(2, context.getLogVersionRepository().getCurrentLogVersion());
}
Also used : DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) Dependencies(org.neo4j.collection.Dependencies) Test(org.junit.jupiter.api.Test)

Example 17 with DatabaseHealth

use of org.neo4j.monitoring.DatabaseHealth in project neo4j by neo4j.

the class RecordStorageEngineTest method panicOnExceptionDuringCommandsApply.

@Test
void panicOnExceptionDuringCommandsApply() {
    IllegalStateException failure = new IllegalStateException("Too many open files");
    RecordStorageEngine engine = storageEngineRule.getWith(fs, pageCache, databaseLayout).databaseHealth(databaseHealth).transactionApplierTransformer(facade -> transactionApplierFacadeTransformer(facade, failure)).build();
    CommandsToApply commandsToApply = mock(CommandsToApply.class);
    var exception = assertThrows(Exception.class, () -> engine.apply(commandsToApply, TransactionApplicationMode.INTERNAL));
    assertSame(failure, getRootCause(exception));
    verify(databaseHealth).panic(any(Throwable.class));
}
Also used : Visitor(org.neo4j.internal.helpers.collection.Visitor) BeforeEach(org.junit.jupiter.api.BeforeEach) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) Status(org.neo4j.kernel.api.exceptions.Status) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) IdUpdateListener(org.neo4j.kernel.impl.store.IdUpdateListener) Mockito.doThrow(org.mockito.Mockito.doThrow) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) EXCLUSIVE(org.neo4j.lock.LockType.EXCLUSIVE) Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) Collection(java.util.Collection) Set(java.util.Set) LockService(org.neo4j.lock.LockService) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) EphemeralNeo4jLayoutExtension(org.neo4j.test.extension.EphemeralNeo4jLayoutExtension) Mockito.inOrder(org.mockito.Mockito.inOrder) CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) Mockito.mock(org.mockito.Mockito.mock) Lock(org.neo4j.lock.Lock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ArrayList(java.util.ArrayList) StorageCommand(org.neo4j.storageengine.api.StorageCommand) RecordStorageEngineRule(org.neo4j.test.rule.RecordStorageEngineRule) ArgumentCaptor(org.mockito.ArgumentCaptor) Inject(org.neo4j.test.extension.Inject) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InOrder(org.mockito.InOrder) ExceptionUtils.getRootCause(org.apache.commons.lang3.exception.ExceptionUtils.getRootCause) IOException(java.io.IOException) Health(org.neo4j.monitoring.Health) Mockito.when(org.mockito.Mockito.when) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) EphemeralPageCacheExtension(org.neo4j.test.extension.pagecache.EphemeralPageCacheExtension) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) AfterEach(org.junit.jupiter.api.AfterEach) KernelException(org.neo4j.exceptions.KernelException) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Timeout(org.junit.jupiter.api.Timeout) CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseHealth (org.neo4j.monitoring.DatabaseHealth)17 Test (org.junit.jupiter.api.Test)12 Health (org.neo4j.monitoring.Health)9 IOException (java.io.IOException)7 DatabasePanicEventGenerator (org.neo4j.kernel.monitoring.DatabasePanicEventGenerator)6 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)5 Dependencies (org.neo4j.collection.Dependencies)4 LogRotation (org.neo4j.kernel.impl.transaction.log.rotation.LogRotation)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2 Config (org.neo4j.configuration.Config)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 FileSystemLifecycleAdapter (org.neo4j.io.fs.FileSystemLifecycleAdapter)2 TestCommandReaderFactory (org.neo4j.kernel.impl.api.TestCommandReaderFactory)2 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)2 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)2