Example #1
0
        public void Cleanup_StateUnderTest_ExpectedBehavior(int active)
        {
            // Arrange
            var sub = Substitute.For <IRevokeContextConcurrentCollectionFactory>();

            sub.Create().Returns(_ => new RevokeContextConcurrentCollection());
            var revokeKeyIndexer = new RevokeKeyIndexer(
                sub,
                this.subLog);;

            // Act
            Parallel.For(0, 100, (i, _) =>
            {
                var collect = i >= active;
                RevokeContext rc;
                if (collect)
                {
                    rc = CreateRevokeContext(i);
                }
                else
                {
                    rc = CreateRevokeContextRooted(i);
                }

                revokeKeyIndexer.AddRevokeContext((i % 10).ToString(), rc);
            });

            revokeKeyIndexer.Cleanup();

            //Assert
            Assert.AreEqual(active, revokeKeyIndexer.CountRevokees());
        }
Example #2
0
        public void GetLiveRevokeesAndSafelyRemoveDeadOnes_Existing_Key_For_Collected_Context_Should_Return_Empty_Enumerable()
        {
            // Arrange
            var rcc = new RevokeContextConcurrentCollection();
            var sub = Substitute.For <IRevokeContextConcurrentCollectionFactory>();

            sub.Create().Returns(_ => rcc);
            var revokeKeyIndexer = new RevokeKeyIndexer(
                sub,
                this.subLog);;
            string revokeKey = "existing";

            revokeKeyIndexer.AddRevokeContext(revokeKey, CreateRevokeContext());
            // Act
            var res = revokeKeyIndexer.GetLiveRevokeesAndSafelyRemoveDeadOnes(
                revokeKey);

            // Assert
            Assert.IsEmpty(res);
        }
Example #3
0
        public void GetLiveRevokeesAndSafelyRemoveDeadOnes_dead_Entries_Should_Be_Cleaned2()
        {
            // Arrange
            var rcc = new RevokeContextConcurrentCollection();
            var sub = Substitute.For <IRevokeContextConcurrentCollectionFactory>();

            sub.Create().Returns(_ => rcc);
            var revokeKeyIndexer = new RevokeKeyIndexer(
                sub,
                this.subLog);;
            string revokeKey = "existing";

            revokeKeyIndexer.AddRevokeContext(revokeKey, CreateRevokeContext());

            // Act
            var res = revokeKeyIndexer.GetLiveRevokeesAndSafelyRemoveDeadOnes(
                revokeKey);

            // Assert
            Assert.False(revokeKeyIndexer.ContainsKey(revokeKey));
        }
Example #4
0
        public void AddRevokeContext_Concurrently_Should_Succeed(int active)
        {
            // Arrange
            var sub = Substitute.For <IRevokeContextConcurrentCollectionFactory>();

            sub.Create().Returns(_ => new RevokeContextConcurrentCollection());
            var revokeKeyIndexer = new RevokeKeyIndexer(
                sub,
                this.subLog);;

            // Act
            Parallel.For(0, 100, (i, _) =>
            {
                var collect = i >= active;
                RevokeContext rc;
                if (collect)
                {
                    rc = CreateRevokeContext(i);
                }
                else
                {
                    rc = CreateRevokeContextRooted(i);
                }

                revokeKeyIndexer.AddRevokeContext((i % 10).ToString(), rc);
            });

            var count = 0;

            for (var i = 0; i < 10; i++)
            {
                count += revokeKeyIndexer.GetLiveRevokeesAndSafelyRemoveDeadOnes(i.ToString()).Count();
            }

            //Assert
            Assert.AreEqual(active, count);
        }
Example #5
0
        public void Remove_Object_Should_Remove_From_All_Keys()
        {
            // Arrange
            var sub = Substitute.For <IRevokeContextConcurrentCollectionFactory>();

            sub.Create().Returns(_ => new RevokeContextConcurrentCollection());
            var revokeKeyIndexer = new RevokeKeyIndexer(
                sub,
                this.subLog);;
            var    context = CreateRevokeContextRooted();
            object obj     = context.Revokee;
            string key1    = "key1";
            string key2    = "key2";

            revokeKeyIndexer.AddRevokeContext(key1, context);
            revokeKeyIndexer.AddRevokeContext(key2, context);

            // Act
            revokeKeyIndexer.Remove(obj);

            //Assert
            Assert.IsEmpty(revokeKeyIndexer.GetLiveRevokeesAndSafelyRemoveDeadOnes(key1));
            Assert.IsEmpty(revokeKeyIndexer.GetLiveRevokeesAndSafelyRemoveDeadOnes(key2));
        }
Example #6
0
        public void Remove_Existing_Key_Should_Succeed()
        {
            // Arrange
            var sub = Substitute.For <IRevokeContextConcurrentCollectionFactory>();

            sub.Create().Returns(_ => new RevokeContextConcurrentCollection());
            var revokeKeyIndexer = new RevokeKeyIndexer(
                sub,
                this.subLog);;
            var    context = CreateRevokeContextRooted();
            object obj     = context.Revokee;
            string key     = "key";

            revokeKeyIndexer.AddRevokeContext(key, context);

            // Act
            var res = revokeKeyIndexer.Remove(
                obj,
                key);

            //Assert
            Assert.True(res);
            Assert.False(revokeKeyIndexer.ContainsKey(key));
        }