Search in sources :

Example 26 with DependencyResolver

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

the class BoltFactoryImplTest method newDbMock.

private static GraphDatabaseAPI newDbMock() {
    GraphDatabaseAPI db = mock(GraphDatabaseAPI.class);
    DependencyResolver dependencyResolver = mock(DependencyResolver.class);
    when(db.getDependencyResolver()).thenReturn(dependencyResolver);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    when(queryService.getDependencyResolver()).thenReturn(dependencyResolver);
    when(dependencyResolver.resolveDependency(GraphDatabaseQueryService.class)).thenReturn(queryService);
    return db;
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 27 with DependencyResolver

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

the class ReadReplicaStoreCopyIT method addStoreCopyBlockingMonitor.

private static Semaphore addStoreCopyBlockingMonitor(ReadReplica readReplica) {
    DependencyResolver dependencyResolver = readReplica.database().getDependencyResolver();
    Monitors monitors = dependencyResolver.resolveDependency(Monitors.class);
    Semaphore semaphore = new Semaphore(0);
    monitors.addMonitorListener((FileCopyMonitor) file -> {
        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }
    });
    return semaphore;
}
Also used : FALSE(org.neo4j.kernel.configuration.Settings.FALSE) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) Monitors(org.neo4j.kernel.monitoring.Monitors) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) Assert.assertThat(org.junit.Assert.assertThat) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Assert.fail(org.junit.Assert.fail) FileCopyMonitor(org.neo4j.causalclustering.catchup.tx.FileCopyMonitor) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) IOException(java.io.IOException) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) Cluster(org.neo4j.causalclustering.discovery.Cluster) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) UncheckedIOException(java.io.UncheckedIOException) TimeUnit(java.util.concurrent.TimeUnit) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Rule(org.junit.Rule) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Matchers.is(org.hamcrest.Matchers.is) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) Matchers.containsString(org.hamcrest.Matchers.containsString) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) Monitors(org.neo4j.kernel.monitoring.Monitors) Semaphore(java.util.concurrent.Semaphore) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 28 with DependencyResolver

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

the class ReadReplicaStoreCopyIT method forceLogRotationAndPruning.

private static void forceLogRotationAndPruning(CoreClusterMember core) {
    try {
        DependencyResolver dependencyResolver = core.database().getDependencyResolver();
        dependencyResolver.resolveDependency(LogRotation.class).rotateLogFile();
        SimpleTriggerInfo info = new SimpleTriggerInfo("test");
        dependencyResolver.resolveDependency(CheckPointer.class).forceCheckPoint(info);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) UncheckedIOException(java.io.UncheckedIOException) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 29 with DependencyResolver

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

the class GraphDatabaseFacade method init.

/**
     * Create a new Core API facade, backed by the given SPI.
     *
     * Any required dependencies are resolved using the resolver obtained from the SPI.
     */
public final void init(SPI spi) {
    DependencyResolver resolver = spi.resolver();
    init(spi, resolver.resolveDependency(Guard.class), resolver.resolveDependency(ThreadToStatementContextBridge.class), resolver.resolveDependency(Config.class));
}
Also used : Config(org.neo4j.kernel.configuration.Config) Guard(org.neo4j.kernel.guard.Guard) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 30 with DependencyResolver

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

the class DetectAllRelationshipInconsistenciesIT method shouldDetectSabotagedRelationshipWhereEverItIs.

@Test
public void shouldDetectSabotagedRelationshipWhereEverItIs() throws Exception {
    // GIVEN a database which lots of relationships
    GraphDatabaseAPI db = getGraphDatabaseAPI();
    Sabotage sabotage;
    try {
        Node[] nodes = new Node[1_000];
        Relationship[] relationships = new Relationship[10_000];
        try (Transaction tx = db.beginTx()) {
            for (int i = 0; i < nodes.length; i++) {
                nodes[i] = db.createNode(label("Foo"));
            }
            for (int i = 0; i < 10_000; i++) {
                relationships[i] = random.among(nodes).createRelationshipTo(random.among(nodes), MyRelTypes.TEST);
            }
            tx.success();
        }
        // WHEN sabotaging a random relationship
        DependencyResolver resolver = db.getDependencyResolver();
        PageCache pageCache = resolver.resolveDependency(PageCache.class);
        StoreFactory storeFactory = newStoreFactory(pageCache);
        try (NeoStores neoStores = storeFactory.openNeoStores(false, StoreType.RELATIONSHIP)) {
            RelationshipStore relationshipStore = neoStores.getRelationshipStore();
            Relationship sabotagedRelationships = random.among(relationships);
            sabotage = sabotage(relationshipStore, sabotagedRelationships.getId());
        }
    } finally {
        db.shutdown();
    }
    // THEN the checker should find it, where ever it is in the store
    db = getGraphDatabaseAPI();
    try {
        DependencyResolver resolver = db.getDependencyResolver();
        PageCache pageCache = resolver.resolveDependency(PageCache.class);
        StoreFactory storeFactory = newStoreFactory(pageCache);
        try (NeoStores neoStores = storeFactory.openAllNeoStores()) {
            StoreAccess storeAccess = new StoreAccess(neoStores).initialize();
            DirectStoreAccess directStoreAccess = new DirectStoreAccess(storeAccess, db.getDependencyResolver().resolveDependency(LabelScanStore.class), db.getDependencyResolver().resolveDependency(SchemaIndexProvider.class));
            int threads = random.intBetween(2, 10);
            FullCheck checker = new FullCheck(getTuningConfiguration(), ProgressMonitorFactory.NONE, Statistics.NONE, threads);
            AssertableLogProvider logProvider = new AssertableLogProvider(true);
            ConsistencySummaryStatistics summary = checker.execute(directStoreAccess, logProvider.getLog(FullCheck.class));
            int relationshipInconsistencies = summary.getInconsistencyCountForRecordType(RecordType.RELATIONSHIP);
            assertTrue("Couldn't detect sabotaged relationship " + sabotage, relationshipInconsistencies > 0);
            logProvider.assertContainsLogCallContaining(sabotage.after.toString());
        }
    } finally {
        db.shutdown();
    }
}
Also used : LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) StoreAccess(org.neo4j.kernel.impl.store.StoreAccess) Node(org.neo4j.graphdb.Node) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) DependencyResolver(org.neo4j.graphdb.DependencyResolver) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) PageCache(org.neo4j.io.pagecache.PageCache) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Aggregations

DependencyResolver (org.neo4j.graphdb.DependencyResolver)51 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)18 Test (org.junit.Test)15 Transaction (org.neo4j.graphdb.Transaction)10 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)9 Before (org.junit.Before)8 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)8 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)7 NeoStores (org.neo4j.kernel.impl.store.NeoStores)7 Monitors (org.neo4j.kernel.monitoring.Monitors)7 Node (org.neo4j.graphdb.Node)6 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)6 NeoStoreDataSource (org.neo4j.kernel.NeoStoreDataSource)5 Statement (org.neo4j.kernel.api.Statement)5 File (java.io.File)4 IOException (java.io.IOException)4 Label (org.neo4j.graphdb.Label)4 PageCache (org.neo4j.io.pagecache.PageCache)4 Guard (org.neo4j.kernel.guard.Guard)4 QueryExecutionEngine (org.neo4j.kernel.impl.query.QueryExecutionEngine)4