Search in sources :

Example 66 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldConvertChangedPropertyToNodePropertyUpdates.

@Test
public void shouldConvertChangedPropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    int nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
    DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
    apply(neoStores, transactionRepresentationOf(recordState));
    // WHEN
    String newValue1 = "new", newValue2 = "new 2";
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeChangeProperty(nodeId, property1.propertyKeyId(), newValue1);
    recordState.nodeChangeProperty(nodeId, property2.propertyKeyId(), newValue2);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId).changed(property1.propertyKeyId(), property1.value(), newValue1).changed(property2.propertyKeyId(), property2.value(), newValue2).build();
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 67 with NeoStores

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));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 68 with NeoStores

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);
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 69 with NeoStores

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();
    }
}
Also used : AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap) HashMap(java.util.HashMap) AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Node(org.neo4j.graphdb.Node) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(org.neo4j.graphdb.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Relationship(org.neo4j.graphdb.Relationship) NeoStores(org.neo4j.kernel.impl.store.NeoStores) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) HashMap(java.util.HashMap) AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap)

Example 70 with NeoStores

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();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores)

Aggregations

NeoStores (org.neo4j.kernel.impl.store.NeoStores)77 Test (org.junit.Test)48 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)17 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)14 NodeStore (org.neo4j.kernel.impl.store.NodeStore)12 File (java.io.File)11 Transaction (org.neo4j.graphdb.Transaction)11 ArrayList (java.util.ArrayList)9 PageCache (org.neo4j.io.pagecache.PageCache)9 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 Node (org.neo4j.graphdb.Node)8 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)8 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)8 DependencyResolver (org.neo4j.graphdb.DependencyResolver)7 RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)7 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)6 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)6 NeoStoreBatchTransactionApplier (org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier)6 CacheAccessBackDoor (org.neo4j.kernel.impl.core.CacheAccessBackDoor)5 NodeCommand (org.neo4j.kernel.impl.transaction.command.Command.NodeCommand)5