Search in sources :

Example 81 with NeoStores

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

the class TransactionRecordStateTest method shouldValidateConstraintIndexAsPartOfExtraction.

@Test
public void shouldValidateConstraintIndexAsPartOfExtraction() throws Throwable {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    final long indexId = neoStores.getSchemaStore().nextId();
    final long constraintId = neoStores.getSchemaStore().nextId();
    recordState.createSchemaRule(constraintRule(constraintId, uniqueForLabel(1, 1), indexId));
    // WHEN
    recordState.extractCommands(new ArrayList<>());
    // THEN
    verify(integrityValidator).validateSchemaRule(any());
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 82 with NeoStores

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

the class TransactionRecordStateTest method shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithDifferentTypes.

@Test
public void shouldConvertToDenseNodeRepresentationWhenHittingThresholdWithDifferentTypes() throws Exception {
    // GIVEN a node with a total of denseNodeThreshold-1 relationships
    NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "50");
    TransactionRecordState tx = newTransactionRecordState(neoStores);
    long nodeId = neoStores.getNodeStore().nextId();
    int typeA = 0, typeB = 1, typeC = 2;
    tx.nodeCreate(nodeId);
    tx.createRelationshipTypeToken("A", typeA);
    createRelationships(neoStores, tx, nodeId, typeA, OUTGOING, 6);
    createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 7);
    tx.createRelationshipTypeToken("B", typeB);
    createRelationships(neoStores, tx, nodeId, typeB, OUTGOING, 8);
    createRelationships(neoStores, tx, nodeId, typeB, INCOMING, 9);
    tx.createRelationshipTypeToken("C", typeC);
    createRelationships(neoStores, tx, nodeId, typeC, OUTGOING, 10);
    createRelationships(neoStores, tx, nodeId, typeC, INCOMING, 10);
    // here we're at the edge
    assertFalse(recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData().isDense());
    // WHEN creating the relationship that pushes us over the threshold
    createRelationships(neoStores, tx, nodeId, typeC, INCOMING, 1);
    // THEN the node should have been converted into a dense node
    assertTrue(recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData().isDense());
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeA, 6, 7);
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeB, 8, 9);
    assertDenseRelationshipCounts(recordChangeSet, nodeId, typeC, 10, 11);
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 83 with NeoStores

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

the class TransactionRecordStateTest method shouldDeleteDynamicLabelsForDeletedNodeForRecoveredTransaction.

@Test
public void shouldDeleteDynamicLabelsForDeletedNodeForRecoveredTransaction() throws Throwable {
    // GIVEN a store that has got a node with a dynamic label record
    NeoStores store = neoStoresRule.open();
    BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(store, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
    AtomicLong nodeId = new AtomicLong();
    AtomicLong dynamicLabelRecordId = new AtomicLong();
    apply(applier, transaction(nodeWithDynamicLabelRecord(store, nodeId, dynamicLabelRecordId)));
    assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), true);
    // WHEN applying a transaction, which has first round-tripped through a log (written then read)
    TransactionRepresentation transaction = transaction(deleteNode(store, nodeId.get()));
    InMemoryVersionableReadableClosablePositionAwareChannel channel = new InMemoryVersionableReadableClosablePositionAwareChannel();
    writeToChannel(transaction, channel);
    CommittedTransactionRepresentation recoveredTransaction = readFromChannel(channel);
    // and applying that recovered transaction
    apply(applier, recoveredTransaction.getTransactionRepresentation());
    // THEN should have the dynamic label record should be deleted as well
    assertDynamicLabelRecordInUse(store, dynamicLabelRecordId.get(), false);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) InMemoryVersionableReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.InMemoryVersionableReadableClosablePositionAwareChannel) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) CacheAccessBackDoor(org.neo4j.kernel.impl.core.CacheAccessBackDoor) Test(org.junit.Test)

Example 84 with NeoStores

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

the class TransactionRecordStateTest method shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates.

@Test
public void shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    long nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
    addLabelsToNode(recordState, nodeId, bothLabelIds);
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
    removeLabelsFromNode(recordState, nodeId, secondLabelId);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, bothLabelIds, oneLabelId).added(property2.propertyKeyId(), property2.value()).buildWithExistingProperties(property1, property2);
    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 85 with NeoStores

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

the class TransactionRecordStateTest method shouldPrepareRelevantRecords.

@Test
public void shouldPrepareRelevantRecords() throws Exception {
    // GIVEN
    PrepareTrackingRecordFormats format = new PrepareTrackingRecordFormats(Standard.LATEST_RECORD_FORMATS);
    NeoStores neoStores = neoStoresRule.open(format, GraphDatabaseSettings.dense_node_threshold.name(), "1");
    // WHEN
    TransactionRecordState state = newTransactionRecordState(neoStores);
    state.nodeCreate(0);
    state.relCreate(0, 0, 0, 0);
    state.relCreate(1, 0, 0, 0);
    state.relCreate(2, 0, 0, 0);
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands);
    // THEN
    int nodes = 0, rels = 0, groups = 0;
    for (StorageCommand command : commands) {
        if (command instanceof NodeCommand) {
            assertTrue(format.node().prepared(((NodeCommand) command).getAfter()));
            nodes++;
        } else if (command instanceof RelationshipCommand) {
            assertTrue(format.relationship().prepared(((RelationshipCommand) command).getAfter()));
            rels++;
        } else if (command instanceof RelationshipGroupCommand) {
            assertTrue(format.relationshipGroup().prepared(((RelationshipGroupCommand) command).getAfter()));
            groups++;
        }
    }
    assertEquals(1, nodes);
    assertEquals(3, rels);
    assertEquals(1, groups);
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) RelationshipGroupCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand) RelationshipCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand) NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) Test(org.junit.Test)

Aggregations

NeoStores (org.neo4j.kernel.impl.store.NeoStores)122 Test (org.junit.Test)46 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)32 Test (org.junit.jupiter.api.Test)25 ArrayList (java.util.ArrayList)17 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)16 PageCache (org.neo4j.io.pagecache.PageCache)16 NodeStore (org.neo4j.kernel.impl.store.NodeStore)15 Transaction (org.neo4j.graphdb.Transaction)14 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)14 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)13 File (java.io.File)11 IOException (java.io.IOException)11 Node (org.neo4j.graphdb.Node)11 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)11 MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)10 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)9 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)9