use of org.neo4j.lock.LockService in project neo4j by neo4j.
the class ApplyRecoveredTransactionsTest method applyExternalTransaction.
private void applyExternalTransaction(long transactionId, Command... commands) throws Exception {
LockService lockService = mock(LockService.class);
when(lockService.acquireNodeLock(anyLong(), any(LockType.class))).thenReturn(LockService.NO_LOCK);
when(lockService.acquireRelationshipLock(anyLong(), any(LockType.class))).thenReturn(LockService.NO_LOCK);
Map<IdType, WorkSync<IdGenerator, IdGeneratorUpdateWork>> idGeneratorWorkSyncs = new EnumMap<>(IdType.class);
for (IdType idType : IdType.values()) {
idGeneratorWorkSyncs.put(idType, new WorkSync<>(idGeneratorFactory.get(idType)));
}
NeoStoreTransactionApplierFactory applier = new NeoStoreTransactionApplierFactory(INTERNAL, neoStores, mock(CacheAccessBackDoor.class), lockService);
CommandsToApply tx = new GroupOfCommands(transactionId, commands);
CommandHandlerContract.apply(applier, txApplier -> {
tx.accept(txApplier);
return false;
}, new GroupOfCommands(transactionId, commands));
}
use of org.neo4j.lock.LockService in project neo4j by neo4j.
the class MultiIndexPopulationConcurrentUpdatesIT method dynamicIndexStoreViewWrapper.
private DynamicIndexStoreView dynamicIndexStoreViewWrapper(Runnable customAction, Supplier<StorageReader> readerSupplier, IndexingService.IndexProxyProvider indexProxies, Config config, JobScheduler scheduler) {
LockService lockService = LockService.NO_LOCK_SERVICE;
Locks locks = org.neo4j.kernel.impl.locking.Locks.NO_LOCKS;
FullScanStoreView fullScanStoreView = new FullScanStoreView(lockService, readerSupplier, Config.defaults(), scheduler);
return new DynamicIndexStoreViewWrapper(fullScanStoreView, indexProxies, lockService, locks, readerSupplier, customAction, config, scheduler);
}
use of org.neo4j.lock.LockService in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldLockUpdatedNodes.
@Test
void shouldLockUpdatedNodes() throws Exception {
neoStores = createStores();
// given
LockService locks = mock(LockService.class, RETURNS_MOCKS);
NodeStore nodeStore = neoStores.getNodeStore();
long[] nodes = { // allocate ids
nodeStore.nextId(NULL), nodeStore.nextId(NULL), nodeStore.nextId(NULL), nodeStore.nextId(NULL), nodeStore.nextId(NULL), nodeStore.nextId(NULL), nodeStore.nextId(NULL) };
{
// create the node records that we will modify in our main tx.
TransactionRecordState tx = newTransactionRecordState();
for (int i = 1; i < nodes.length - 1; i++) {
tx.nodeCreate(nodes[i]);
}
tx.nodeAddProperty(nodes[3], 0, Values.of("old"));
tx.nodeAddProperty(nodes[4], 0, Values.of("old"));
TransactionApplierFactory applier = buildApplier(locks);
apply(applier, transaction(tx));
}
reset(locks);
// These are the changes we want to assert locking on
TransactionRecordState tx = newTransactionRecordState();
tx.nodeCreate(nodes[0]);
tx.addLabelToNode(0, nodes[1]);
tx.nodeAddProperty(nodes[2], 0, Values.of("value"));
tx.nodeChangeProperty(nodes[3], 0, Values.of("value"));
tx.nodeRemoveProperty(nodes[4], 0);
tx.nodeDelete(nodes[5]);
tx.nodeCreate(nodes[6]);
tx.addLabelToNode(0, nodes[6]);
tx.nodeAddProperty(nodes[6], 0, Values.of("value"));
// commit( tx );
TransactionApplierFactory applier = buildApplier(locks);
apply(applier, transaction(tx));
// then
// create node, NodeCommand == 1 update
verify(locks).acquireNodeLock(nodes[0], EXCLUSIVE);
// add label, NodeCommand == 1 update
verify(locks).acquireNodeLock(nodes[1], EXCLUSIVE);
// add property, NodeCommand and PropertyCommand == 2 updates
verify(locks, times(2)).acquireNodeLock(nodes[2], EXCLUSIVE);
// update property, in place, PropertyCommand == 1 update
verify(locks).acquireNodeLock(nodes[3], EXCLUSIVE);
// remove property, updates the Node and the Property == 2 updates
verify(locks, times(2)).acquireNodeLock(nodes[4], EXCLUSIVE);
// delete node, single NodeCommand == 1 update
verify(locks).acquireNodeLock(nodes[5], EXCLUSIVE);
// create and add-label goes into the NodeCommand, add property is a PropertyCommand == 2 updates
verify(locks, times(2)).acquireNodeLock(nodes[6], EXCLUSIVE);
}
use of org.neo4j.lock.LockService 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