Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemoveTruncatedItems()
        public virtual void ShouldRemoveTruncatedItems()
        {
            // given
            int capacity = 20;
            ConsecutiveInFlightCache cache = new ConsecutiveInFlightCache(capacity, 1000, InFlightCacheMonitor.VOID, true);

            for (int i = 0; i < capacity; i++)
            {
                cache.Put(i, Content(i));
            }

            // when
            int fromIndex = capacity / 2;

            cache.Truncate(fromIndex);

            // then
            assertEquals(fromIndex, cache.ElementCount());
            assertEquals((fromIndex * (fromIndex - 1)) / 2, cache.TotalBytes());

            for (int i = fromIndex; i < capacity; i++)
            {
                assertNull(cache.Get(i));
            }
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnLatestItems()
        public virtual void ShouldReturnLatestItems()
        {
            // given
            int capacity = 4;
            ConsecutiveInFlightCache cache = new ConsecutiveInFlightCache(capacity, 1000, InFlightCacheMonitor.VOID, true);

            // when
            for (int i = 0; i < 3 * capacity; i++)
            {
                cache.Put(i, Content(i));
            }

            // then
            for (int i = 0; i < 3 * capacity; i++)
            {
                RaftLogEntry entry = cache.Get(i);
                if (i < 2 * capacity)
                {
                    assertNull(entry);
                }
                else
                {
                    assertTrue(entry.Content().size().HasValue);
                    assertEquals(i, entry.Content().size().Value);
                }
            }
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemovePrunedItems()
        public virtual void ShouldRemovePrunedItems()
        {
            // given
            int capacity = 20;
            ConsecutiveInFlightCache cache = new ConsecutiveInFlightCache(capacity, 1000, InFlightCacheMonitor.VOID, true);

            for (int i = 0; i < capacity; i++)
            {
                cache.Put(i, Content(i));
            }

            // when
            int upToIndex = capacity / 2 - 1;

            cache.Prune(upToIndex);

            // then
            assertEquals(capacity / 2, cache.ElementCount());

            for (int i = 0; i < capacity; i++)
            {
                RaftLogEntry entry = cache.Get(i);
                if (i <= upToIndex)
                {
                    assertNull(entry);
                }
                else
                {
                    assertTrue(entry.Content().size().HasValue);
                    assertEquals(i, entry.Content().size().Value);
                }
            }
        }