use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertRemovedPropertyToNodePropertyUpdates.
@Test
public void shouldConvertRemovedPropertyToNodePropertyUpdates() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
int nodeId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
addLabelsToNode(recordState, nodeId, oneLabelId);
DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
apply(neoStores, transactionRepresentationOf(recordState));
// WHEN
recordState = newTransactionRecordState(neoStores);
recordState.nodeRemoveProperty(nodeId, property1.propertyKeyId());
recordState.nodeRemoveProperty(nodeId, property2.propertyKeyId());
Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
// THEN
NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId).removed(property1.propertyKeyId(), property1.value()).removed(property2.propertyKeyId(), property2.value()).build();
assertEquals(expected, Iterables.single(indexUpdates));
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithOneType.
@Test
public void shouldMaintainCorrectDataWhenDeletingFromDenseNodeWithOneType() throws Exception {
// GIVEN a node with a total of denseNodeThreshold-1 relationships
NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "13");
TransactionRecordState tx = newTransactionRecordState(neoStores);
int nodeId = (int) neoStores.getNodeStore().nextId(), typeA = 0;
tx.nodeCreate(nodeId);
tx.createRelationshipTypeToken("A", typeA);
long[] relationshipsCreated = createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 15);
//WHEN
tx.relDelete(relationshipsCreated[0]);
// THEN the node should have been converted into a dense node
assertDenseRelationshipCounts(recordChangeSet, nodeId, typeA, 0, 14);
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class CsvInputBatchImportIT method verifyImportedData.
// ======================================================
// Below is code for verifying the imported data
// ======================================================
private void verifyImportedData(List<InputNode> nodeData, List<InputRelationship> relationshipData) {
// Build up expected data for the verification below
Map<String, InputNode> /*id*/
expectedNodes = new HashMap<>();
Map<String, String[]> expectedNodeNames = new HashMap<>();
Map<String, Map<String, Map<String, AtomicInteger>>> /*end node name*/
expectedRelationships = new AutoCreatingHashMap<>(nested(String.class, nested(String.class, values(AtomicInteger.class))));
Map<String, AtomicLong> expectedNodeCounts = new AutoCreatingHashMap<>(values(AtomicLong.class));
Map<String, Map<String, Map<String, AtomicLong>>> expectedRelationshipCounts = new AutoCreatingHashMap<>(nested(String.class, nested(String.class, values(AtomicLong.class))));
buildUpExpectedData(nodeData, relationshipData, expectedNodes, expectedNodeNames, expectedRelationships, expectedNodeCounts, expectedRelationshipCounts);
// Do the verification
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(directory.graphDbDir());
try (Transaction tx = db.beginTx()) {
// Verify nodes
for (Node node : db.getAllNodes()) {
String name = (String) node.getProperty("name");
String[] labels = expectedNodeNames.remove(name);
assertEquals(asSet(labels), names(node.getLabels()));
}
assertEquals(0, expectedNodeNames.size());
// Verify relationships
for (Relationship relationship : db.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, greaterThanOrEqualTo(0));
if (countAfterwards == 0) {
innerInner.remove(type);
if (innerInner.isEmpty()) {
inner.remove(endNodeName);
if (inner.isEmpty()) {
expectedRelationships.remove(startNodeName);
}
}
}
}
assertEquals(0, expectedRelationships.size());
// Verify counts, TODO how to get counts store other than this way?
NeoStores neoStores = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
Function<String, Integer> labelTranslationTable = translationTable(neoStores.getLabelTokenStore(), ReadOperations.ANY_LABEL);
for (Pair<Integer, Long> count : allNodeCounts(labelTranslationTable, expectedNodeCounts)) {
assertEquals("Label count mismatch for label " + count.first(), count.other().longValue(), neoStores.getCounts().nodeCount(count.first().intValue(), newDoubleLongRegister()).readSecond());
}
Function<String, Integer> relationshipTypeTranslationTable = translationTable(neoStores.getRelationshipTypeTokenStore(), ReadOperations.ANY_RELATIONSHIP_TYPE);
for (Pair<RelationshipCountKey, Long> count : allRelationshipCounts(labelTranslationTable, relationshipTypeTranslationTable, expectedRelationshipCounts)) {
RelationshipCountKey key = count.first();
assertEquals("Label count mismatch for label " + key, count.other().longValue(), neoStores.getCounts().relationshipCount(key.startLabel, key.type, key.endLabel, newDoubleLongRegister()).readSecond());
}
tx.success();
} finally {
db.shutdown();
}
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class CountsStoreRecoveryTest method flushNeoStoreOnly.
private void flushNeoStoreOnly() throws Exception {
NeoStores neoStores = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
MetaDataStore metaDataStore = neoStores.getMetaDataStore();
metaDataStore.flush();
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class StoreUpgraderTest method upgradedNeoStoreShouldHaveNewUpgradeTimeAndUpgradeId.
@Test
public void upgradedNeoStoreShouldHaveNewUpgradeTimeAndUpgradeId() throws Exception {
// Given
fileSystem.deleteFile(new File(dbDirectory, StoreLogService.INTERNAL_LOG_NAME));
PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
// When
newUpgrader(upgradableDatabase, allowMigrateConfig, pageCache).migrateIfNeeded(dbDirectory);
// Then
StoreFactory factory = new StoreFactory(dbDirectory, pageCache, fileSystem, NullLogProvider.getInstance());
try (NeoStores neoStores = factory.openAllNeoStores()) {
assertThat(neoStores.getMetaDataStore().getUpgradeTransaction(), equalTo(neoStores.getMetaDataStore().getLastCommittedTransaction()));
assertThat(neoStores.getMetaDataStore().getUpgradeTime(), not(equalTo(MetaDataStore.FIELD_NOT_INITIALIZED)));
long minuteAgo = System.currentTimeMillis() - MINUTES.toMillis(1);
assertThat(neoStores.getMetaDataStore().getUpgradeTime(), greaterThan(minuteAgo));
}
}
Aggregations