Search in sources :

Example 1 with ReporterFactory

use of org.neo4j.annotations.documented.ReporterFactory in project neo4j by neo4j.

the class LuceneIndexAccessorTest method indexReportInconsistencyToVisitor.

@Test
void indexReportInconsistencyToVisitor() {
    when(schemaIndex.isValid()).thenReturn(false);
    MutableBoolean called = new MutableBoolean();
    final InvocationHandler handler = (proxy, method, args) -> {
        called.setTrue();
        return null;
    };
    assertFalse(accessor.consistencyCheck(new ReporterFactory(handler), NULL), "Expected index to be inconsistent");
    assertTrue(called.booleanValue(), "Expected visitor to be called");
}
Also used : ReporterFactories(org.neo4j.annotations.documented.ReporterFactories) BeforeEach(org.junit.jupiter.api.BeforeEach) ReporterFactory(org.neo4j.annotations.documented.ReporterFactory) Mockito.when(org.mockito.Mockito.when) Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) InvocationHandler(java.lang.reflect.InvocationHandler) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Mockito.mock(org.mockito.Mockito.mock) SIMPLE_TOKEN_LOOKUP(org.neo4j.kernel.api.impl.schema.LuceneTestTokenNameLookup.SIMPLE_TOKEN_LOOKUP) ReporterFactory(org.neo4j.annotations.documented.ReporterFactory) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) InvocationHandler(java.lang.reflect.InvocationHandler) Test(org.junit.jupiter.api.Test)

Example 2 with ReporterFactory

use of org.neo4j.annotations.documented.ReporterFactory in project neo4j by neo4j.

the class RecoveryIT method idGeneratorIsDirty.

private boolean idGeneratorIsDirty(Path path, IdType idType) throws IOException {
    DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), "my db");
    try (IdGenerator idGenerator = idGeneratorFactory.open(pageCache, path, idType, () -> 0L, /*will not be used*/
    10_000, readOnly(), Config.defaults(), NULL, Sets.immutable.empty())) {
        MutableBoolean dirtyOnStartup = new MutableBoolean();
        InvocationHandler invocationHandler = (proxy, method, args) -> {
            if (method.getName().equals("dirtyOnStartup")) {
                dirtyOnStartup.setTrue();
            }
            return null;
        };
        ReporterFactory reporterFactory = new ReporterFactory(invocationHandler);
        idGenerator.consistencyCheck(reporterFactory, NULL);
        return dirtyOnStartup.booleanValue();
    }
}
Also used : LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) MetaDataStore.getRecord(org.neo4j.kernel.impl.store.MetaDataStore.getRecord) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) GraphDatabaseSettings.fail_on_missing_files(org.neo4j.configuration.GraphDatabaseSettings.fail_on_missing_files) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ReporterFactory(org.neo4j.annotations.documented.ReporterFactory) LogFilesBuilder(org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder) Config(org.neo4j.configuration.Config) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Recovery.performRecovery(org.neo4j.kernel.recovery.Recovery.performRecovery) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) GraphDatabaseSettings.logical_log_rotation_threshold(org.neo4j.configuration.GraphDatabaseSettings.logical_log_rotation_threshold) LogCheckPointEvent(org.neo4j.kernel.impl.transaction.tracing.LogCheckPointEvent) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Monitors(org.neo4j.monitoring.Monitors) CHECKPOINT_LOG_VERSION(org.neo4j.kernel.impl.store.MetaDataStore.Position.CHECKPOINT_LOG_VERSION) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Transaction(org.neo4j.graphdb.Transaction) Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) LAST_MISSING_STORE_FILES_RECOVERY_TIMESTAMP(org.neo4j.kernel.impl.store.MetaDataStore.Position.LAST_MISSING_STORE_FILES_RECOVERY_TIMESTAMP) DEFAULT_NAME(org.neo4j.kernel.impl.transaction.log.files.TransactionLogFilesHelper.DEFAULT_NAME) LegacyTransactionLogsLocator(org.neo4j.kernel.impl.storemigration.LegacyTransactionLogsLocator) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) CompositeDatabaseAvailabilityGuard(org.neo4j.kernel.availability.CompositeDatabaseAvailabilityGuard) RelationshipType.withName(org.neo4j.graphdb.RelationshipType.withName) Instant(java.time.Instant) ArrayUtil(org.neo4j.internal.helpers.ArrayUtil) Services(org.neo4j.service.Services) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.jupiter.api.Test) IdType(org.neo4j.internal.id.IdType) IndexQueryConstraints.unconstrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.unconstrained) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) ExtensionContext(org.neo4j.kernel.extension.context.ExtensionContext) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) DatabaseStartAbortedException(org.neo4j.dbms.database.DatabaseStartAbortedException) RelationshipType(org.neo4j.graphdb.RelationshipType) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Label(org.neo4j.graphdb.Label) Config.defaults(org.neo4j.configuration.Config.defaults) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) DatabaseTracer(org.neo4j.kernel.impl.transaction.tracing.DatabaseTracer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Node(org.neo4j.graphdb.Node) IndexType(org.neo4j.graphdb.schema.IndexType) GraphDatabaseSettings.preallocate_logical_logs(org.neo4j.configuration.GraphDatabaseSettings.preallocate_logical_logs) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) PropertyIndexQuery.fulltextSearch(org.neo4j.internal.kernel.api.PropertyIndexQuery.fulltextSearch) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Inject(org.neo4j.test.extension.Inject) StorageEngineFactory.defaultStorageEngine(org.neo4j.storageengine.api.StorageEngineFactory.defaultStorageEngine) Iterables(org.neo4j.internal.helpers.collection.Iterables) IdGenerator(org.neo4j.internal.id.IdGenerator) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EMPTY(org.neo4j.kernel.database.DatabaseTracers.EMPTY) Sets(org.eclipse.collections.api.factory.Sets) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) NullLogProvider.nullLogProvider(org.neo4j.logging.NullLogProvider.nullLogProvider) BASE_TX_LOG_BYTE_OFFSET(org.neo4j.storageengine.api.LogVersionRepository.BASE_TX_LOG_BYTE_OFFSET) DetachedCheckpointAppender(org.neo4j.kernel.impl.transaction.log.checkpoint.DetachedCheckpointAppender) ByteUnit(org.neo4j.io.ByteUnit) LockTracer(org.neo4j.lock.LockTracer) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) Iterables.count(org.neo4j.internal.helpers.collection.Iterables.count) RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) ExceptionUtils.getRootCause(org.apache.commons.lang3.exception.ExceptionUtils.getRootCause) IOException(java.io.IOException) Neo4jLayout(org.neo4j.io.layout.Neo4jLayout) DatabaseTracers(org.neo4j.kernel.database.DatabaseTracers) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) ExtensionFactory(org.neo4j.kernel.extension.ExtensionFactory) Relationship(org.neo4j.graphdb.Relationship) String.valueOf(java.lang.String.valueOf) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Clock(java.time.Clock) InvocationHandler(java.lang.reflect.InvocationHandler) ReporterFactory(org.neo4j.annotations.documented.ReporterFactory) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IdGenerator(org.neo4j.internal.id.IdGenerator) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 3 with ReporterFactory

use of org.neo4j.annotations.documented.ReporterFactory in project neo4j by neo4j.

the class FullCheck method consistencyCheckSchemaIndexes.

private static void consistencyCheckSchemaIndexes(IndexAccessors indexes, InconsistencyReport report, ProgressListener listener, CursorContext cursorContext) {
    List<IndexDescriptor> rulesToRemove = new ArrayList<>();
    for (IndexDescriptor onlineRule : indexes.onlineRules()) {
        ConsistencyReporter.FormattingDocumentedHandler handler = ConsistencyReporter.formattingHandler(report, RecordType.INDEX);
        ReporterFactory reporterFactory = new ReporterFactory(handler);
        IndexAccessor accessor = indexes.accessorFor(onlineRule);
        if (!accessor.consistencyCheck(reporterFactory, cursorContext)) {
            rulesToRemove.add(onlineRule);
        }
        handler.updateSummary();
        listener.add(1);
    }
    for (IndexDescriptor toRemove : rulesToRemove) {
        indexes.remove(toRemove);
    }
}
Also used : ReporterFactory(org.neo4j.annotations.documented.ReporterFactory) ConsistencyReporter(org.neo4j.consistency.report.ConsistencyReporter) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 4 with ReporterFactory

use of org.neo4j.annotations.documented.ReporterFactory in project neo4j by neo4j.

the class FullCheck method consistencyCheckSingleCheckable.

private static void consistencyCheckSingleCheckable(InconsistencyReport report, ProgressListener listener, ConsistencyCheckable checkable, RecordType recordType, CursorContext cursorContext) {
    ConsistencyReporter.FormattingDocumentedHandler handler = ConsistencyReporter.formattingHandler(report, recordType);
    ReporterFactory proxyFactory = new ReporterFactory(handler);
    checkable.consistencyCheck(proxyFactory, cursorContext);
    handler.updateSummary();
    listener.add(1);
}
Also used : ReporterFactory(org.neo4j.annotations.documented.ReporterFactory) ConsistencyReporter(org.neo4j.consistency.report.ConsistencyReporter)

Aggregations

ReporterFactory (org.neo4j.annotations.documented.ReporterFactory)4 InvocationHandler (java.lang.reflect.InvocationHandler)2 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 Test (org.junit.jupiter.api.Test)2 ConsistencyReporter (org.neo4j.consistency.report.ConsistencyReporter)2 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2 NULL (org.neo4j.io.pagecache.context.CursorContext.NULL)2 IOException (java.io.IOException)1 String.valueOf (java.lang.String.valueOf)1 Path (java.nio.file.Path)1 Clock (java.time.Clock)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 MINUTES (java.util.concurrent.TimeUnit.MINUTES)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric)1 ExceptionUtils.getRootCause (org.apache.commons.lang3.exception.ExceptionUtils.getRootCause)1