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;
}
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();
}
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();
}
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;
}
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();
}
Aggregations