//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void verifyAsyncActionCausesConcurrentFlushingRush(org.neo4j.function.ThrowingConsumer<CheckPointerImpl,java.io.IOException> asyncAction) throws Exception private void VerifyAsyncActionCausesConcurrentFlushingRush(ThrowingConsumer <CheckPointerImpl, IOException> asyncAction) { AtomicLong limitDisableCounter = new AtomicLong(); AtomicLong observedRushCount = new AtomicLong(); BinaryLatch backgroundCheckPointStartedLatch = new BinaryLatch(); BinaryLatch forceCheckPointStartLatch = new BinaryLatch(); _limiter = new IOLimiterAnonymousInnerClass4(this, limitDisableCounter, forceCheckPointStartLatch); MockTxIdStore(); CheckPointerImpl checkPointer = checkPointer(); doAnswer(invocation => { backgroundCheckPointStartedLatch.Release(); forceCheckPointStartLatch.Await(); long newValue = limitDisableCounter.get(); observedRushCount.set(newValue); return(null); }).when(_storageEngine).flushAndForce(_limiter); Future <object> forceCheckPointer = forkFuture(() => { backgroundCheckPointStartedLatch.Await(); asyncAction.Accept(checkPointer); return(null); }); when(_threshold.isCheckPointingNeeded(anyLong(), eq(_info))).thenReturn(true); checkPointer.CheckPointIfNeeded(_info); forceCheckPointer.get(); assertThat(observedRushCount.get(), @is(1L)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCheckPointAlwaysWhenThereIsNoRunningCheckPoint() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCheckPointAlwaysWhenThereIsNoRunningCheckPoint() { // Given CheckPointerImpl checkPointing = CheckPointer(); when(_threshold.isCheckPointingNeeded(anyLong(), eq(_info))).thenReturn(false); MockTxIdStore(); checkPointing.Start(); // When long txId = checkPointing.TryCheckPoint(_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); }
//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(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void mustFlushAsFastAsPossibleDuringTryCheckPoint() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MustFlushAsFastAsPossibleDuringTryCheckPoint() { AtomicBoolean doneDisablingLimits = new AtomicBoolean(); _limiter = new IOLimiterAnonymousInnerClass3(this, doneDisablingLimits); MockTxIdStore(); CheckPointerImpl checkPointer = checkPointer(); checkPointer.TryCheckPoint(_info); assertTrue(doneDisablingLimits.get()); }
//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()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void mustUseIoLimiterFromFlushing() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MustUseIoLimiterFromFlushing() { _limiter = new IOLimiterAnonymousInnerClass(this); when(_threshold.isCheckPointingNeeded(anyLong(), eq(_info))).thenReturn(true, false); MockTxIdStore(); CheckPointerImpl checkPointing = CheckPointer(); checkPointing.Start(); checkPointing.CheckPointIfNeeded(_info); verify(_storageEngine).flushAndForce(_limiter); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotFlushIfItIsNotNeeded() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotFlushIfItIsNotNeeded() { // Given CheckPointerImpl checkPointing = CheckPointer(); when(_threshold.isCheckPointingNeeded(anyLong(), any(typeof(TriggerInfo)))).thenReturn(false); checkPointing.Start(); // When long txId = checkPointing.CheckPointIfNeeded(_info); // Then assertEquals(-1, txId); verifyZeroInteractions(_storageEngine); verifyZeroInteractions(_tracer); verifyZeroInteractions(_appender); }
//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)); }
//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); }
internal CheckPointerThread(CheckPointerImpl checkPointing, System.Threading.CountdownEvent startSignal, System.Threading.CountdownEvent completed) { this.CheckPointing = checkPointing; this.StartSignal = startSignal; this.Completed = completed; }