Search in sources :

Example 16 with NodeUpdates

use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldConvertMixedLabelRemovalAndRemovePropertyToNodePropertyUpdates.

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

use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldConvertAddedPropertyToNodePropertyUpdates.

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

Example 18 with NodeUpdates

use of org.neo4j.kernel.api.index.NodeUpdates 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 19 with NodeUpdates

use of org.neo4j.kernel.api.index.NodeUpdates 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 20 with NodeUpdates

use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.

the class NeoStoreIndexStoreViewTest method shouldLockNodesWhileReadingThem.

@Test
public void shouldLockNodesWhileReadingThem() throws Exception {
    // given
    @SuppressWarnings("unchecked") Visitor<NodeUpdates, Exception> visitor = mock(Visitor.class);
    StoreScan<Exception> storeScan = storeView.visitNodes(new int[] { labelId }, (id) -> id == propertyKeyId, visitor, null, false);
    // when
    storeScan.run();
    // then
    assertEquals("allocated locks: " + lockMocks.keySet(), 2, lockMocks.size());
    Lock lock0 = lockMocks.get(0L);
    Lock lock1 = lockMocks.get(1L);
    assertNotNull("Lock[node=0] never acquired", lock0);
    assertNotNull("Lock[node=1] never acquired", lock1);
    InOrder order = inOrder(locks, lock0, lock1);
    order.verify(locks).acquireNodeLock(0, LockService.LockType.READ_LOCK);
    order.verify(lock0).release();
    order.verify(locks).acquireNodeLock(1, LockService.LockType.READ_LOCK);
    order.verify(lock1).release();
    order.verifyNoMoreInteractions();
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) InOrder(org.mockito.InOrder) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) Lock(org.neo4j.kernel.impl.locking.Lock) Test(org.junit.Test)

Aggregations

NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)28 Test (org.junit.Test)25 NeoStores (org.neo4j.kernel.impl.store.NeoStores)9 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)5 NeoStoreIndexStoreView (org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView)5 ArrayList (java.util.ArrayList)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 Transaction (org.neo4j.graphdb.Transaction)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3 Collection (java.util.Collection)2 Visitor (org.neo4j.helpers.collection.Visitor)2 KernelException (org.neo4j.kernel.api.exceptions.KernelException)2 NodeLabelUpdate (org.neo4j.kernel.api.labelscan.NodeLabelUpdate)2 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)2 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1