Search in sources :

Example 1 with StorageStatement

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

the class NeoStoresTest method nodeAddProperty.

private DefinedProperty nodeAddProperty(long nodeId, int key, Object value) {
    DefinedProperty property = Property.property(key, value);
    DefinedProperty oldProperty = NO_SUCH_PROPERTY;
    try (StorageStatement statement = storeLayer.newStatement();
        Cursor<NodeItem> cursor = statement.acquireSingleNodeCursor(nodeId)) {
        if (cursor.next()) {
            if (cursor.next()) {
                DefinedProperty fetched = getProperty(key, statement, cursor.get().nextPropertyId());
                if (fetched != null) {
                    oldProperty = fetched;
                }
            }
        }
    }
    if (oldProperty == NO_SUCH_PROPERTY) {
        transaction.nodeDoAddProperty(nodeId, property);
    } else {
        transaction.nodeDoChangeProperty(nodeId, oldProperty, property);
    }
    return property;
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NodeItem(org.neo4j.storageengine.api.NodeItem) StorageStatement(org.neo4j.storageengine.api.StorageStatement)

Example 2 with StorageStatement

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

the class KernelTransactionsTest method transactionClosesUnderlyingStoreStatementWhenDisposed.

@Test
public void transactionClosesUnderlyingStoreStatementWhenDisposed() throws Throwable {
    StorageStatement storeStatement1 = mock(StorageStatement.class);
    StorageStatement storeStatement2 = mock(StorageStatement.class);
    StorageStatement storeStatement3 = mock(StorageStatement.class);
    KernelTransactions kernelTransactions = newKernelTransactions(mock(TransactionCommitProcess.class), storeStatement1, storeStatement2, storeStatement3);
    // start and close 3 transactions from different threads
    startAndCloseTransaction(kernelTransactions);
    Executors.newSingleThreadExecutor().submit(() -> startAndCloseTransaction(kernelTransactions)).get();
    Executors.newSingleThreadExecutor().submit(() -> startAndCloseTransaction(kernelTransactions)).get();
    kernelTransactions.disposeAll();
    verify(storeStatement1).close();
    verify(storeStatement2).close();
    verify(storeStatement3).close();
}
Also used : StorageStatement(org.neo4j.storageengine.api.StorageStatement) Test(org.junit.Test)

Example 3 with StorageStatement

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

the class StatementLifecycleTest method shouldReleaseStoreStatementOnlyWhenReferenceCountDownToZero.

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

Example 4 with StorageStatement

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

the class StatementOperationsTestHelper method mockedState.

public static KernelStatement mockedState(final TransactionState txState) {
    KernelStatement state = mock(KernelStatement.class);
    Locks.Client locks = mock(Locks.Client.class);
    try {
        IndexReader indexReader = mock(IndexReader.class);
        when(indexReader.query(Matchers.isA(IndexQuery.ExactPredicate.class))).thenReturn(PrimitiveLongCollections.emptyIterator());
        StorageStatement storageStatement = mock(StorageStatement.class);
        when(storageStatement.getIndexReader(Matchers.any())).thenReturn(indexReader);
        when(state.getStoreStatement()).thenReturn(storageStatement);
    } catch (IndexNotFoundKernelException | IndexNotApplicableKernelException e) {
        throw new Error(e);
    }
    when(state.txState()).thenReturn(txState);
    when(state.hasTxStateWithChanges()).thenAnswer(invocation -> txState.hasChanges());
    when(state.locks()).thenReturn(new SimpleStatementLocks(locks));
    when(state.readOperations()).thenReturn(mock(ReadOperations.class));
    return state;
}
Also used : SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) LegacyIndexReadOperations(org.neo4j.kernel.impl.api.operations.LegacyIndexReadOperations) ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) EntityReadOperations(org.neo4j.kernel.impl.api.operations.EntityReadOperations) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException) StorageStatement(org.neo4j.storageengine.api.StorageStatement) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) Locks(org.neo4j.kernel.impl.locking.Locks) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Example 5 with StorageStatement

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

the class KernelStatementTest method assertStatementIsNotOpenWhileAcquireIsNotInvoked.

@Test(expected = NotInTransactionException.class)
public void assertStatementIsNotOpenWhileAcquireIsNotInvoked() {
    KernelTransactionImplementation transaction = mock(KernelTransactionImplementation.class);
    TxStateHolder txStateHolder = mock(TxStateHolder.class);
    StorageStatement storeStatement = mock(StorageStatement.class);
    AccessCapability accessCapability = mock(AccessCapability.class);
    Procedures procedures = mock(Procedures.class);
    KernelStatement statement = new KernelStatement(transaction, txStateHolder, storeStatement, procedures, accessCapability, LockTracer.NONE);
    statement.assertOpen();
}
Also used : TxStateHolder(org.neo4j.kernel.api.txstate.TxStateHolder) AccessCapability(org.neo4j.kernel.impl.factory.AccessCapability) StorageStatement(org.neo4j.storageengine.api.StorageStatement) Procedures(org.neo4j.kernel.impl.proc.Procedures) Test(org.junit.Test)

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