public void Remove() { var addressCache = new AddressCache(new TimeSpan(0, 0, 2)); Assert.True(addressCache.Add(IPAddress.Parse("1.1.1.1"))); Assert.False(addressCache.Remove(IPAddress.Parse("2.2.2.2"))); Assert.True(addressCache.Remove(IPAddress.Parse("1.1.1.1"))); }
public void Remove() { var addressCache = new AddressCache(new TimeSpan(0, 0, 2)); Assert.True(addressCache.Add(IPAddress.Parse("1.1.1.1"))); Assert.True(addressCache.Add(IPAddress.Parse("2.2.2.2"))); Assert.AreEqual("2.2.2.2", addressCache.Peek().ToString()); Assert.True(addressCache.Remove(IPAddress.Parse("2.2.2.2"))); Assert.AreEqual("1.1.1.1", addressCache.Peek().ToString()); Assert.True(addressCache.Remove(IPAddress.Parse("1.1.1.1"))); Assert.Null(addressCache.Peek()); }
public void SingleMonkey() { var random = new Random(); for (var i = 0; i < _actionCount; i++) { var address = GenerateAddress(random); switch (random.Next(1, 4)) { case 1: _addressCache.Add(address); break; case 2: _addressCache.Remove(address); break; case 3: _addressCache.Peek(); break; default: Console.WriteLine("In default"); break; } Thread.Sleep(_actionDelayInMs); } }
public void ExpiredRemove() { var addressCache = new AddressCache(new TimeSpan(0, 0, 2)); Assert.True(addressCache.Add(IPAddress.Parse("1.1.1.1"))); Thread.Sleep(2000); Assert.False(addressCache.Remove(IPAddress.Parse("1.1.1.1"))); }
public void TestRemoveExpired() { var addressCache = new AddressCache(new TimeSpan(0, 0, 2)); Assert.True(addressCache.Add(IPAddress.Parse("1.1.1.1"))); Assert.True(addressCache.Add(IPAddress.Parse("2.2.2.2"))); Thread.Sleep(1000); Assert.True(addressCache.Add(IPAddress.Parse("3.3.3.3"))); Assert.True(addressCache.Add(IPAddress.Parse("4.4.4.4"))); Thread.Sleep(1000); Assert.True(addressCache.Remove(IPAddress.Parse("4.4.4.4"))); }