Search in sources :

Example 11 with StorageStatement

use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.

the class StatementLifecycleTest method shouldReleaseStoreStatementWhenForceClosingStatements.

@Test
public void shouldReleaseStoreStatementWhenForceClosingStatements() throws Exception {
    // given
    KernelTransactionImplementation transaction = mock(KernelTransactionImplementation.class);
    StorageStatement storageStatement = mock(StorageStatement.class);
    KernelStatement statement = getKernelStatement(transaction, storageStatement);
    statement.acquire();
    // when
    statement.forceClose();
    // then
    verify(storageStatement).release();
}
Also used : StorageStatement(org.neo4j.storageengine.api.StorageStatement) Test(org.junit.Test)

Example 12 with StorageStatement

use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.

the class StorageLayerPropertyTest method should_get_all_node_properties.

@Test
public void should_get_all_node_properties() throws Exception {
    // GIVEN
    String longString = "AlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalong";
    Object[] properties = { longString, createNew(String.class), createNew(long.class), createNew(int.class), createNew(byte.class), createNew(short.class), createNew(boolean.class), createNew(char.class), createNew(float.class), createNew(double.class), array(0, String.class), array(0, long.class), array(0, int.class), array(0, byte.class), array(0, short.class), array(0, boolean.class), array(0, char.class), array(0, float.class), array(0, double.class), array(1, String.class), array(1, long.class), array(1, int.class), array(1, byte.class), array(1, short.class), array(1, boolean.class), array(1, char.class), array(1, float.class), array(1, double.class), array(256, String.class), array(256, long.class), array(256, int.class), array(256, byte.class), array(256, short.class), array(256, boolean.class), array(256, char.class), array(256, float.class), array(256, double.class) };
    int propKey = disk.propertyKeyGetOrCreateForName("prop");
    StorageStatement statement = state.getStoreStatement();
    for (Object value : properties) {
        // given
        long nodeId = createLabeledNode(db, singletonMap("prop", value), label1).getId();
        // when
        try (Cursor<NodeItem> node = statement.acquireSingleNodeCursor(nodeId)) {
            node.next();
            Lock lock = node.get().lock();
            try (Cursor<PropertyItem> props = statement.acquireSinglePropertyCursor(node.get().nextPropertyId(), propKey, lock)) {
                if (props.next()) {
                    Object propVal = props.get().value();
                    //then
                    assertTrue(propVal + ".valueEquals(" + value + ")", Property.property(propKey, propVal).valueEquals(value));
                } else {
                    fail();
                }
            }
        }
    }
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) StorageStatement(org.neo4j.storageengine.api.StorageStatement) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Lock(org.neo4j.kernel.impl.locking.Lock) Test(org.junit.Test)

Example 13 with StorageStatement

use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method addMockedIndexReader.

private IndexReader addMockedIndexReader(KernelStatement kernelStatement) throws IndexNotFoundKernelException {
    StorageStatement storageStatement = mock(StorageStatement.class);
    when(kernelStatement.getStoreStatement()).thenReturn(storageStatement);
    return addMockedIndexReader(storageStatement);
}
Also used : StorageStatement(org.neo4j.storageengine.api.StorageStatement)

Example 14 with StorageStatement

use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByNumberWithIndexQuery.

@SuppressWarnings("unchecked")
@Test
public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByNumberWithIndexQuery() throws Exception {
    // Given
    final int propertyKey = 2;
    final int inRange = 15;
    int lower = 10;
    int upper = 20;
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    StorageStatement storageStatement = mock(StorageStatement.class);
    when(statement.getStoreStatement()).thenReturn(storageStatement);
    when(txState.indexUpdatesForRangeSeekByNumber(index, lower, true, upper, false)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
    when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    when(txState.augmentSingleNodeCursor(any(Cursor.class), anyLong())).thenAnswer(invocationOnMock -> {
        long nodeId = (long) invocationOnMock.getArguments()[1];
        when(txState.augmentSinglePropertyCursor(any(Cursor.class), any(PropertyContainerState.class), eq(propertyKey))).thenReturn(asPropertyCursor(intProperty(propertyKey, inRange)));
        return asNodeCursor(nodeId, nodeId + 20000);
    });
    IndexReader indexReader = addMockedIndexReader(storageStatement);
    IndexQuery.NumberRangePredicate indexQuery = IndexQuery.range(index.schema().getPropertyId(), lower, true, upper, false);
    when(indexReader.query(indexQuery)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    when(storageStatement.acquireSingleNodeCursor(anyLong())).thenAnswer(invocationOnMock -> {
        long nodeId = (long) invocationOnMock.getArguments()[0];
        when(storeReadLayer.nodeGetProperty(eq(storageStatement), any(NodeItem.class), eq(propertyKey))).thenReturn(asPropertyCursor(intProperty(propertyKey, inRange)));
        return asNodeCursor(nodeId, nodeId + 20000);
    });
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, indexQuery);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StorageStatement(org.neo4j.storageengine.api.StorageStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) Cursor(org.neo4j.cursor.Cursor) StubCursors.asNodeCursor(org.neo4j.kernel.impl.api.state.StubCursors.asNodeCursor) StubCursors.asPropertyCursor(org.neo4j.kernel.impl.api.state.StubCursors.asPropertyCursor) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyContainerState(org.neo4j.storageengine.api.txstate.PropertyContainerState) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Example 15 with StorageStatement

use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.

the class NeoStoresTest method relAddProperty.

private DefinedProperty relAddProperty(long relationshipId, int key, Object value) {
    DefinedProperty property = Property.property(key, value);
    Property oldProperty = Property.noRelationshipProperty(relationshipId, key);
    try (StorageStatement statement = storeLayer.newStatement();
        Cursor<RelationshipItem> cursor = statement.acquireSingleRelationshipCursor(relationshipId)) {
        if (cursor.next()) {
            Property fetched = getProperty(key, statement, cursor.get().nextPropertyId());
            if (fetched != null) {
                oldProperty = fetched;
            }
        }
    }
    transaction.relationshipDoReplaceProperty(relationshipId, oldProperty, property);
    return property;
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) StorageStatement(org.neo4j.storageengine.api.StorageStatement) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Aggregations

StorageStatement (org.neo4j.storageengine.api.StorageStatement)15 Test (org.junit.Test)7 Procedures (org.neo4j.kernel.impl.proc.Procedures)3 NodeItem (org.neo4j.storageengine.api.NodeItem)3 StorageEngine (org.neo4j.storageengine.api.StorageEngine)3 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)3 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)3 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)2 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)2 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)2 CanWrite (org.neo4j.kernel.impl.factory.CanWrite)2 Locks (org.neo4j.kernel.impl.locking.Locks)2 SimpleStatementLocks (org.neo4j.kernel.impl.locking.SimpleStatementLocks)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Supplier (java.util.function.Supplier)1 Matchers.anyCollection (org.mockito.Matchers.anyCollection)1 Pool (org.neo4j.collection.pool.Pool)1