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 testTimer()
        public virtual void TestTimer()
        {
            // GIVEN
            FakeClock fakeClock = Clocks.fakeClock(10000, TimeUnit.MILLISECONDS);

            // WHEN
            RotationTimerFactory timerFactory = new RotationTimerFactory(fakeClock, 1000);

            RotationTimerFactory.RotationTimer timer        = timerFactory.CreateTimer();
            RotationTimerFactory.RotationTimer anotherTimer = timerFactory.CreateTimer();

            // THEN
            assertFalse(timer.TimedOut);
            assertEquals(0, timer.ElapsedTimeMillis);
            assertNotSame("Factory should construct different timers", timer, anotherTimer);

            // WHEN
            fakeClock = Clocks.fakeClock();
            RotationTimerFactory fakeTimerFactory = new RotationTimerFactory(fakeClock, 1000);

            RotationTimerFactory.RotationTimer fakeTimer = fakeTimerFactory.CreateTimer();
            fakeClock.Forward(1001, TimeUnit.MILLISECONDS);

            assertTrue(fakeTimer.TimedOut);
            assertEquals(1001, fakeTimer.ElapsedTimeMillis);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: ActiveState<Key> rotate(boolean force, RotationStrategy strategy, RotationTimerFactory timerFactory, System.Action<Headers.Builder> headersUpdater) throws java.io.IOException
            internal override ActiveState <Key> Rotate(bool force, RotationStrategy strategy, RotationTimerFactory timerFactory, System.Action <Headers.Builder> headersUpdater)
            {
                if (!force)
                {
                    RotationTimerFactory.RotationTimer rotationTimer = timerFactory.CreateTimer();
                    for (long expected = Threshold - PreState.store.version(), sleep = 10; PreState.applied() < expected; sleep = Math.Min(sleep * 2, 100))
                    {
                        if (rotationTimer.TimedOut)
                        {
                            throw new RotationTimeoutException(Threshold, PreState.store.version(), rotationTimer.ElapsedTimeMillis);
                        }
                        try
                        {
                            Thread.Sleep(sleep);
                        }
                        catch (InterruptedException e)
                        {
                            throw ( InterruptedIOException )(new InterruptedIOException("Rotation was interrupted.")).initCause(e);
                        }
                    }
                }
                Pair <File, KeyValueStoreFile> next = strategy.Next(File(), UpdateHeaders(headersUpdater), KeyFormat().filter(PreState.dataProvider()));

                return(PostState.create(ReadableState.Store(PreState.keyFormat(), next.Other()), next.First(), PreState.versionContextSupplier));
            }