Search in sources :

Example 41 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class TxStateTransactionDataViewTest method shouldListRemovedRelationshipProperties.

@Test
public void shouldListRemovedRelationshipProperties() throws Exception {
    // Given
    int propertyKeyId = 1;
    DefinedProperty prevValue = stringProperty(propertyKeyId, "prevValue");
    state.relationshipDoRemoveProperty(1L, prevValue);
    when(ops.propertyKeyGetName(propertyKeyId)).thenReturn("theKey");
    long propertyId = 40L;
    when(storeStatement.acquireSingleRelationshipCursor(1)).thenReturn(asRelationshipCursor(1, 0, 0, 0, propertyId));
    when(storeStatement.acquireSinglePropertyCursor(propertyId, propertyKeyId, NO_LOCK)).thenReturn(asPropertyCursor(prevValue));
    // When
    Iterable<PropertyEntry<Relationship>> propertyEntries = snapshot().removedRelationshipProperties();
    // Then
    PropertyEntry<Relationship> entry = single(propertyEntries);
    assertThat(entry.key(), equalTo("theKey"));
    assertThat(entry.previouslyCommitedValue(), equalTo((Object) "prevValue"));
    assertThat(entry.entity().getId(), equalTo(1L));
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyEntry(org.neo4j.graphdb.event.PropertyEntry) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 42 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class TxStateTransactionDataViewTest method shouldListAddedRelationshipProperties.

@Test
public void shouldListAddedRelationshipProperties() throws Exception {
    // Given
    int propertyKeyId = 1;
    DefinedProperty prevProp = stringProperty(propertyKeyId, "prevValue");
    state.relationshipDoReplaceProperty(1L, prevProp, stringProperty(propertyKeyId, "newValue"));
    when(ops.propertyKeyGetName(propertyKeyId)).thenReturn("theKey");
    long propertyId = 40L;
    when(storeStatement.acquireSingleRelationshipCursor(1)).thenReturn(asRelationshipCursor(1, 0, 0, 0, propertyId));
    when(storeStatement.acquireSinglePropertyCursor(propertyId, propertyKeyId, NO_LOCK)).thenReturn(asPropertyCursor(prevProp));
    // When
    Iterable<PropertyEntry<Relationship>> propertyEntries = snapshot().assignedRelationshipProperties();
    // Then
    PropertyEntry<Relationship> entry = single(propertyEntries);
    assertThat(entry.key(), equalTo("theKey"));
    assertThat(entry.value(), equalTo((Object) "newValue"));
    assertThat(entry.previouslyCommitedValue(), equalTo((Object) "prevValue"));
    assertThat(entry.entity().getId(), equalTo(1L));
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyEntry(org.neo4j.graphdb.event.PropertyEntry) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 43 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class NeoStoresTest method validateNodeRel1.

private void validateNodeRel1(final long node, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long rel1, long rel2, final int relType1, final int relType2) throws IOException {
    assertTrue(nodeExists(node));
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    PropertyReceiver<DefinedProperty> receiver = newPropertyReceiver(props);
    propertyLoader.nodeLoadProperties(node, receiver);
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = getRecord(pStore, id);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("string1", data.value());
            nodeAddProperty(node, prop1.propertyKeyId(), "-string1");
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(1, data.value());
            nodeAddProperty(node, prop2.propertyKeyId(), -1);
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(true, data.value());
            nodeAddProperty(node, prop3.propertyKeyId(), false);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    count = validateAndCountRelationships(node, rel1, rel2, relType1, relType2);
    assertEquals(2, count);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Pair(org.neo4j.helpers.collection.Pair)

Example 44 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class NeoStoresTest method testProps1.

@Test
public void testProps1() throws Exception {
    initializeStores(storeDir, stringMap());
    startTx();
    long nodeId = nextId(Node.class);
    transaction.nodeDoCreate(nodeId);
    pStore.nextId();
    DefinedProperty prop = nodeAddProperty(nodeId, index("nisse"), 10);
    commitTx();
    ds.stop();
    initializeStores(storeDir, stringMap());
    startTx();
    DefinedProperty prop2 = nodeAddProperty(nodeId, prop.propertyKeyId(), 5);
    transaction.nodeDoRemoveProperty(nodeId, prop2);
    transaction.nodeDoDelete(nodeId);
    commitTx();
    ds.stop();
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Test(org.junit.Test)

Example 45 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class NeoStoresTest method validateRel1.

private void validateRel1(long rel, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long firstNode, long secondNode, int relType) throws IOException {
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    propertyLoader.relLoadProperties(rel, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = getRecord(pStore, id);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("string1", data.value());
            relAddProperty(rel, prop1.propertyKeyId(), "-string1");
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(1, data.value());
            relAddProperty(rel, prop2.propertyKeyId(), -1);
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(true, data.value());
            relAddProperty(rel, prop3.propertyKeyId(), false);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    assertRelationshipData(rel, firstNode, secondNode, relType);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Pair(org.neo4j.helpers.collection.Pair)

Aggregations

DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)47 Test (org.junit.Test)23 Pair (org.neo4j.helpers.collection.Pair)9 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)8 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)8 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)8 PropertyItem (org.neo4j.storageengine.api.PropertyItem)8 NodeItem (org.neo4j.storageengine.api.NodeItem)7 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)7 Property (org.neo4j.kernel.api.properties.Property)6 PropertyEntry (org.neo4j.graphdb.event.PropertyEntry)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)4 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)4 NeoStores (org.neo4j.kernel.impl.store.NeoStores)4 StorageProperty (org.neo4j.storageengine.api.StorageProperty)4 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 Statement (org.neo4j.kernel.api.Statement)3