use of org.neo4j.storageengine.api.CommandsToApply in project neo4j by neo4j.
the class RecordStorageEngineTest method newTransactionThatFailsWith.
private static CommandsToApply newTransactionThatFailsWith(Exception error) throws IOException {
CommandsToApply transaction = mock(CommandsToApply.class);
doThrow(error).when(transaction).accept(any());
long txId = ThreadLocalRandom.current().nextLong(0, 1000);
when(transaction.transactionId()).thenReturn(txId);
return transaction;
}
use of org.neo4j.storageengine.api.CommandsToApply in project neo4j by neo4j.
the class CommandHandlerContract method apply.
/**
* Simply calls through to the {@link CommandStream#accept(Visitor)} method for each {@link
* CommandsToApply} given. This assumes that the {@link TransactionApplierFactory} will return {@link
* TransactionApplier}s which actually do the work and that the transaction has all the relevant data.
*
* @param applier to use
* @param transactions to apply
*/
public static void apply(TransactionApplierFactory applier, CommandsToApply... transactions) throws Exception {
var batchContext = mock(BatchContext.class);
when(batchContext.getLockGroup()).thenReturn(new LockGroup());
when(batchContext.getIdUpdateListener()).thenReturn(IdUpdateListener.IGNORE);
when(batchContext.getIndexActivator()).thenReturn(mock(IndexActivator.class));
for (CommandsToApply tx : transactions) {
try (TransactionApplier txApplier = applier.startTx(tx, batchContext)) {
tx.accept(txApplier);
}
}
}
use of org.neo4j.storageengine.api.CommandsToApply in project neo4j by neo4j.
the class BatchingNeoStoresTest method apply.
private static void apply(TxState txState, CommandCreationContext commandCreationContext, RecordStorageEngine storageEngine) throws Exception {
List<StorageCommand> commands = new ArrayList<>();
try (RecordStorageReader storageReader = storageEngine.newReader()) {
storageEngine.createCommands(commands, txState, storageReader, commandCreationContext, ResourceLocker.IGNORE, LockTracer.NONE, BASE_TX_ID, v -> v, NULL, INSTANCE);
CommandsToApply apply = new TransactionToApply(new PhysicalTransactionRepresentation(commands, new byte[0], 0, 0, 0, 0, ANONYMOUS), NULL);
storageEngine.apply(apply, TransactionApplicationMode.INTERNAL);
}
}
use of org.neo4j.storageengine.api.CommandsToApply in project neo4j by neo4j.
the class RecordStorageEngine method apply.
@Override
public void apply(CommandsToApply batch, TransactionApplicationMode mode) throws Exception {
TransactionApplierFactoryChain batchApplier = applierChain(mode);
CommandsToApply initialBatch = batch;
try (BatchContext context = createBatchContext(batchApplier, batch)) {
while (batch != null) {
try (TransactionApplier txApplier = batchApplier.startTx(batch, context)) {
batch.accept(txApplier);
}
batch = batch.next();
}
} catch (Throwable cause) {
TransactionApplyKernelException kernelException = new TransactionApplyKernelException(cause, "Failed to apply transaction: %s", batch == null ? initialBatch : batch);
databaseHealth.panic(kernelException);
throw kernelException;
}
}
use of org.neo4j.storageengine.api.CommandsToApply in project neo4j by neo4j.
the class WriteTransactionCommandOrderingTest method shouldExecuteCommandsInTheSameOrderRegardlessOfItBeingRecoveredOrNot.
@Test
void shouldExecuteCommandsInTheSameOrderRegardlessOfItBeingRecoveredOrNot() throws Exception {
// Given
TransactionRecordState tx = injectAllPossibleCommands();
// When
CommandsToApply commands = transactionRepresentationOf(tx);
// Then
final OrderVerifyingCommandHandler orderVerifyingCommandHandler = new OrderVerifyingCommandHandler();
commands.accept(element -> ((Command) element).handle(orderVerifyingCommandHandler));
}
Aggregations