Beispiel #1
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);
                }
            }
        }
Beispiel #2
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));
            }
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTrackUsedMemory()
        public virtual void ShouldTrackUsedMemory()
        {
            int capacity = 4;
            ConsecutiveInFlightCache cache = new ConsecutiveInFlightCache(capacity, 1000, InFlightCacheMonitor.VOID, true);

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

                // then
                assertEquals((i + 1) * 100, cache.TotalBytes());
            }

            // when
            cache.Put(capacity, Content(100));

            // then
            assertEquals(capacity, cache.ElementCount());
            assertEquals(capacity * 100, cache.TotalBytes());

            // when
            cache.Put(capacity + 1, Content(500));
            assertEquals(capacity, cache.ElementCount());
            assertEquals(800, cache.TotalBytes());

            // when
            cache.Put(capacity + 2, Content(500));
            assertEquals(2, cache.ElementCount());
            assertEquals(1000, cache.TotalBytes());
        }
Beispiel #4
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);
                }
            }
        }