Search in sources :

Example 26 with NeoStores

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

the class IntegrityValidatorTest method deletingNodeWithRelationshipsIsNotAllowed.

@Test
public void deletingNodeWithRelationshipsIsNotAllowed() throws Exception {
    // Given
    NeoStores store = mock(NeoStores.class);
    IndexingService indexes = mock(IndexingService.class);
    IntegrityValidator validator = new IntegrityValidator(store, indexes);
    NodeRecord record = new NodeRecord(1L, false, 1L, -1L);
    record.setInUse(false);
    // When
    try {
        validator.validateNodeRecord(record);
        fail("Should have thrown integrity error.");
    } catch (Exception e) {
    // good
    }
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Test(org.junit.Test)

Example 27 with NeoStores

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

the class IntegrityValidatorTest method transactionsStartedBeforeAConstraintWasCreatedAreDisallowed.

@Test
public void transactionsStartedBeforeAConstraintWasCreatedAreDisallowed() throws Exception {
    // Given
    NeoStores store = mock(NeoStores.class);
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    when(store.getMetaDataStore()).thenReturn(metaDataStore);
    IndexingService indexes = mock(IndexingService.class);
    when(metaDataStore.getLatestConstraintIntroducingTx()).thenReturn(10L);
    IntegrityValidator validator = new IntegrityValidator(store, indexes);
    // When
    try {
        validator.validateTransactionStartKnowledge(1);
        fail("Should have thrown integrity error.");
    } catch (Exception e) {
    // good
    }
}
Also used : MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Test(org.junit.Test)

Example 28 with NeoStores

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

the class TransactionRecordStateTest method shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates.

@Test
public void shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    long nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    recordState.nodeAddProperty(nodeId, propertyId1, value1);
    addLabelsToNode(recordState, nodeId, oneLabelId);
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeAddProperty(nodeId, propertyId2, value2);
    addLabelsToNode(recordState, nodeId, secondLabelId);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId, bothLabelIds).added(propertyId2, value2).buildWithExistingProperties(Property.stringProperty(propertyId1, value1));
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 29 with NeoStores

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

the class TransactionRecordStateTest method shouldConvertLabelRemovalToNodePropertyUpdates.

@Test
public void shouldConvertLabelRemovalToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    long nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    recordState.nodeAddProperty(nodeId, propertyId1, value1);
    recordState.nodeAddProperty(nodeId, propertyId2, value2);
    addLabelsToNode(recordState, nodeId, oneLabelId);
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    removeLabelsFromNode(recordState, nodeId, oneLabelId);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId, noLabels).buildWithExistingProperties(Property.stringProperty(propertyId1, value1), Property.intProperty(propertyId2, value2));
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 30 with NeoStores

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

the class TransactionRecordStateTest method shouldLockUpdatedNodes.

@Test
public void shouldLockUpdatedNodes() throws Exception {
    // given
    LockService locks = mock(LockService.class, new Answer<Object>() {

        @Override
        public synchronized Object answer(final InvocationOnMock invocation) throws Throwable {
            // This is necessary because finalize() will also be called
            String name = invocation.getMethod().getName();
            if (name.equals("acquireNodeLock") || name.equals("acquireRelationshipLock")) {
                return mock(Lock.class, (Answer) invocationOnMock -> null);
            }
            return null;
        }
    });
    NeoStores neoStores = neoStoresRule.open();
    NodeStore nodeStore = neoStores.getNodeStore();
    long[] nodes = { // allocate ids
    nodeStore.nextId(), nodeStore.nextId(), nodeStore.nextId(), nodeStore.nextId(), nodeStore.nextId(), nodeStore.nextId(), nodeStore.nextId() };
    {
        // create the node records that we will modify in our main tx.
        TransactionRecordState tx = newTransactionRecordState(neoStores);
        for (int i = 1; i < nodes.length - 1; i++) {
            tx.nodeCreate(nodes[i]);
        }
        tx.nodeAddProperty(nodes[3], 0, "old");
        tx.nodeAddProperty(nodes[4], 0, "old");
        BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), locks);
        apply(applier, transaction(tx));
    }
    reset(locks);
    // These are the changes we want to assert locking on
    TransactionRecordState tx = newTransactionRecordState(neoStores);
    tx.nodeCreate(nodes[0]);
    tx.addLabelToNode(0, nodes[1]);
    tx.nodeAddProperty(nodes[2], 0, "value");
    tx.nodeChangeProperty(nodes[3], 0, "value");
    tx.nodeRemoveProperty(nodes[4], 0);
    tx.nodeDelete(nodes[5]);
    tx.nodeCreate(nodes[6]);
    tx.addLabelToNode(0, nodes[6]);
    tx.nodeAddProperty(nodes[6], 0, "value");
    //commit( tx );
    BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), locks);
    apply(applier, transaction(tx));
    // then
    // create node, NodeCommand == 1 update
    verify(locks, times(1)).acquireNodeLock(nodes[0], LockService.LockType.WRITE_LOCK);
    // add label, NodeCommand == 1 update
    verify(locks, times(1)).acquireNodeLock(nodes[1], LockService.LockType.WRITE_LOCK);
    // add property, NodeCommand and PropertyCommand == 2 updates
    verify(locks, times(2)).acquireNodeLock(nodes[2], LockService.LockType.WRITE_LOCK);
    // update property, in place, PropertyCommand == 1 update
    verify(locks, times(1)).acquireNodeLock(nodes[3], LockService.LockType.WRITE_LOCK);
    // remove property, updates the Node and the Property == 2 updates
    verify(locks, times(2)).acquireNodeLock(nodes[4], LockService.LockType.WRITE_LOCK);
    // delete node, single NodeCommand == 1 update
    verify(locks, times(1)).acquireNodeLock(nodes[5], LockService.LockType.WRITE_LOCK);
    // create and add-label goes into the NodeCommand, add property is a PropertyCommand == 2 updates
    verify(locks, times(2)).acquireNodeLock(nodes[6], LockService.LockType.WRITE_LOCK);
}
Also used : LockService(org.neo4j.kernel.impl.locking.LockService) Lock(org.neo4j.kernel.impl.locking.Lock) Answer(org.mockito.stubbing.Answer) NodeStore(org.neo4j.kernel.impl.store.NodeStore) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NeoStores(org.neo4j.kernel.impl.store.NeoStores) NeoStoreBatchTransactionApplier(org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier) 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)

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