public void StressPeak() { 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.True(addressCache.Add(IPAddress.Parse("3.3.3.3"))); Assert.True(addressCache.Add(IPAddress.Parse("4.4.4.4"))); Assert.True(addressCache.Add(IPAddress.Parse("5.5.5.5"))); Assert.AreEqual("5.5.5.5", addressCache.Peek().ToString()); Thread.Sleep(1000); Assert.True(addressCache.Add(IPAddress.Parse("6.6.6.6"))); Assert.AreEqual("6.6.6.6", addressCache.Peek().ToString()); Thread.Sleep(1000); Assert.True(addressCache.Add(IPAddress.Parse("5.5.5.5"))); Assert.AreEqual("5.5.5.5", addressCache.Peek().ToString()); Thread.Sleep(2000); Assert.Null(addressCache.Peek()); }
public void Peek() { var addressCache = new AddressCache(new TimeSpan(0, 0, 10)); Assert.Null(addressCache.Peek()); Assert.True(addressCache.Add(IPAddress.Parse("1.1.1.1"))); Assert.AreEqual("1.1.1.1", addressCache.Peek().ToString()); Assert.True(addressCache.Add(IPAddress.Parse("2.2.2.2"))); Assert.AreEqual("2.2.2.2", addressCache.Peek().ToString()); }
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 ExpiredPeek() { var addressCache = new AddressCache(new TimeSpan(0, 0, 2)); Assert.True(addressCache.Add(IPAddress.Parse("1.1.1.1"))); Assert.AreEqual("1.1.1.1", addressCache.Peek().ToString()); Thread.Sleep(2000); Assert.Null(addressCache.Peek()); Assert.True(addressCache.Add(IPAddress.Parse("1.1.1.1"))); Thread.Sleep(1000); Assert.True(addressCache.Add(IPAddress.Parse("2.2.2.2"))); Thread.Sleep(1000); Assert.AreEqual("2.2.2.2", addressCache.Peek().ToString()); Assert.AreEqual("2.2.2.2", addressCache.Peek().ToString()); Thread.Sleep(1000); Assert.Null(addressCache.Peek()); }