Search in sources :

Example 16 with DependencyResolver

use of org.neo4j.common.DependencyResolver in project neo4j by neo4j.

the class FileWatchIT method doNotNotifyAboutIndexFilesDeletion.

@Test
void doNotNotifyAboutIndexFilesDeletion() throws IOException, InterruptedException {
    DependencyResolver dependencyResolver = ((GraphDatabaseAPI) database).getDependencyResolver();
    FileWatcher fileWatcher = getFileWatcher(database);
    CheckPointer checkPointer = dependencyResolver.resolveDependency(CheckPointer.class);
    String propertyStoreName = databaseLayout.propertyStore().getFileName().toString();
    AccumulativeDeletionEventListener accumulativeListener = new AccumulativeDeletionEventListener();
    ModificationEventListener modificationListener = new ModificationEventListener(propertyStoreName);
    fileWatcher.addFileWatchEventListener(modificationListener);
    fileWatcher.addFileWatchEventListener(accumulativeListener);
    String labelName = "labelName";
    String propertyName = "propertyName";
    Label testLabel = Label.label(labelName);
    createIndexes(database, propertyName, testLabel);
    do {
        createNode(database, propertyName, testLabel);
        forceCheckpoint(checkPointer);
    } while (!modificationListener.awaitModificationNotification());
    fileWatcher.removeFileWatchEventListener(modificationListener);
    ModificationEventListener afterRemovalListener = new ModificationEventListener(propertyStoreName);
    fileWatcher.addFileWatchEventListener(afterRemovalListener);
    dropAllIndexes(database);
    do {
        createNode(database, propertyName, testLabel);
        forceCheckpoint(checkPointer);
    } while (!afterRemovalListener.awaitModificationNotification());
    accumulativeListener.assertDoesNotHaveAnyDeletions();
}
Also used : FileWatcher(org.neo4j.io.fs.watcher.FileWatcher) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.common.DependencyResolver) Test(org.junit.jupiter.api.Test)

Example 17 with DependencyResolver

use of org.neo4j.common.DependencyResolver in project neo4j by neo4j.

the class CheckerTestBase method context.

CheckerContext context(int numberOfThreads, ConsistencyFlags consistencyFlags, ConsistencySummaryStatistics inconsistenciesSummary) throws Exception {
    if (context != null) {
        return context;
    }
    // We do this as late as possible because of how it eagerly caches which indexes exist so if the test creates an index
    // this lazy instantiation allows the context to pick it up
    Config config = Config.defaults(neo4j_home, directory.homePath());
    DependencyResolver dependencies = db.getDependencyResolver();
    IndexProviderMap indexProviders = dependencies.resolveDependency(IndexProviderMap.class);
    IndexingService indexingService = dependencies.resolveDependency(IndexingService.class);
    IndexAccessors indexAccessors = new IndexAccessors(indexProviders, neoStores, new IndexSamplingConfig(config), new LookupAccessorsFromRunningDb(indexingService), PageCacheTracer.NULL, tokenHolders, neoStores.getMetaDataStore());
    InconsistencyReport report = new InconsistencyReport(new InconsistencyMessageLogger(NullLog.getInstance()), inconsistenciesSummary);
    monitor = mock(ConsistencyReporter.Monitor.class);
    reporter = new ConsistencyReporter(report, monitor);
    countsState = new CountsState(neoStores, cacheAccess, INSTANCE);
    NodeBasedMemoryLimiter limiter = new NodeBasedMemoryLimiter(pageCache.pageSize() * pageCache.maxCachedPages(), Runtime.getRuntime().maxMemory(), Long.MAX_VALUE, CacheSlots.CACHE_LINE_SIZE_BYTES, nodeStore.getHighId(), 1);
    ProgressMonitorFactory.MultiPartBuilder progress = ProgressMonitorFactory.NONE.multipleParts("Test");
    ParallelExecution execution = new ParallelExecution(numberOfThreads, NOOP_EXCEPTION_HANDLER, IDS_PER_CHUNK);
    context = new CheckerContext(neoStores, indexAccessors, execution, reporter, cacheAccess, tokenHolders, new RecordLoading(neoStores), countsState, limiter, progress, pageCache, PageCacheTracer.NULL, INSTANCE, DebugContext.NO_DEBUG, consistencyFlags);
    context.initialize();
    return context;
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.IndexSamplingConfig) IndexAccessors(org.neo4j.consistency.checking.index.IndexAccessors) InconsistencyReport(org.neo4j.consistency.report.InconsistencyReport) ConsistencyReporter(org.neo4j.consistency.report.ConsistencyReporter) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) Config(org.neo4j.configuration.Config) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.IndexSamplingConfig) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap) DependencyResolver(org.neo4j.common.DependencyResolver) LookupAccessorsFromRunningDb(org.neo4j.consistency.LookupAccessorsFromRunningDb) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) InconsistencyMessageLogger(org.neo4j.consistency.report.InconsistencyMessageLogger)

Example 18 with DependencyResolver

use of org.neo4j.common.DependencyResolver in project neo4j by neo4j.

the class HttpStructuredLoggingIT method shouldLogRequestsInStructuredFormat.

@Test
public void shouldLogRequestsInStructuredFormat() throws Exception {
    var bootstrapper = new CommunityBootstrapper();
    HttpResponse<String> response;
    Path httpLogPath;
    try {
        bootstrapper.start(folder.homePath(), Map.of(HttpConnector.listen_address.name(), "localhost:0", ServerSettings.http_log_format.name(), FormattedLogFormat.JSON.name(), ServerSettings.http_logging_enabled.name(), TRUE, HttpConnector.enabled.name(), TRUE));
        var dependencyResolver = getDependencyResolver(bootstrapper.getDatabaseManagementService());
        var baseUri = dependencyResolver.resolveDependency(AbstractNeoWebServer.class).getBaseUri();
        var config = dependencyResolver.resolveDependency(Config.class);
        var request = HttpRequest.newBuilder().uri(baseUri).timeout(Duration.ofSeconds(10)).header("Accept", "application/json").header("User-Agent", HttpStructuredLoggingIT.class.getSimpleName()).GET().build();
        // Just ask the discovery api for a response we don't actually care of
        httpLogPath = config.get(ServerSettings.http_log_path);
        response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
    } finally {
        bootstrapper.stop();
        // Make sure the log manager flushes everything.
        LogManager.shutdown();
    }
    assertThat(response.statusCode()).isEqualTo(200);
    var httpLogLines = Files.readAllLines(httpLogPath).stream().map(s -> {
        try {
            return OBJECT_MAPPER.readValue(s, MAP_TYPE);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());
    assertThat(httpLogLines).anyMatch(logEntry -> logEntry.getOrDefault("message", "").contains(HttpStructuredLoggingIT.class.getSimpleName()));
}
Also used : Path(java.nio.file.Path) ExclusiveWebContainerTestBase(org.neo4j.test.server.ExclusiveWebContainerTestBase) ServerSettings(org.neo4j.server.configuration.ServerSettings) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) HttpRequest(java.net.http.HttpRequest) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) HttpConnector(org.neo4j.configuration.connectors.HttpConnector) Duration(java.time.Duration) Map(java.util.Map) HttpClient(java.net.http.HttpClient) AbstractNeoWebServer(org.neo4j.server.AbstractNeoWebServer) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) DependencyResolver(org.neo4j.common.DependencyResolver) HttpResponse(java.net.http.HttpResponse) Files(java.nio.file.Files) FormattedLogFormat(org.neo4j.logging.FormattedLogFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityBootstrapper(org.neo4j.server.CommunityBootstrapper) TRUE(org.neo4j.configuration.SettingValueParsers.TRUE) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) LogManager(org.apache.logging.log4j.LogManager) AbstractNeoWebServer(org.neo4j.server.AbstractNeoWebServer) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CommunityBootstrapper(org.neo4j.server.CommunityBootstrapper) Test(org.junit.Test)

Example 19 with DependencyResolver

use of org.neo4j.common.DependencyResolver in project neo4j by neo4j.

the class FullCheckTokenIndexIT method updateNodeLabelIndex.

void updateNodeLabelIndex(GraphDatabaseAPI database, IndexDescriptor index) throws IOException, IndexEntryConflictException {
    DependencyResolver dependencyResolver = database.getDependencyResolver();
    IndexingService indexingService = dependencyResolver.resolveDependency(IndexingService.class);
    IndexAccessors.IndexAccessorLookup indexAccessorLookup = new LookupAccessorsFromRunningDb(indexingService);
    IndexAccessor accessor = indexAccessorLookup.apply(index);
    try (IndexUpdater indexUpdater = accessor.newUpdater(IndexUpdateMode.ONLINE, CursorContext.NULL)) {
        indexUpdater.process(IndexEntryUpdate.change(100, index, new long[0], new long[] { 1 }));
    }
}
Also used : LookupAccessorsFromRunningDb(org.neo4j.consistency.LookupAccessorsFromRunningDb) IndexAccessors(org.neo4j.consistency.checking.index.IndexAccessors) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) DependencyResolver(org.neo4j.common.DependencyResolver)

Example 20 with DependencyResolver

use of org.neo4j.common.DependencyResolver in project neo4j by neo4j.

the class SecurityProcedureQueryTypeTest method beforeAll.

@BeforeAll
static void beforeAll() {
    databaseManagementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setConfig(GraphDatabaseSettings.auth_enabled, true).build();
    DependencyResolver dependencyResolver = ((GraphDatabaseFacade) databaseManagementService.database("system")).getDependencyResolver();
    planner = dependencyResolver.resolveDependency(FabricPlanner.class);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) DependencyResolver(org.neo4j.common.DependencyResolver) FabricPlanner(org.neo4j.fabric.planning.FabricPlanner) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

DependencyResolver (org.neo4j.common.DependencyResolver)41 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)13 Config (org.neo4j.configuration.Config)12 Test (org.junit.jupiter.api.Test)10 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)8 DatabaseContext (org.neo4j.dbms.database.DatabaseContext)6 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)5 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)5 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)4 SystemGraphComponents (org.neo4j.dbms.database.SystemGraphComponents)3 Transaction (org.neo4j.graphdb.Transaction)3 IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)3 PageCache (org.neo4j.io.pagecache.PageCache)3 CheckPointer (org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer)3 SimpleTriggerInfo (org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo)3 TokenHolders (org.neo4j.token.TokenHolders)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2