Exemple #1
0
 public void TearDown()
 {
     if (evictor != null)
     {
         evictor.Stop();
     }
 }
Exemple #2
0
        public void TriggeringEvictionStrategiesInThread()
        {
            var resetEvent = new AutoResetEvent(false); // non-signaled, all threads will block

            mockBeaconCache.When(c => c.RecordAdded += Arg.Any <EventHandler>()).Do(x => resetEvent.Set());

            // also do reset event when executing mock strategy
            mockStrategyTwo.When(s => s.Execute()).Do(x => resetEvent.Set());

            // first step start the eviction thread
            evictor = new BeaconCacheEvictor(mockLogger, mockBeaconCache, mockStrategyOne, mockStrategyTwo);
            evictor.Start();
            resetEvent.WaitOne(); // wait until the evictor thread subscribed

            for (int i = 0; i < 10; i++)
            {
                mockBeaconCache.RecordAdded += Raise.Event();
                resetEvent.WaitOne();
            }

            // stop the thread
            var stopped = evictor.Stop();

            // verify stop worked
            Assert.That(stopped, Is.True);
            Assert.That(evictor.IsAlive, Is.False);

            // ensure that the mocks were called accordingly
            mockStrategyOne.Received(10).Execute();
            mockStrategyTwo.Received(10).Execute();
        }
Exemple #3
0
        public void StoppingABeaconCacheEvictorWhichIsNotAliveDoesNothing()
        {
            // given
            evictor = new BeaconCacheEvictor(mockLogger, mockBeaconCache);

            // when
            var obtained = evictor.Stop();

            // then
            Assert.That(obtained, Is.False);
            Assert.That(evictor.IsAlive, Is.False);
        }
Exemple #4
0
        public void StoppingAnAliveBeaconCacheEvictor()
        {
            // given
            evictor = new BeaconCacheEvictor(mockLogger, mockBeaconCache);
            evictor.Start();

            // when
            var obtained = evictor.Stop();

            // then
            Assert.That(obtained, Is.True);
            Assert.That(evictor.IsAlive, Is.False);
        }
Exemple #5
0
 public void TearDown()
 {
     evictor?.Stop();
 }