コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnSameRateLimiterForSameHandle() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReturnSameRateLimiterForSameHandle()
        {
            // given
            Limiters      limiters = new Limiters(Clocks.fakeClock());
            AtomicInteger cnt      = new AtomicInteger();

            System.Action <ThreadStart> rateLimiterA = Org.Neo4j.causalclustering.helper.Limiters.rateLimiter("SAME", _eternity);
            System.Action <ThreadStart> rateLimiterB = Org.Neo4j.causalclustering.helper.Limiters.rateLimiter("SAME", _eternity);

            // when
            rateLimiterA(cnt.incrementAndGet);
            rateLimiterA(cnt.incrementAndGet);

            rateLimiterB(cnt.incrementAndGet);
            rateLimiterB(cnt.incrementAndGet);

            // then
            assertEquals(1, cnt.get());
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void distinctRateLimitersOperateIndependently() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void DistinctRateLimitersOperateIndependently()
        {
            // given
            Limiters      limiters = new Limiters(Clocks.fakeClock());
            AtomicInteger cnt      = new AtomicInteger();

            System.Action <ThreadStart> rateLimiterA = Org.Neo4j.causalclustering.helper.Limiters.rateLimiter("A", _eternity);
            System.Action <ThreadStart> rateLimiterB = Org.Neo4j.causalclustering.helper.Limiters.rateLimiter("B", _eternity);

            // when
            rateLimiterA(cnt.incrementAndGet);
            rateLimiterA(cnt.incrementAndGet);
            rateLimiterA(cnt.incrementAndGet);

            rateLimiterB(cnt.incrementAndGet);
            rateLimiterB(cnt.incrementAndGet);
            rateLimiterB(cnt.incrementAndGet);

            // then
            assertEquals(2, cnt.get());
        }
コード例 #3
0
 /// <summary>
 /// Rate limits calls under the specified handle.
 /// </summary>
 /// <param name="handle"> A unique handle. </param>
 /// <param name="minInterval"> The minimum interval between invocations. </param>
 /// <returns> A rate limited consumer of <seealso cref="System.Threading.ThreadStart"/>s. </returns>
 public virtual System.Action <ThreadStart> RateLimiter(object handle, Duration minInterval)
 {
     return(_caps.computeIfAbsent(handle, ignored => Limiters.RateLimiter(minInterval, _clock)));
 }