Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSlowlyReduceTheNumberOfResourcesInThePoolWhenResourcesAreReleased() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSlowlyReduceTheNumberOfResourcesInThePoolWhenResourcesAreReleased()
        {
            // given
            const int poolMinSize = 50;
            const int poolMaxSize = 200;

            StatefulMonitor stateMonitor = new StatefulMonitor(this);
            FakeClock       clock        = FakeClocks;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final SomethingResourcePool pool = getResourcePool(stateMonitor, clock, poolMinSize);
            SomethingResourcePool pool = GetResourcePool(stateMonitor, clock, poolMinSize);

            AcquireResourcesAndExceedTimeout(pool, clock, poolMaxSize);

            // when
            // After the peak, stay below MIN_SIZE concurrent usage, using up all already present resources.
            ExceedTimeout(clock);
            for (int i = 0; i < poolMaxSize; i++)
            {
                AcquireFromPool(pool, 1)[0].release();
            }

            // then
            // currentPeakSize must have reset from the latest check to minimum size.
            assertEquals(1, stateMonitor.CurrentPeakSize.get());                 // because of timeout
            // targetSize must be set to MIN_SIZE since currentPeakSize was that 2 checks ago and didn't increase
            assertEquals(poolMinSize, stateMonitor.TargetSize.get());
            // Only pooled resources must be used, disposing what is in excess
            // +1 that was used to trigger exceed timeout check
            assertEquals(poolMinSize, pool.UnusedSize());
            assertEquals(poolMaxSize - poolMinSize + 1, stateMonitor.DisposedConflict.get());
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSlowlyReduceTheNumberOfFlyweightsInThePoolWhenFlyweightsAreReleased()
        internal virtual void ShouldSlowlyReduceTheNumberOfFlyweightsInThePoolWhenFlyweightsAreReleased()
        {
            // given
            const int minSize = 50;
            const int maxSize = 200;

            StatefulMonitor stateMonitor = new StatefulMonitor();
            FakeClock       clock        = new FakeClock();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LinkedQueuePool<Object> pool = getLinkedQueuePool(stateMonitor, clock, MIN_SIZE);
            LinkedQueuePool <object>          pool    = GetLinkedQueuePool(stateMonitor, clock, minSize);
            IList <FlyweightHolder <object> > holders = new LinkedList <FlyweightHolder <object> >();

            BuildAPeakOfAcquiredFlyweightsAndTriggerAlarmWithSideEffects(maxSize, clock, pool, holders);

            // when
            // After the peak, stay below MIN_SIZE concurrent usage, using up all already present Flyweights.
            clock.Forward(110, TimeUnit.MILLISECONDS);
            for (int i = 0; i < maxSize; i++)
            {
                AcquireFromPool(pool, 1)[0].release();
            }

            // then

            // currentPeakSize must have reset from the latest alarm to MIN_SIZE.
            assertEquals(1, stateMonitor.CurrentPeakSize.get());                 // Alarm
            // targetSize must be set to MIN_SIZE since currentPeakSize was that 2 alarms ago and didn't increase
            assertEquals(minSize, stateMonitor.TargetSize.get());
            // Only pooled Flyweights must be used, disposing what is in excess
            // +1 for the alarm from buildAPeakOfAcquiredFlyweightsAndTriggerAlarmWithSideEffects
            assertEquals(maxSize - minSize + 1, stateMonitor.DisposedConflict.get());
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKeepSmallPeakAndNeverDisposeIfAcquireAndReleaseContinuously() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldKeepSmallPeakAndNeverDisposeIfAcquireAndReleaseContinuously()
        {
            // given
            const int poolMinSize = 1;

            StatefulMonitor stateMonitor = new StatefulMonitor(this);
            FakeClock       clock        = FakeClocks;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ResourcePool<Something> pool = getResourcePool(stateMonitor, clock, poolMinSize);
            ResourcePool <Something> pool = GetResourcePool(stateMonitor, clock, poolMinSize);

            // when
            for (int i = 0; i < 200; i++)
            {
                IList <ResourceHolder>          newOnes = AcquireFromPool(pool, 1);
                System.Threading.CountdownEvent release = new System.Threading.CountdownEvent(newOnes.Count);
                foreach (ResourceHolder newOne in newOnes)
                {
                    newOne.Release(release);
                }
                release.await();
            }

            // then
            assertEquals(-1, stateMonitor.CurrentPeakSize.get());                 // no alarm has rung, -1 is the default
            assertEquals(1, stateMonitor.CreatedConflict.get());
            assertEquals(0, stateMonitor.DisposedConflict.get());                 // we should always be below min size, so 0 dispose calls
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpdateTargetSizeWhenSpikesOccur() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUpdateTargetSizeWhenSpikesOccur()
        {
            // given
            const int poolMinSize = 5;
            const int poolMaxSize = 10;

            StatefulMonitor stateMonitor = new StatefulMonitor(this);
            FakeClock       clock        = FakeClocks;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ResourcePool<Something> pool = getResourcePool(stateMonitor, clock, poolMinSize);
            ResourcePool <Something> pool = GetResourcePool(stateMonitor, clock, poolMinSize);

            // when
            IList <ResourceHolder> holders = AcquireFromPool(pool, poolMaxSize);

            ExceedTimeout(clock);
            ((IList <ResourceHolder>)holders).AddRange(AcquireFromPool(pool, 1));                      // Needed to trigger the alarm

            // then
            assertEquals(poolMaxSize + 1, stateMonitor.CurrentPeakSize.get());
            // We have not released anything, so targetSize will not be reduced
            assertEquals(poolMaxSize + 1, stateMonitor.TargetSize.get());                 // + 1 from the acquire

            foreach (ResourceHolder holder in holders)
            {
                holder.End();
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldKeepSmallPeakAndNeverDisposeIfAcquireAndReleaseContinuously()
        internal virtual void ShouldKeepSmallPeakAndNeverDisposeIfAcquireAndReleaseContinuously()
        {
            // given
            const int minSize = 1;

            StatefulMonitor stateMonitor = new StatefulMonitor();
            FakeClock       clock        = new FakeClock();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LinkedQueuePool<Object> pool = getLinkedQueuePool(stateMonitor, clock, MIN_SIZE);
            LinkedQueuePool <object> pool = GetLinkedQueuePool(stateMonitor, clock, minSize);

            // when
            for (int i = 0; i < 200; i++)
            {
                IList <FlyweightHolder <object> > newOnes = AcquireFromPool(pool, 1);
                foreach (FlyweightHolder newOne in newOnes)
                {
                    newOne.release();
                }
            }

            // then
            assertEquals(-1, stateMonitor.CurrentPeakSize.get());                 // no alarm has rung, -1 is the default
            assertEquals(1, stateMonitor.CreatedConflict.get());
            assertEquals(0, stateMonitor.DisposedConflict.get());                 // we should always be below min size, so 0 dispose calls
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBuildUpGracefullyWhilePassingMinPoolSizeBeforeTimerRings()
        internal virtual void ShouldBuildUpGracefullyWhilePassingMinPoolSizeBeforeTimerRings()
        {
            // GIVEN
            StatefulMonitor stateMonitor = new StatefulMonitor();
            FakeClock       clock        = new FakeClock();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LinkedQueuePool<Object> pool = getLinkedQueuePool(stateMonitor, clock, 5);
            LinkedQueuePool <object> pool = GetLinkedQueuePool(stateMonitor, clock, 5);

            // WHEN
            IList <FlyweightHolder <object> > flyweightHolders = AcquireFromPool(pool, 15);

            foreach (FlyweightHolder <object> flyweightHolder in flyweightHolders)
            {
                flyweightHolder.Release();
            }

            // THEN
            // The clock hasn't ticked, so these two should be unset
            assertEquals(-1, stateMonitor.CurrentPeakSize.get());
            assertEquals(-1, stateMonitor.TargetSize.get());
            // We obviously created 15 threads
            assertEquals(15, stateMonitor.CreatedConflict.get());
            // And of those 10 are not needed and therefore disposed on release (min size is 5)
            assertEquals(10, stateMonitor.DisposedConflict.get());
        }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReclaimAndRecreateWhenUsageGoesDownBetweenSpikes() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReclaimAndRecreateWhenUsageGoesDownBetweenSpikes()
        {
            // given
            const int poolMinSize = 50;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int bellowPoolMinSize = poolMinSize / 5;
            int       bellowPoolMinSize = poolMinSize / 5;
            const int poolMaxSize       = 200;

            StatefulMonitor stateMonitor = new StatefulMonitor(this);
            FakeClock       clock        = FakeClocks;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final SomethingResourcePool pool = getResourcePool(stateMonitor, clock, poolMinSize);
            SomethingResourcePool pool = GetResourcePool(stateMonitor, clock, poolMinSize);

            AcquireResourcesAndExceedTimeout(pool, clock, poolMaxSize);

            // when
            // After the peak, stay well below concurrent usage, using up all already present resources in the process
            ExceedTimeout(clock);
            // Requires some rounds to happen, since there is constant racing between releasing and acquiring which does
            // not always result in reaping of resources, as there is reuse
            for (int i = 0; i < 30; i++)
            {
                // The latch is necessary to reduce races between batches
                System.Threading.CountdownEvent release = new System.Threading.CountdownEvent(bellowPoolMinSize);
                foreach (ResourceHolder holder in AcquireFromPool(pool, bellowPoolMinSize))
                {
                    holder.Release(release);
                }
                release.await();
                ExceedTimeout(clock);
            }

            // then
            // currentPeakSize should not be higher than bellowPoolMinSize
            assertTrue(stateMonitor.CurrentPeakSize.get().ToString(), stateMonitor.CurrentPeakSize.get() <= bellowPoolMinSize);
            // target size should remain at pool min size
            assertEquals(poolMinSize, stateMonitor.TargetSize.get());
            assertEquals(poolMinSize, pool.UnusedSize());
            // only the excess from the pool max size down to min size must have been disposed
            // +1 that was used to trigger initial exceed timeout check
            assertEquals(poolMaxSize - poolMinSize + 1, stateMonitor.DisposedConflict.get());

            stateMonitor.CreatedConflict.set(0);
            stateMonitor.DisposedConflict.set(0);

            // when
            // After the lull, recreate a peak
            AcquireResourcesAndExceedTimeout(pool, clock, poolMaxSize);

            // then
            assertEquals(poolMaxSize - poolMinSize + 1, stateMonitor.CreatedConflict.get());
            assertEquals(0, stateMonitor.DisposedConflict.get());
        }
Beispiel #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReclaimAndRecreateWhenLullBetweenSpikesOccurs()
        internal virtual void ShouldReclaimAndRecreateWhenLullBetweenSpikesOccurs()
        {
            // given
            const int minSize = 50;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int BELOW_MIN_SIZE = MIN_SIZE / 5;
            int       belowMinSize = minSize / 5;
            const int maxSize      = 200;

            StatefulMonitor stateMonitor = new StatefulMonitor();
            FakeClock       clock        = new FakeClock();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LinkedQueuePool<Object> pool = getLinkedQueuePool(stateMonitor, clock, MIN_SIZE);
            LinkedQueuePool <object>          pool    = GetLinkedQueuePool(stateMonitor, clock, minSize);
            IList <FlyweightHolder <object> > holders = new LinkedList <FlyweightHolder <object> >();

            BuildAPeakOfAcquiredFlyweightsAndTriggerAlarmWithSideEffects(maxSize, clock, pool, holders);

            // when
            // After the peak, stay well below concurrent usage, using up all already present Flyweights in the process
            clock.Forward(110, TimeUnit.MILLISECONDS);
            // Requires some rounds to happen, since there is constant racing between releasing and acquiring which does
            // not always result in reaping of Flyweights, as there is reuse
            for (int i = 0; i < 30; i++)
            {
                // The latch is necessary to reduce races between batches
                foreach (FlyweightHolder holder in AcquireFromPool(pool, belowMinSize))
                {
                    holder.release();
                }
                clock.Forward(110, TimeUnit.MILLISECONDS);
            }

            // then
            // currentPeakSize should be at MIN_SIZE / 5
            assertTrue(stateMonitor.CurrentPeakSize.get() <= belowMinSize, "Expected " + stateMonitor.CurrentPeakSize.get() + " <= " + belowMinSize);
            // target size should remain at MIN_SIZE
            assertEquals(minSize, stateMonitor.TargetSize.get());
            // only the excess from the MAX_SIZE down to min size must have been disposed
            // +1 for the alarm from buildAPeakOfAcquiredFlyweightsAndTriggerAlarmWithSideEffects
            assertEquals(maxSize - minSize + 1, stateMonitor.DisposedConflict.get());

            stateMonitor.CreatedConflict.set(0);
            stateMonitor.DisposedConflict.set(0);

            // when
            // After the lull, recreate a peak
            ((IList <FlyweightHolder <object> >)holders).AddRange(AcquireFromPool(pool, maxSize));

            // then
            assertEquals(maxSize - minSize, stateMonitor.CreatedConflict.get());
            assertEquals(0, stateMonitor.DisposedConflict.get());
        }
Beispiel #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldMaintainPoolAtHighWatermarkWhenConcurrentUsagePassesMinSize()
        internal virtual void ShouldMaintainPoolAtHighWatermarkWhenConcurrentUsagePassesMinSize()
        {
            // given
            const int minSize = 50;
            const int maxSize = 200;
            const int midSize = 90;

            StatefulMonitor stateMonitor = new StatefulMonitor();
            FakeClock       clock        = new FakeClock();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LinkedQueuePool<Object> pool = getLinkedQueuePool(stateMonitor, clock, MIN_SIZE);
            LinkedQueuePool <object>          pool    = GetLinkedQueuePool(stateMonitor, clock, minSize);
            IList <FlyweightHolder <object> > holders = new LinkedList <FlyweightHolder <object> >();

            // when
            BuildAPeakOfAcquiredFlyweightsAndTriggerAlarmWithSideEffects(maxSize, clock, pool, holders);

            // then
            assertEquals(maxSize + 1, stateMonitor.CurrentPeakSize.get());                 // the peak method above does +1 on the peak

            // when

            /* After the peak, stay at MID_SIZE concurrent usage, using up all already present Flyweights in the process
             * but also keeping the high watermark above the MIN_SIZE
             * We must do this at least twice, since the counter for disposed is incremented once per release, if appropriate,
             * and only after the clock has ticked. Essentially this is one loop for reducing the watermark down to
             * mid size and one more loop to dispose of all excess resources. That does indeed mean that there is a lag
             * of one clock tick before resources are disposed. If this is a bug or not remains to be seen.
             */
            for (int i = 0; i < 2; i++)
            {
                clock.Forward(110, TimeUnit.MILLISECONDS);
                foreach (FlyweightHolder holder in AcquireFromPool(pool, midSize))
                {
                    holder.release();
                }
                clock.Forward(110, TimeUnit.MILLISECONDS);
                foreach (FlyweightHolder holder in AcquireFromPool(pool, midSize))
                {
                    holder.release();
                }
            }

            // then
            // currentPeakSize should be at MID_SIZE
            assertEquals(midSize, stateMonitor.CurrentPeakSize.get());
            // target size too
            assertEquals(midSize, stateMonitor.TargetSize.get());
            // only the excess from the MAX_SIZE down to mid size must have been disposed
            // +1 for the alarm from buildAPeakOfAcquiredFlyweightsAndTriggerAlarmWithSideEffects
            assertEquals(maxSize - midSize + 1, stateMonitor.DisposedConflict.get());
        }
Beispiel #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBuildUpGracefullyUntilReachedMinPoolSize() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBuildUpGracefullyUntilReachedMinPoolSize()
        {
            // GIVEN
            StatefulMonitor stateMonitor = new StatefulMonitor(this);
            FakeClock       clock        = FakeClocks;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ResourcePool<Something> pool = getResourcePool(stateMonitor, clock, 5);
            ResourcePool <Something> pool = GetResourcePool(stateMonitor, clock, 5);

            // WHEN
            AcquireFromPool(pool, 5);

            // THEN
            assertEquals(-1, stateMonitor.CurrentPeakSize.get());
            assertEquals(-1, stateMonitor.TargetSize.get());                 // that means the target size was not updated
            assertEquals(0, stateMonitor.DisposedConflict.get());            // no disposed happened, since the count to update is 10
        }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBuildUpGracefullyWhilePassingMinPoolSizeBeforeTimerRings() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBuildUpGracefullyWhilePassingMinPoolSizeBeforeTimerRings()
        {
            // GIVEN
            StatefulMonitor stateMonitor = new StatefulMonitor(this);
            FakeClock       clock        = FakeClocks;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ResourcePool<Something> pool = getResourcePool(stateMonitor, clock, 5);
            ResourcePool <Something> pool = GetResourcePool(stateMonitor, clock, 5);

            // WHEN
            AcquireFromPool(pool, 15);

            // THEN
            assertEquals(-1, stateMonitor.CurrentPeakSize.get());
            assertEquals(15, stateMonitor.CreatedConflict.get());
            assertEquals(-1, stateMonitor.TargetSize.get());
            assertEquals(0, stateMonitor.DisposedConflict.get());
        }
Beispiel #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMaintainPoolHigherThenMinSizeWhenPeekUsagePasses() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMaintainPoolHigherThenMinSizeWhenPeekUsagePasses()
        {
            // given
            const int poolMinSize       = 50;
            const int poolMaxSize       = 200;
            const int afterPeekPoolSize = 90;

            StatefulMonitor stateMonitor = new StatefulMonitor(this);
            FakeClock       clock        = FakeClocks;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final SomethingResourcePool pool = getResourcePool(stateMonitor, clock, poolMinSize);
            SomethingResourcePool pool = GetResourcePool(stateMonitor, clock, poolMinSize);

            AcquireResourcesAndExceedTimeout(pool, clock, poolMaxSize);

            // when
            // After the peak, stay at afterPeekPoolSize concurrent usage, using up all already present resources in the process
            // but also keeping the high watermark above the minimum size
            ExceedTimeout(clock);
            // Requires some rounds to happen, since there is constant racing between releasing and acquiring which does
            // not always result in reaping of resources, as there is reuse
            for (int i = 0; i < 10; i++)
            {
                // The latch is necessary to reduce races between batches
                System.Threading.CountdownEvent release = new System.Threading.CountdownEvent(afterPeekPoolSize);
                foreach (ResourceHolder holder in AcquireFromPool(pool, afterPeekPoolSize))
                {
                    holder.Release(release);
                }
                release.await();
                ExceedTimeout(clock);
            }

            // then
            // currentPeakSize should be at afterPeekPoolSize
            assertEquals(afterPeekPoolSize, stateMonitor.CurrentPeakSize.get());
            // target size too
            assertEquals(afterPeekPoolSize, stateMonitor.TargetSize.get());
            // only the excess from the maximum size down to after peek usage size must have been disposed
            // +1 that was used to trigger exceed timeout check
            assertEquals(afterPeekPoolSize, pool.UnusedSize());
            assertThat(stateMonitor.DisposedConflict.get(), greaterThanOrEqualTo(poolMaxSize - afterPeekPoolSize + 1));
        }
Beispiel #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldUpdateTargetSizeWhenSpikesOccur()
        internal virtual void ShouldUpdateTargetSizeWhenSpikesOccur()
        {
            // given
            const int minSize = 5;
            const int maxSize = 10;

            StatefulMonitor stateMonitor = new StatefulMonitor();
            FakeClock       clock        = new FakeClock();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LinkedQueuePool<Object> pool = getLinkedQueuePool(stateMonitor, clock, MIN_SIZE);
            LinkedQueuePool <object> pool = GetLinkedQueuePool(stateMonitor, clock, minSize);
            // when
            IList <FlyweightHolder <object> > holders = AcquireFromPool(pool, maxSize);

            clock.Forward(110, TimeUnit.MILLISECONDS);
            ((IList <FlyweightHolder <object> >)holders).AddRange(AcquireFromPool(pool, 1));                    // Needed to trigger the alarm

            // then
            assertEquals(maxSize + 1, stateMonitor.CurrentPeakSize.get());
            // We have not released anything, so targetSize will not be reduced
            assertEquals(maxSize + 1, stateMonitor.TargetSize.get());                 // + 1 from the acquire
        }
Beispiel #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBuildUpGracefullyUntilReachedMinPoolSize()
        internal virtual void ShouldBuildUpGracefullyUntilReachedMinPoolSize()
        {
            // GIVEN
            StatefulMonitor stateMonitor = new StatefulMonitor();
            FakeClock       clock        = new FakeClock();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LinkedQueuePool<Object> pool = getLinkedQueuePool(stateMonitor, clock, 5);
            LinkedQueuePool <object> pool = GetLinkedQueuePool(stateMonitor, clock, 5);

            // WHEN
            IList <FlyweightHolder <object> > flyweightHolders = AcquireFromPool(pool, 5);

            foreach (FlyweightHolder <object> flyweightHolder in flyweightHolders)
            {
                flyweightHolder.Release();
            }

            // THEN
            // clock didn't tick, these two are not set
            assertEquals(-1, stateMonitor.CurrentPeakSize.get());
            assertEquals(-1, stateMonitor.TargetSize.get());
            // no disposed happened, since the count to update is 5
            assertEquals(0, stateMonitor.DisposedConflict.get());
        }
Beispiel #15
0
 internal SomethingResourcePool(int minSize, CheckStrategy checkStrategy, StatefulMonitor stateMonitor) : base(minSize, checkStrategy, stateMonitor)
 {
 }
Beispiel #16
0
        private LinkedQueuePool <object> GetLinkedQueuePool(StatefulMonitor stateMonitor, FakeClock clock, int minSize)
        {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            return(new LinkedQueuePool <object>(minSize, object::new, new LinkedQueuePool.CheckStrategy_TimeoutCheckStrategy(100, clock), stateMonitor));
        }
Beispiel #17
0
 private SomethingResourcePool GetResourcePool(StatefulMonitor stateMonitor, FakeClock clock, int minSize)
 {
     ResourcePool.CheckStrategy_TimeoutCheckStrategy timeoutCheckStrategy = new ResourcePool.CheckStrategy_TimeoutCheckStrategy(TIMEOUT_MILLIS, clock);
     return(new SomethingResourcePool(minSize, timeoutCheckStrategy, stateMonitor));
 }