use of org.neo4j.kernel.impl.locking.LockGroup in project neo4j by neo4j.
the class ReplicatedTokenStateMachine method applyToStore.
private int applyToStore(Collection<StorageCommand> commands, long logIndex) throws NoSuchEntryException {
int tokenId = extractTokenId(commands);
PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation(commands);
representation.setHeader(encodeLogIndexAsTxHeader(logIndex), 0, 0, 0, 0L, 0L, 0);
try (LockGroup ignored = new LockGroup()) {
commitProcess.commit(new TransactionToApply(representation), CommitEvent.NULL, TransactionApplicationMode.EXTERNAL);
} catch (TransactionFailureException e) {
throw new RuntimeException(e);
}
return tokenId;
}
use of org.neo4j.kernel.impl.locking.LockGroup in project neo4j by neo4j.
the class CommandHandlerContract method apply.
/**
* In case the transactions do not have the commands to apply, use this method to apply any commands you want with a
* given {@link ApplyFunction} instead.
*
* @param applier to use
* @param function which knows what to do with the {@link TransactionApplier}.
* @param transactions are only used to create {@link TransactionApplier}s. The actual work is delegated to the
* function.
* @return the boolean-and result of all function operations.
*/
public static boolean apply(BatchTransactionApplier applier, ApplyFunction function, TransactionToApply... transactions) throws Exception {
boolean result = true;
for (TransactionToApply tx : transactions) {
try (TransactionApplier txApplier = applier.startTx(tx, new LockGroup())) {
result &= function.apply(txApplier);
}
}
applier.close();
return result;
}
use of org.neo4j.kernel.impl.locking.LockGroup in project neo4j by neo4j.
the class BatchTransactionApplierFacadeTest method testStartTxCorrectOrderWithLockGroup.
@Test
public void testStartTxCorrectOrderWithLockGroup() throws Exception {
// GIVEN
TransactionToApply tx = mock(TransactionToApply.class);
LockGroup lockGroup = mock(LockGroup.class);
// WHEN
TransactionApplierFacade result = (TransactionApplierFacade) facade.startTx(tx, lockGroup);
// THEN
InOrder inOrder = inOrder(applier1, applier2, applier3);
inOrder.verify(applier1).startTx(tx, lockGroup);
inOrder.verify(applier2).startTx(tx, lockGroup);
inOrder.verify(applier3).startTx(tx, lockGroup);
assertEquals(txApplier1, result.appliers[0]);
assertEquals(txApplier2, result.appliers[1]);
assertEquals(txApplier3, result.appliers[2]);
assertEquals(3, result.appliers.length);
}
Aggregations