use of org.neo4j.internal.recordstorage.RecordStorageEngine in project neo4j by neo4j.
the class NeoStoresTest method reinitializeStores.
private void reinitializeStores(DatabaseLayout databaseLayout) {
Dependencies dependencies = new Dependencies();
Config config = Config.defaults(GraphDatabaseSettings.fail_on_missing_files, false);
dependencies.satisfyDependency(config);
closeStorageEngine();
IdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName());
TokenHolders tokenHolders = new TokenHolders(createReadOnlyTokenHolder(TokenHolder.TYPE_PROPERTY_KEY), createReadOnlyTokenHolder(TokenHolder.TYPE_LABEL), createReadOnlyTokenHolder(TokenHolder.TYPE_RELATIONSHIP_TYPE));
storageEngine = new RecordStorageEngine(databaseLayout, config, pageCache, fs, nullLogProvider(), tokenHolders, new DatabaseSchemaState(nullLogProvider()), new StandardConstraintRuleAccessor(), i -> i, NO_LOCK_SERVICE, mock(Health.class), idGeneratorFactory, new DefaultIdController(), immediate(), PageCacheTracer.NULL, true, INSTANCE, writable(), CommandLockVerification.Factory.IGNORE, LockVerificationMonitor.Factory.IGNORE);
life = new LifeSupport();
life.add(storageEngine);
life.add(storageEngine.schemaAndTokensLifecycle());
life.start();
NeoStores neoStores = storageEngine.testAccessNeoStores();
pStore = neoStores.getPropertyStore();
nodeStore = neoStores.getNodeStore();
storageReader = storageEngine.newReader();
}
use of org.neo4j.internal.recordstorage.RecordStorageEngine in project neo4j by neo4j.
the class StoreScanChunkIT method differentChunksHaveDifferentCursors.
@Test
void differentChunksHaveDifferentCursors() {
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try {
RecordStorageEngine recordStorageEngine = database.getDependencyResolver().resolveDependency(RecordStorageEngine.class);
NeoStores neoStores = recordStorageEngine.testAccessNeoStores();
RecordStorageReader storageReader = new RecordStorageReader(neoStores);
TestStoreScanChunk scanChunk1 = new TestStoreScanChunk(storageReader, false);
TestStoreScanChunk scanChunk2 = new TestStoreScanChunk(storageReader, false);
assertNotSame(scanChunk1.getCursor(), scanChunk2.getCursor());
assertNotSame(scanChunk1.getStorePropertyCursor(), scanChunk2.getStorePropertyCursor());
} finally {
managementService.shutdown();
}
}
use of org.neo4j.internal.recordstorage.RecordStorageEngine in project neo4j by neo4j.
the class CsvInputBatchImportIT method verifyImportedData.
// ======================================================
// Below is code for verifying the imported data
// ======================================================
private void verifyImportedData(List<InputEntity> nodeData, List<InputEntity> relationshipData) {
// Build up expected data for the verification below
Map<String, InputEntity> /*id*/
expectedNodes = new HashMap<>();
Map<String, String[]> expectedNodeNames = new HashMap<>();
Map<String, Map<String, Consumer<Object>>> expectedNodePropertyVerifiers = new HashMap<>();
Map<String, Map<String, Map<String, AtomicInteger>>> /*end node name*/
expectedRelationships = new AutoCreatingHashMap<>(nested(nested(values(AtomicInteger.class))));
Map<String, AtomicLong> expectedNodeCounts = new AutoCreatingHashMap<>(values(AtomicLong.class));
Map<String, Map<String, Map<String, AtomicLong>>> expectedRelationshipCounts = new AutoCreatingHashMap<>(nested(nested(values(AtomicLong.class))));
buildUpExpectedData(nodeData, relationshipData, expectedNodes, expectedNodeNames, expectedNodePropertyVerifiers, expectedRelationships, expectedNodeCounts, expectedRelationshipCounts);
// Do the verification
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
// Verify nodes
for (Node node : tx.getAllNodes()) {
String name = (String) node.getProperty("name");
String[] labels = expectedNodeNames.remove(name);
assertEquals(asSet(labels), names(node.getLabels()));
// Verify node properties
Map<String, Consumer<Object>> expectedPropertyVerifiers = expectedNodePropertyVerifiers.remove(name);
Map<String, Object> actualProperties = node.getAllProperties();
// The id does not exist in expected properties
actualProperties.remove("id");
for (Map.Entry actualProperty : actualProperties.entrySet()) {
Consumer v = expectedPropertyVerifiers.get(actualProperty.getKey());
if (v != null) {
v.accept(actualProperty.getValue());
}
}
}
assertEquals(0, expectedNodeNames.size());
// Verify relationships
for (Relationship relationship : tx.getAllRelationships()) {
String startNodeName = (String) relationship.getStartNode().getProperty("name");
Map<String, Map<String, AtomicInteger>> inner = expectedRelationships.get(startNodeName);
String endNodeName = (String) relationship.getEndNode().getProperty("name");
Map<String, AtomicInteger> innerInner = inner.get(endNodeName);
String type = relationship.getType().name();
int countAfterwards = innerInner.get(type).decrementAndGet();
assertThat(countAfterwards).isGreaterThanOrEqualTo(0);
if (countAfterwards == 0) {
innerInner.remove(type);
if (innerInner.isEmpty()) {
inner.remove(endNodeName);
if (inner.isEmpty()) {
expectedRelationships.remove(startNodeName);
}
}
}
}
assertEquals(0, expectedRelationships.size());
RecordStorageEngine storageEngine = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(RecordStorageEngine.class);
NeoStores neoStores = storageEngine.testAccessNeoStores();
CountsAccessor counts = storageEngine.countsAccessor();
Function<String, Integer> labelTranslationTable = translationTable(neoStores.getLabelTokenStore(), ANY_LABEL);
for (Pair<Integer, Long> count : allNodeCounts(labelTranslationTable, expectedNodeCounts)) {
assertEquals(count.other().longValue(), counts.nodeCount(count.first(), NULL), "Label count mismatch for label " + count.first());
}
Function<String, Integer> relationshipTypeTranslationTable = translationTable(neoStores.getRelationshipTypeTokenStore(), ANY_RELATIONSHIP_TYPE);
for (Pair<RelationshipCountKey, Long> count : allRelationshipCounts(labelTranslationTable, relationshipTypeTranslationTable, expectedRelationshipCounts)) {
RelationshipCountKey key = count.first();
assertEquals(count.other().longValue(), counts.relationshipCount(key.startLabel, key.type, key.endLabel, NULL), "Label count mismatch for label " + key);
}
tx.commit();
} finally {
managementService.shutdown();
}
}
Aggregations