Exemplo n.º 1
0
        public void MergeMissingEntriesWith_Collection_With_Null_Should_Not_Throw()
        {
            // Arrange
            var revokeContextConcurrentCollection = this.CreateRevokeContextConcurrentCollection(100);

            IRevokeContextConcurrentCollection other = null;

            // Act
            var result = revokeContextConcurrentCollection.MergeMissingEntriesWith(
                other);

            // Assert
            Assert.AreEqual(100, revokeContextConcurrentCollection.Count());
        }
Exemplo n.º 2
0
        public IRevokeContextConcurrentCollection MergeMissingEntriesWith(IRevokeContextConcurrentCollection other)
        {
            if (other == null)
            {
                return(this);
            }

            foreach (var entry in other)
            {
                var otherObj = entry.Revokee;
                //Doing best effort not to insert nulls
                if (otherObj == null)
                {
                    continue;
                }

                _collection.TryAdd(new EquatableWeakReference <object>(otherObj), entry);
            }

            return(this);
        }
Exemplo n.º 3
0
        protected bool SafelyRemoveEntry(string revokeKey, out IRevokeContextConcurrentCollection revived)
        {
            revived = null;
            _entries.TryRemove(revokeKey, out var removed);

            //Race condition #1 somebody registered this revoke key after we emptied it.
            if (removed.IsEmpty == false)
            {
                //Lets try and put it back
                //Race condition #2 we want to add the collection after removing it but somebody created a new one already
                revived = _entries.AddOrUpdate(revokeKey, removed, (_, dictionary) => dictionary.MergeMissingEntriesWith(removed));
                return(false);
            }

            _log.Info(logger => logger("Removed entry for revokeKey",
                                       unencryptedTags: new
            {
                revokeKey
            }));
            return(true);
        }