Search in sources :

Example 56 with NeoStores

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

the class RecordChangeSetTest method shouldClearStateOnClose.

@Test
public void shouldClearStateOnClose() throws Exception {
    // GIVEN
    NeoStores mockStore = mock(NeoStores.class);
    when(mockStore.getNodeStore()).thenReturn(mock(NodeStore.class));
    when(mockStore.getRelationshipStore()).thenReturn(mock(RelationshipStore.class));
    when(mockStore.getPropertyStore()).thenReturn(mock(PropertyStore.class));
    when(mockStore.getSchemaStore()).thenReturn(mock(SchemaStore.class));
    when(mockStore.getRelationshipGroupStore()).thenReturn(mock(RelationshipGroupStore.class));
    RecordChangeSet changeSet = new RecordChangeSet(new Loaders(mockStore));
    // WHEN
    /*
         * We need to make sure some stuff is stored in the sets being managed. That is why forChangingLinkage() is
         * called - otherwise, no changes will be stored and changeSize() would return 0 anyway.
         */
    changeSet.getNodeRecords().create(1L, null).forChangingLinkage();
    changeSet.getPropertyRecords().create(1L, null).forChangingLinkage();
    changeSet.getRelRecords().create(1L, null).forChangingLinkage();
    changeSet.getSchemaRuleChanges().create(1L, null).forChangingLinkage();
    changeSet.getRelGroupRecords().create(1L, 1).forChangingLinkage();
    changeSet.close();
    // THEN
    assertEquals(0, changeSet.getNodeRecords().changeSize());
    assertEquals(0, changeSet.getPropertyRecords().changeSize());
    assertEquals(0, changeSet.getRelRecords().changeSize());
    assertEquals(0, changeSet.getSchemaRuleChanges().changeSize());
    assertEquals(0, changeSet.getRelGroupRecords().changeSize());
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Test(org.junit.Test)

Example 57 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 58 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 59 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 60 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)

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