use of org.neo4j.lock.Lock in project neo4j by neo4j.
the class RecordStorageEngineTest method shouldCloseLockGroupAfterAppliers.
@Test
void shouldCloseLockGroupAfterAppliers() throws Exception {
// given
long nodeId = 5;
LockService lockService = mock(LockService.class);
Lock nodeLock = mock(Lock.class);
when(lockService.acquireNodeLock(nodeId, EXCLUSIVE)).thenReturn(nodeLock);
// <-- simply so that we can use InOrder mockito construct
Consumer<Boolean> applierCloseCall = mock(Consumer.class);
CapturingTransactionApplierFactoryChain applier = new CapturingTransactionApplierFactoryChain(applierCloseCall);
RecordStorageEngine engine = recordStorageEngineBuilder().lockService(lockService).transactionApplierTransformer(applier::wrapAroundActualApplier).build();
CommandsToApply commandsToApply = mock(CommandsToApply.class);
when(commandsToApply.cursorContext()).thenReturn(NULL);
when(commandsToApply.accept(any())).thenAnswer(invocationOnMock -> {
// Visit one node command
Visitor<StorageCommand, IOException> visitor = invocationOnMock.getArgument(0);
NodeRecord after = new NodeRecord(nodeId);
after.setInUse(true);
visitor.visit(new Command.NodeCommand(new NodeRecord(nodeId), after));
return null;
});
// when
engine.apply(commandsToApply, TransactionApplicationMode.INTERNAL);
// then
InOrder inOrder = inOrder(lockService, applierCloseCall, nodeLock);
inOrder.verify(lockService).acquireNodeLock(nodeId, EXCLUSIVE);
inOrder.verify(applierCloseCall).accept(true);
inOrder.verify(nodeLock).release();
inOrder.verifyNoMoreInteractions();
}
Aggregations