use of org.neo4j.storageengine.api.StorageEngine in project neo4j by neo4j.
the class KernelTransactionFactory method kernelTransactionWithInternals.
static Instances kernelTransactionWithInternals(SecurityContext securityContext) {
TransactionHeaderInformation headerInformation = new TransactionHeaderInformation(-1, -1, new byte[0]);
TransactionHeaderInformationFactory headerInformationFactory = mock(TransactionHeaderInformationFactory.class);
when(headerInformationFactory.create()).thenReturn(headerInformation);
StorageEngine storageEngine = mock(StorageEngine.class);
StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
StorageStatement storageStatement = mock(StorageStatement.class);
when(storeReadLayer.newStatement()).thenReturn(storageStatement);
when(storageEngine.storeReadLayer()).thenReturn(storeReadLayer);
KernelTransactionImplementation transaction = new KernelTransactionImplementation(mock(StatementOperationContainer.class), mock(SchemaWriteGuard.class), new TransactionHooks(), mock(ConstraintIndexCreator.class), new Procedures(), headerInformationFactory, mock(TransactionRepresentationCommitProcess.class), mock(TransactionMonitor.class), mock(Supplier.class), mock(Pool.class), Clocks.systemClock(), NULL, LockTracer.NONE, PageCursorTracerSupplier.NULL, storageEngine, new CanWrite());
StatementLocks statementLocks = new SimpleStatementLocks(new NoOpClient());
transaction.initialize(0, 0, statementLocks, KernelTransaction.Type.implicit, securityContext, 0L);
return new Instances(transaction, storageEngine, storeReadLayer, storageStatement);
}
use of org.neo4j.storageengine.api.StorageEngine in project neo4j by neo4j.
the class KernelTransactionsTest method newKernelTransactions.
private static KernelTransactions newKernelTransactions(boolean testKernelTransactions, TransactionCommitProcess commitProcess, StorageStatement firstStoreStatements, StorageStatement... otherStorageStatements) throws Throwable {
Locks locks = mock(Locks.class);
when(locks.newClient()).thenReturn(mock(Locks.Client.class));
StoreReadLayer readLayer = mock(StoreReadLayer.class);
when(readLayer.newStatement()).thenReturn(firstStoreStatements, otherStorageStatements);
StorageEngine storageEngine = mock(StorageEngine.class);
when(storageEngine.storeReadLayer()).thenReturn(readLayer);
doAnswer(invocation -> {
invocation.getArgumentAt(0, Collection.class).add(mock(StorageCommand.class));
return null;
}).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageStatement.class), any(ResourceLocker.class), anyLong());
return newKernelTransactions(locks, storageEngine, commitProcess, testKernelTransactions);
}
use of org.neo4j.storageengine.api.StorageEngine in project neo4j by neo4j.
the class TransactionRepresentationCommitProcessTest method shouldSuccessfullyCommitTransactionWithNoCommands.
@Test
public void shouldSuccessfullyCommitTransactionWithNoCommands() throws Exception {
// GIVEN
long txId = 11;
long commitTimestamp = System.currentTimeMillis();
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
TransactionAppender appender = new TestableTransactionAppender(transactionIdStore);
when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
StorageEngine storageEngine = mock(StorageEngine.class);
TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(appender, storageEngine);
PhysicalTransactionRepresentation noCommandTx = new PhysicalTransactionRepresentation(Collections.emptyList());
noCommandTx.setHeader(new byte[0], -1, -1, -1, -1, -1, -1);
// WHEN
commitProcess.commit(new TransactionToApply(noCommandTx), commitEvent, INTERNAL);
verify(transactionIdStore).transactionCommitted(txId, FakeCommitment.CHECKSUM, FakeCommitment.TIMESTAMP);
}
use of org.neo4j.storageengine.api.StorageEngine in project neo4j by neo4j.
the class TransactionRepresentationCommitProcessTest method shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly.
@Test
public void shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly() throws Exception {
// GIVEN
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
TransactionAppender appender = new TestableTransactionAppender(transactionIdStore);
long txId = 11;
when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
IOException rootCause = new IOException("Mock exception");
StorageEngine storageEngine = mock(StorageEngine.class);
doThrow(new IOException(rootCause)).when(storageEngine).apply(any(TransactionToApply.class), any(TransactionApplicationMode.class));
TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(appender, storageEngine);
TransactionToApply transaction = mockedTransaction();
// WHEN
try {
commitProcess.commit(transaction, commitEvent, INTERNAL);
} catch (TransactionFailureException e) {
assertThat(e.getMessage(), containsString("Could not apply the transaction to the store"));
assertTrue(contains(e, rootCause.getMessage(), rootCause.getClass()));
}
// THEN
// we can't verify transactionCommitted since that's part of the TransactionAppender, which we have mocked
verify(transactionIdStore, times(1)).transactionClosed(eq(txId), anyLong(), anyLong());
}
Aggregations