use of org.neo4j.consistency.report.ConsistencySummaryStatistics 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();
}
}
use of org.neo4j.consistency.report.ConsistencySummaryStatistics in project neo4j by neo4j.
the class ExecutionOrderIntegrationTest method shouldRunChecksInSingleThreadedPass.
@Test
public void shouldRunChecksInSingleThreadedPass() throws Exception {
// given
StoreAccess store = fixture.directStoreAccess().nativeStores();
int threads = defaultConsistencyCheckThreadsNumber();
CacheAccess cacheAccess = new DefaultCacheAccess(new DefaultCounts(threads), threads);
RecordAccess access = FullCheck.recordAccess(store, cacheAccess);
FullCheck singlePass = new FullCheck(getTuningConfiguration(), ProgressMonitorFactory.NONE, Statistics.NONE, threads);
ConsistencySummaryStatistics singlePassSummary = new ConsistencySummaryStatistics();
InconsistencyLogger logger = mock(InconsistencyLogger.class);
InvocationLog singlePassChecks = new InvocationLog();
// when
singlePass.execute(fixture.directStoreAccess(), new LogDecorator(singlePassChecks), access, new InconsistencyReport(logger, singlePassSummary), cacheAccess, NO_MONITOR);
// then
verifyZeroInteractions(logger);
assertEquals("Expected no inconsistencies in single pass.", 0, singlePassSummary.getTotalInconsistencyCount());
}
use of org.neo4j.consistency.report.ConsistencySummaryStatistics in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportIndexInconsistencies.
@Test
public void shouldReportIndexInconsistencies() throws Exception {
// given
for (Long indexedNodeId : indexedNodes) {
fixture.directStoreAccess().nativeStores().getNodeStore().updateRecord(notInUse(new NodeRecord(indexedNodeId, false, -1, -1)));
}
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.INDEX, 1).verify(RecordType.LABEL_SCAN_DOCUMENT, 1).verify(RecordType.COUNTS, 3).andThatsAllFolks();
}
use of org.neo4j.consistency.report.ConsistencySummaryStatistics in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldCheckConsistencyOfAConsistentStore.
@Test
public void shouldCheckConsistencyOfAConsistentStore() throws Exception {
// when
ConsistencySummaryStatistics result = check();
// then
assertEquals(result.toString(), 0, result.getTotalInconsistencyCount());
}
use of org.neo4j.consistency.report.ConsistencySummaryStatistics in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportRelationshipInconsistencies.
@Test
public void shouldReportRelationshipInconsistencies() throws Exception {
// given
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
tx.create(new RelationshipRecord(next.relationship(), 1, 2, C));
}
});
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.RELATIONSHIP, 2).verify(RecordType.COUNTS, 3).andThatsAllFolks();
}
Aggregations