use of org.neo4j.common.DependencyResolver in project neo4j by neo4j.
the class AbstractDatabaseManager method createVersionContextSupplier.
protected VersionContextSupplier createVersionContextSupplier(DatabaseConfig databaseConfig) {
DependencyResolver externalDependencyResolver = globalModule.getExternalDependencyResolver();
Class<VersionContextSupplier> klass = VersionContextSupplier.class;
if (externalDependencyResolver.containsDependency(klass)) {
return externalDependencyResolver.resolveDependency(klass);
} else {
return databaseConfig.get(snapshot_query) ? new TransactionVersionContextSupplier() : EmptyVersionContextSupplier.EMPTY;
}
}
use of org.neo4j.common.DependencyResolver in project neo4j by neo4j.
the class DetectAllRelationshipInconsistenciesIT method shouldDetectSabotagedRelationshipWhereEverItIs.
@Test
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];
long additionalNodeId;
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < nodes.length; i++) {
nodes[i] = tx.createNode(label("Foo"));
}
additionalNodeId = tx.createNode().getId();
for (int i = 0; i < 10_000; i++) {
relationships[i] = random.among(nodes).createRelationshipTo(random.among(nodes), MyRelTypes.TEST);
}
tx.commit();
}
// WHEN sabotaging a random relationship
DependencyResolver resolver = db.getDependencyResolver();
NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
RelationshipStore relationshipStore = neoStores.getRelationshipStore();
Relationship sabotagedRelationships = random.among(relationships);
sabotage = sabotage(relationshipStore, sabotagedRelationships.getId(), additionalNodeId);
} finally {
managementService.shutdown();
}
// THEN the checker should find it, where ever it is in the store
db = getGraphDatabaseAPI();
try {
DependencyResolver resolver = db.getDependencyResolver();
RecordStorageEngine storageEngine = resolver.resolveDependency(RecordStorageEngine.class);
NeoStores neoStores = storageEngine.testAccessNeoStores();
CountsStore counts = (CountsStore) storageEngine.countsAccessor();
RelationshipGroupDegreesStore groupDegreesStore = storageEngine.relationshipGroupDegreesStore();
DirectStoreAccess directStoreAccess = new DirectStoreAccess(neoStores, db.getDependencyResolver().resolveDependency(IndexProviderMap.class), db.getDependencyResolver().resolveDependency(TokenHolders.class), db.getDependencyResolver().resolveDependency(IndexStatisticsStore.class), db.getDependencyResolver().resolveDependency(IdGeneratorFactory.class));
int threads = random.intBetween(2, 10);
FullCheck checker = new FullCheck(ProgressMonitorFactory.NONE, threads, ConsistencyFlags.DEFAULT, getTuningConfiguration(), DebugContext.NO_DEBUG, NodeBasedMemoryLimiter.DEFAULT);
AssertableLogProvider logProvider = new AssertableLogProvider(true);
ConsistencySummaryStatistics summary = checker.execute(resolver.resolveDependency(PageCache.class), directStoreAccess, () -> counts, () -> groupDegreesStore, null, PageCacheTracer.NULL, INSTANCE, logProvider.getLog(FullCheck.class));
int relationshipInconsistencies = summary.getInconsistencyCountForRecordType(RecordType.RELATIONSHIP);
assertTrue(relationshipInconsistencies > 0, "Couldn't detect sabotaged relationship " + sabotage);
assertThat(logProvider).containsMessages(sabotage.after.toString());
} finally {
managementService.shutdown();
}
}
use of org.neo4j.common.DependencyResolver in project neo4j by neo4j.
the class FullCheckTokenIndexIT method check.
private ConsistencySummaryStatistics check(GraphDatabaseAPI database, Config config) throws ConsistencyCheckIncompleteException {
DependencyResolver dependencyResolver = database.getDependencyResolver();
RecordStorageEngine storageEngine = dependencyResolver.resolveDependency(RecordStorageEngine.class);
NeoStores neoStores = storageEngine.testAccessNeoStores();
IndexingService indexingService = dependencyResolver.resolveDependency(IndexingService.class);
DirectStoreAccess directStoreAccess = new DirectStoreAccess(neoStores, dependencyResolver.resolveDependency(IndexProviderMap.class), dependencyResolver.resolveDependency(TokenHolders.class), dependencyResolver.resolveDependency(IndexStatisticsStore.class), dependencyResolver.resolveDependency(IdGeneratorFactory.class));
CountsAccessor countsStore = storageEngine.countsAccessor();
RelationshipGroupDegreesStore groupDegreesStore = storageEngine.relationshipGroupDegreesStore();
PageCache pageCache = dependencyResolver.resolveDependency(PageCache.class);
IndexAccessors.IndexAccessorLookup indexAccessorLookup = new LookupAccessorsFromRunningDb(indexingService);
FullCheck checker = new FullCheck(ProgressMonitorFactory.NONE, defaultConsistencyCheckThreadsNumber(), ConsistencyFlags.DEFAULT, config, DebugContext.NO_DEBUG, NodeBasedMemoryLimiter.DEFAULT);
return checker.execute(pageCache, directStoreAccess, () -> (CountsStore) countsStore, () -> groupDegreesStore, indexAccessorLookup, PageCacheTracer.NULL, INSTANCE, logProvider.getLog("test"));
}
use of org.neo4j.common.DependencyResolver in project neo4j by neo4j.
the class DiscoveryServiceTest method init.
public void init(String description, String baseUri, Consumer<ConnectorPortRegister> portRegistryOverrider, Consumer<Config.Builder> configOverrider, String expectedBoltUri) throws URISyntaxException {
this.baseUri = new URI(baseUri);
this.dbUri = new URI("/db");
this.portRegistryOverrider = portRegistryOverrider;
this.configOverrider = configOverrider;
this.expectedDatabaseUri = this.baseUri.resolve(this.dbUri).toString();
this.expectedBoltUri = expectedBoltUri;
if (portRegistryOverrider != null) {
portRegistryOverrider.accept(portRegistry);
} else {
when(portRegistry.getLocalAddress("bolt")).thenReturn(new HostnamePort("localhost", 7687));
}
DependencyResolver dependencyResolver = mock(DependencyResolver.class);
when(dependencyResolver.resolveDependency(ConnectorPortRegister.class)).thenReturn(portRegistry);
}
use of org.neo4j.common.DependencyResolver in project neo4j by neo4j.
the class CheckerTestBase method setUpDb.
@BeforeEach
void setUpDb() throws Exception {
TestDatabaseManagementServiceBuilder builder = new TestDatabaseManagementServiceBuilder(directory.homePath());
builder.setFileSystem(directory.getFileSystem());
dbms = builder.build();
db = (GraphDatabaseAPI) dbms.database(GraphDatabaseSettings.DEFAULT_DATABASE_NAME);
// Create our tokens
Kernel kernel = db.getDependencyResolver().resolveDependency(Kernel.class);
try (KernelTransaction tx = kernel.beginTransaction(KernelTransaction.Type.EXPLICIT, LoginContext.AUTH_DISABLED)) {
initialData(tx);
tx.commit();
}
DependencyResolver dependencies = db.getDependencyResolver();
neoStores = dependencies.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
nodeStore = neoStores.getNodeStore();
relationshipGroupStore = neoStores.getRelationshipGroupStore();
propertyStore = neoStores.getPropertyStore();
relationshipStore = neoStores.getRelationshipStore();
schemaStore = neoStores.getSchemaStore();
tokenHolders = dependencies.resolveDependency(TokenHolders.class);
schemaStorage = new SchemaStorage(schemaStore, tokenHolders, neoStores.getMetaDataStore());
cacheAccess = new DefaultCacheAccess(NumberArrayFactories.HEAP.newDynamicByteArray(10_000, new byte[MAX_BYTES], INSTANCE), Counts.NONE, NUMBER_OF_THREADS);
cacheAccess.setCacheSlotSizes(DEFAULT_SLOT_SIZES);
pageCache = dependencies.resolveDependency(PageCache.class);
}
Aggregations