public void SHUpdateTest() { callback_count = 0; int spi = SecurityPolicy.DefaultSPI; MockSender sender1 = new MockSender(null, null, null, 2); MockSender sender2 = new MockSender(null, null, null, 2); SecurityAssociation sa1 = new SecurityAssociation(sender1, spi); sa1.StateChange += StateChange; sender2.Receiver = sa1; MockDataHandler mdh1 = new MockDataHandler(); sa1.Subscribe(mdh1, null); SecurityAssociation sa2 = new SecurityAssociation(sender2, spi); sender1.Receiver = sa2; MockDataHandler mdh2 = new MockDataHandler(); sa2.Subscribe(mdh2, null); Setup(ref sa1, ref sa2); sa1.RequestUpdate += Callback; sa2.RequestUpdate += Callback; byte[] b = null; Random rand = new Random(); MemBlock mb = null; int current_epoch = sa1.CurrentEpoch; for(int i = 0; i < 80; i++) { b = new byte[128]; rand.NextBytes(b); mb = MemBlock.Reference(b); sa1.Send(mb); Assert.IsTrue(mdh2.Contains(mb), "Contains" + i); if(i % 20 == 0 && i != 0) { Assert.AreEqual(callback_count, 1, "Callback count " + i); callback_count = 0; Thread.Sleep(SecurityAssociation.TIMEOUT * 2 + 5); Setup(ref sa1, ref sa2); } else { if(i % 20 == 1 && i != 1) { Assert.IsFalse(current_epoch == sa1.CurrentEpoch, "Current epoch " + i); current_epoch = sa1.CurrentEpoch; } Assert.AreEqual(current_epoch, sa1.CurrentEpoch, "Current epoch " + i); } } }
public void Test() { int spi = SecurityPolicy.DefaultSPI; MockSender sender1 = new MockSender(null, null, null, 2); MockSender sender2 = new MockSender(null, null, null, 2); SecurityAssociation sa1 = new SecurityAssociation(sender1, spi); sa1.StateChange += StateChange; sender2.Receiver = sa1; MockDataHandler mdh1 = new MockDataHandler(); sa1.Subscribe(mdh1, null); SecurityAssociation sa2 = new SecurityAssociation(sender2, spi); sender1.Receiver = sa2; MockDataHandler mdh2 = new MockDataHandler(); sa2.Subscribe(mdh2, null); byte[] b = null; Random rand = new Random(); MemBlock mb = null; int current_epoch = sa1.CurrentEpoch; for(int i = 0; i < 5; i++) { Thread.Sleep(SecurityAssociation.TIMEOUT * 2 + 5); Setup(ref sa1, ref sa2); b = new byte[128]; rand.NextBytes(b); mb = MemBlock.Reference(b); sa1.Send(mb); Assert.IsTrue(mdh2.Contains(mb), "Contains" + i); Assert.AreEqual(state, sa1.State, "State == Active" + i); Assert.IsFalse(current_epoch == sa1.CurrentEpoch, "Current epoch " + i); current_epoch = sa1.CurrentEpoch; } sa1.GarbageCollect(); sa1.GarbageCollect(); b = new byte[128]; rand.NextBytes(b); mb = MemBlock.Reference(b); try { sa1.Send(mb); } catch {} Assert.IsTrue(!mdh2.Contains(mb), "Failed!"); Assert.AreEqual(state, sa1.State, "State == Failed"); }