private static ISet <BackplaneMessage> CreateMany(byte[] owner)
        {
            var messages = new HashSet <BackplaneMessage>();
            var key      = Guid.NewGuid().ToString();
            var region   = Guid.NewGuid().ToString();

            // test hash compare works too, result hashset should still have 41 messages only!
            for (var m = 0; m < 10000; m++)
            {
                for (var i = 0; i < 10; i++)
                {
                    messages.Add(BackplaneMessage.ForChanged(owner, key + i, CacheItemChangedEventAction.Update));
                    messages.Add(BackplaneMessage.ForChanged(owner, key + i, region, CacheItemChangedEventAction.Add));
                }

                messages.Add(BackplaneMessage.ForClear(owner));

                for (var i = 0; i < 10; i++)
                {
                    messages.Add(BackplaneMessage.ForClearRegion(owner, region + i));
                }
                for (var i = 0; i < 10; i++)
                {
                    messages.Add(BackplaneMessage.ForRemoved(owner, key + i, region));
                }
            }

            return(messages);
        }
        public void BackplaneMessage_HashChangedKey()
        {
            // arrange
            var owner = new byte[] { 1, 2, 3, 4 };

            var key  = Guid.NewGuid().ToString();
            var msg  = BackplaneMessage.ForChanged(owner, key, CacheItemChangedEventAction.Update);
            var msg2 = BackplaneMessage.ForChanged(owner, key, CacheItemChangedEventAction.Update);

            // act
            msg.GetHashCode().Should().Be(msg2.GetHashCode());
        }
        public void BackplaneMessage_EqualsOtherChangedKey()
        {
            // arrange
            var owner = new byte[] { 1, 2, 3, 4 };

            var key  = Guid.NewGuid().ToString();
            var msg  = BackplaneMessage.ForChanged(owner, key, CacheItemChangedEventAction.Update);
            var msg2 = BackplaneMessage.ForChanged(owner, key, CacheItemChangedEventAction.Update);

            // act
            msg.Equals(msg2).Should().BeTrue();
        }
        public void BackplaneMessage_ChangePutKey()
        {
            // arrange
            var owner = new byte[] { 1, 2, 3, 4 };
            var key   = Guid.NewGuid().ToString();
            var msg   = BackplaneMessage.ForChanged(owner, key, CacheItemChangedEventAction.Put);

            // act
            var serialized   = BackplaneMessage.Serialize(msg);
            var deserialized = BackplaneMessage.Deserialize(serialized).First();

            // assert
            deserialized.Key.Should().Be(key);
            deserialized.Region.Should().Be(null);
            deserialized.ChangeAction.Should().Be(CacheItemChangedEventAction.Put);
            deserialized.Action.Should().Be(BackplaneAction.Changed);
            deserialized.OwnerIdentity.ShouldBeEquivalentTo(owner);
            deserialized.ShouldBeEquivalentTo(msg);
        }
        public void BackplaneMessage_Hashset_DifferentMessage()
        {
            // arrange
            var owner = new byte[] { 1, 2, 3, 4 };

            var key    = Guid.NewGuid().ToString();
            var region = Guid.NewGuid().ToString();
            var msg    = BackplaneMessage.ForChanged(owner, key, region, CacheItemChangedEventAction.Update);
            var msg2   = BackplaneMessage.ForRemoved(owner, key, region);

            var hashset = new HashSet <BackplaneMessage>();

            // act
            hashset.Add(msg);
            hashset.Add(msg);
            hashset.Count.Should().Be(1);
            hashset.Add(msg2);
            hashset.Add(msg2);
            hashset.Count.Should().Be(2);
        }
Exemplo n.º 6
0
        static BackplaneMessageBenchmarkMultiple()
        {
            var messages = new List <BackplaneMessage>();

            for (var i = 0; i < 10; i++)
            {
                messages.Add(BackplaneMessage.ForChanged(_ownderBytes, "somerandomkey" + i, CacheItemChangedEventAction.Update));
                messages.Add(BackplaneMessage.ForChanged(_ownderBytes, "somerandomkey" + i, "withregion", CacheItemChangedEventAction.Add));
            }
            for (var i = 0; i < 10; i++)
            {
                messages.Add(BackplaneMessage.ForClear(_ownderBytes));
            }
            for (var i = 0; i < 10; i++)
            {
                messages.Add(BackplaneMessage.ForClearRegion(_ownderBytes, "somerandomregion" + i));
            }
            for (var i = 0; i < 10; i++)
            {
                messages.Add(BackplaneMessage.ForRemoved(_ownderBytes, "somerandomkey" + i, "withregion"));
            }
            _multiple = messages.ToArray();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Notifies other cache clients about a changed cache key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="region">The region.</param>
 public override void NotifyChange(string key, string region)
 {
     this.PublishMessage(BackplaneMessage.ForChanged(this.identifier, key, region));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Notifies other cache clients about a changed cache key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="region">The region.</param>
 /// <param name="action">The cache action.</param>
 public override void NotifyChange(string key, string region, CacheItemChangedEventAction action)
 {
     PublishMessage(BackplaneMessage.ForChanged(_identifier, key, region, action));
 }
 /// <summary>
 /// Notifies other cache clients about a changed cache key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="action">The cache action.</param>
 public override void NotifyChange(string key, CacheItemChangedEventAction action)
 {
     this.PublishMessage(BackplaneMessage.ForChanged(this.identifier, key, action));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Notifies other cache clients about a changed cache key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="region">The region.</param>
 /// <param name="action">The cache action.</param>
 public override Task NotifyChangeAsync(string key, string region, CacheItemChangedEventAction action)
 {
     return(PublishMessageAsync(BackplaneMessage.ForChanged(_identifier, key, region, action)));
 }