示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldForceCheckPointAlways() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldForceCheckPointAlways()
        {
            // Given
            CheckPointerImpl checkPointing = CheckPointer();

            when(_threshold.isCheckPointingNeeded(anyLong(), eq(_info))).thenReturn(false);
            MockTxIdStore();

            checkPointing.Start();

            // When
            long txId = checkPointing.ForceCheckPoint(_info);

            // Then
            assertEquals(_transactionId, txId);
            verify(_storageEngine, times(1)).flushAndForce(_limiter);
            verify(_health, times(2)).assertHealthy(typeof(IOException));
            verify(_appender, times(1)).checkPoint(eq(_logPosition), any(typeof(LogCheckPointEvent)));
            verify(_threshold, times(1)).initialize(_initialTransactionId);
            verify(_threshold, times(1)).checkPointHappened(_transactionId);
            verify(_threshold, never()).isCheckPointingNeeded(_transactionId, _info);
            verify(_logPruning, times(1)).pruneLogs(_logPosition.LogVersion);
            verify(_tracer, times(1)).beginCheckPoint();
            verifyNoMoreInteractions(_storageEngine, _health, _appender, _threshold);
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void forceCheckPointShouldWaitTheCurrentCheckPointingToCompleteBeforeRunning() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ForceCheckPointShouldWaitTheCurrentCheckPointingToCompleteBeforeRunning()
        {
            // Given
            Lock @lock = new ReentrantLock();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.locks.Lock spyLock = spy(lock);
            Lock spyLock = spy(@lock);

            doAnswer(invocation =>
            {
                verify(_appender).checkPoint(any(typeof(LogPosition)), any(typeof(LogCheckPointEvent)));
                reset(_appender);
                invocation.callRealMethod();
                return(null);
            }).when(spyLock).unlock();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final CheckPointerImpl checkPointing = checkPointer(mutex(spyLock));
            CheckPointerImpl checkPointing = CheckPointer(Mutex(spyLock));

            MockTxIdStore();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch startSignal = new java.util.concurrent.CountDownLatch(2);
            System.Threading.CountdownEvent startSignal = new System.Threading.CountdownEvent(2);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch completed = new java.util.concurrent.CountDownLatch(2);
            System.Threading.CountdownEvent completed = new System.Threading.CountdownEvent(2);

            checkPointing.Start();

            Thread checkPointerThread = new CheckPointerThread(checkPointing, startSignal, completed);

            Thread forceCheckPointThread = new Thread(() =>
            {
                try
                {
                    startSignal.Signal();
                    startSignal.await();
                    checkPointing.ForceCheckPoint(_info);

                    completed.Signal();
                }
                catch (Exception e)
                {
                    throw new Exception(e);
                }
            });

            // when
            checkPointerThread.Start();
            forceCheckPointThread.Start();

            completed.await();

            verify(spyLock, times(2)).@lock();
            verify(spyLock, times(2)).unlock();
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustFlushAsFastAsPossibleDuringForceCheckPoint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustFlushAsFastAsPossibleDuringForceCheckPoint()
        {
            AtomicBoolean doneDisablingLimits = new AtomicBoolean();

            _limiter = new IOLimiterAnonymousInnerClass2(this, doneDisablingLimits);
            MockTxIdStore();
            CheckPointerImpl checkPointer = checkPointer();

            checkPointer.ForceCheckPoint(new SimpleTriggerInfo("test"));
            assertTrue(doneDisablingLimits.get());
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void tryCheckPointMustWaitForOnGoingCheckPointsToCompleteAsLongAsTimeoutPredicateIsFalse() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TryCheckPointMustWaitForOnGoingCheckPointsToCompleteAsLongAsTimeoutPredicateIsFalse()
        {
            MockTxIdStore();
            CheckPointerImpl checkPointer        = checkPointer();
            BinaryLatch      arriveFlushAndForce = new BinaryLatch();
            BinaryLatch      finishFlushAndForce = new BinaryLatch();

            doAnswer(invocation =>
            {
                arriveFlushAndForce.Release();
                finishFlushAndForce.Await();
                return(null);
            }).when(_storageEngine).flushAndForce(_limiter);

            Thread forceCheckPointThread = new Thread(() =>
            {
                try
                {
                    checkPointer.ForceCheckPoint(_info);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new Exception(e);
                }
            });

            forceCheckPointThread.Start();

            arriveFlushAndForce.Await();               // Wait for force-thread to arrive in flushAndForce().

            System.Func <bool> predicate = mock(typeof(System.Func <bool>));
            when(predicate()).thenReturn(false, false, true);
            assertThat(checkPointer.TryCheckPoint(_info, predicate), @is(-1L)); // We decided to not wait for the on-going check point to finish.

            finishFlushAndForce.Release();                                      // Let the flushAndForce complete.
            forceCheckPointThread.Join();

            assertThat(checkPointer.TryCheckPoint(_info, predicate), @is(this._transactionId));
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void tryCheckPointShouldWaitTheCurrentCheckPointingToCompleteNoRunCheckPointButUseTheTxIdOfTheEarlierRun() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TryCheckPointShouldWaitTheCurrentCheckPointingToCompleteNoRunCheckPointButUseTheTxIdOfTheEarlierRun()
        {
            // Given
            Lock @lock = mock(typeof(Lock));

            when(@lock.tryLock(anyLong(), any(typeof(TimeUnit)))).thenReturn(true);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final CheckPointerImpl checkPointing = checkPointer(mutex(lock));
            CheckPointerImpl checkPointing = CheckPointer(Mutex(@lock));

            MockTxIdStore();

            checkPointing.ForceCheckPoint(_info);

            verify(_appender).checkPoint(eq(_logPosition), any(typeof(LogCheckPointEvent)));
            reset(_appender);

            checkPointing.TryCheckPoint(_info);

            verifyNoMoreInteractions(_appender);
        }