public void BackplaneMessage_DeserializeInvalidBytes_InvalidString() { // arrange clear region with wrong region string var data = new byte[] { 4, 0, 0, 0, 1, 2, 3, 4, 3, 10, 0, 0, 0, 42 }; Action act = () => BackplaneMessage.Deserialize(data).First(); act.ShouldThrow <IndexOutOfRangeException>().WithMessage("*Cannot read string,*"); }
public void BackplaneMessage_DeserializeInvalidBytes_NoAction() { // arrange var data = new byte[] { 4, 0, 0, 0, 1, 2, 3, 4 }; Action act = () => BackplaneMessage.Deserialize(data).First(); act.ShouldThrow <IndexOutOfRangeException>().WithMessage("*Cannot read byte,*"); }
public void BackplaneMessage_DeserializeInvalidBytes_WrongAction() { // arrange var data = new byte[] { 4, 0, 0, 0, 1, 2, 3, 4, 255 }; Action act = () => BackplaneMessage.Deserialize(data).First(); act.ShouldThrow <ArgumentException>().WithMessage("*invalid message type*"); }
public void BackplaneMessage_Mulitple_IgnoreOwner() { // arrange var owner = new byte[] { 1, 2, 3, 4 }; var messages = CreateMany(owner); var serialized = BackplaneMessage.Serialize(messages.ToArray()); var deserialized = BackplaneMessage.Deserialize(serialized, skipOwner: owner).ToArray(); messages.Count.Should().Be(41); deserialized.Length.Should().Be(0); }
public void BackplaneMessage_Mulitple() { // arrange var owner = new byte[] { 1, 2, 3, 4 }; var messages = CreateMany(owner); var serialized = BackplaneMessage.Serialize(messages.ToArray()); var deserialized = BackplaneMessage.Deserialize(serialized).ToArray(); messages.Count.Should().Be(41); deserialized.ShouldAllBeEquivalentTo(messages); }
public void BackplaneMessage_Clear() { // arrange var owner = new byte[] { 1, 2, 3, 4 }; var msg = BackplaneMessage.ForClear(owner); // act var serialized = BackplaneMessage.Serialize(msg); var deserialized = BackplaneMessage.Deserialize(serialized).First(); // assert deserialized.Key.Should().Be(null); deserialized.Region.Should().Be(null); deserialized.ChangeAction.Should().Be(CacheItemChangedEventAction.Invalid); deserialized.Action.Should().Be(BackplaneAction.Clear); deserialized.OwnerIdentity.ShouldBeEquivalentTo(owner); deserialized.ShouldBeEquivalentTo(msg); }
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 DeserializeChangeRegion() { var msg = BackplaneMessage.Deserialize(_rawSingleChangeRegion).ToArray(); }
public void DeserializeMany() { var messages = BackplaneMessage.Deserialize(_multipleSerialized).ToArray(); }
public void DeserializeRemove() { var msg = BackplaneMessage.Deserialize(_rawSingleRemove).ToArray(); }
public void DeserializeClear() { var msg = BackplaneMessage.Deserialize(_rawSingleClear).ToArray(); }
public PublishSusbcribeCacheManagerBackplane( IPublishSubscribe publishSubscribe, ILoggerFactory loggerFactory, ICacheManagerConfiguration configuration) : base(configuration) { NotNull(configuration, nameof(publishSubscribe)); NotNull(loggerFactory, nameof(loggerFactory)); NotNull(loggerFactory, nameof(loggerFactory)); _publishSubscribe = publishSubscribe; _channelName = configuration.BackplaneChannelName ?? "CacheManagerBackplane"; _identifier = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()); ILogger logger = loggerFactory.CreateLogger(this); _subscription = publishSubscribe .Observe <byte[]>(_channelName) .SelectMany(serializedBackplaneMessage => BackplaneMessage.Deserialize(serializedBackplaneMessage.Data, _identifier)) .Subscribe(message => { if (logger.IsEnabled(LogLevel.Information)) { logger.LogInfo("Backplane got notified with new message."); } switch (message.Action) { case BackplaneAction.Clear: TriggerCleared(); break; case BackplaneAction.ClearRegion: TriggerClearedRegion(message.Region); break; case BackplaneAction.Changed: if (string.IsNullOrWhiteSpace(message.Region)) { TriggerChanged(message.Key, message.ChangeAction); } else { TriggerChanged(message.Key, message.Region, message.ChangeAction); } break; case BackplaneAction.Removed: if (string.IsNullOrWhiteSpace(message.Region)) { TriggerRemoved(message.Key); } else { TriggerRemoved(message.Key, message.Region); } break; } }); }