Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseLockGroupAfterAppliers() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCloseLockGroupAfterAppliers()
        {
            // given
            long        nodeId      = 5;
            LockService lockService = mock(typeof(LockService));
            Lock        nodeLock    = mock(typeof(Lock));

            when(lockService.AcquireNodeLock(nodeId, Org.Neo4j.Kernel.impl.locking.LockService_LockType.WriteLock)).thenReturn(nodeLock);
            System.Action <bool> applierCloseCall          = mock(typeof(System.Action));         // <-- simply so that we can use InOrder mockito construct
            CapturingBatchTransactionApplierFacade applier = new CapturingBatchTransactionApplierFacade(this, applierCloseCall);
            RecordStorageEngine engine          = RecordStorageEngineBuilder().lockService(lockService).transactionApplierTransformer(applier.wrapAroundActualApplier).build();
            CommandsToApply     commandsToApply = mock(typeof(CommandsToApply));

            when(commandsToApply.Accept(any())).thenAnswer(invocationOnMock =>
            {
                // Visit one node command
                Visitor <StorageCommand, IOException> visitor = invocationOnMock.getArgument(0);
                NodeRecord after = new NodeRecord(nodeId);
                after.InUse      = 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, Org.Neo4j.Kernel.impl.locking.LockService_LockType.WriteLock);
            inOrder.verify(applierCloseCall).accept(true);
            inOrder.verify(nodeLock, times(1)).release();
            inOrder.verifyNoMoreInteractions();
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void apply(org.neo4j.storageengine.api.CommandsToApply batch, org.neo4j.storageengine.api.TransactionApplicationMode mode) throws Exception
        public override void Apply(CommandsToApply batch, TransactionApplicationMode mode)
        {
            // Have these command appliers as separate try-with-resource to have better control over
            // point between closing this and the locks above
            try
            {
                using (IndexActivator indexActivator = new IndexActivator(_indexingService), LockGroup locks = new LockGroup(), BatchTransactionApplier batchApplier = Applier(mode, indexActivator))
                {
                    while (batch != null)
                    {
                        using (TransactionApplier txApplier = batchApplier.StartTx(batch, locks))
                        {
                            batch.Accept(txApplier);
                        }
                        batch = batch.Next();
                    }
                }
            }
            catch (Exception cause)
            {
                TransactionApplyKernelException kernelException = new TransactionApplyKernelException(cause, "Failed to apply transaction: %s", batch);
                _databaseHealth.panic(kernelException);
                throw kernelException;
            }
        }