Ejemplo n.º 1
0
        public async Task should_support_out_of_order_ZebusV2_acks_and_messages()
        {
            var messageBytes = new byte[512];

            new Random().NextBytes(messageBytes);
            var timestamp = DateTime.UtcNow;
            var messageId = new MessageId(MessageIdV2.CreateNewSequentialId(timestamp.Ticks));
            var peerId    = "Abc.Peer.0";

            await _storage.Write(new List <MatcherEntry> {
                MatcherEntry.Ack(new PeerId(peerId), messageId)
            });

            await Task.Delay(50);

            await _storage.Write(new List <MatcherEntry> {
                MatcherEntry.Message(new PeerId(peerId), messageId, MessageTypeId.PersistenceStopping, messageBytes)
            });

            var retrievedMessage = DataContext.PersistentMessages.Execute().ExpectedSingle();

            retrievedMessage.TransportMessage.ShouldBeNull();
            retrievedMessage.BucketId.ShouldEqual(GetBucketIdFromDateTime(timestamp));
            retrievedMessage.IsAcked.ShouldBeTrue();
            retrievedMessage.PeerId.ShouldEqual(peerId);
            retrievedMessage.UniqueTimestampInTicks.ShouldEqual(timestamp.Ticks);
        }
Ejemplo n.º 2
0
        public void should_update_non_ack_message_count()
        {
            var firstPeer  = new PeerId("Abc.Testing.Target");
            var secondPeer = new PeerId("Abc.Testing.OtherTarget");

            _storage.Write(new[] { MatcherEntry.Message(firstPeer, MessageId.NextId(), new MessageTypeId("Abc.Message"), new byte[] { 0x01, 0x02, 0x03 }) });
            _storage.Write(new[] { MatcherEntry.Message(secondPeer, MessageId.NextId(), new MessageTypeId("Abc.Message"), new byte[] { 0x04, 0x05, 0x06 }) });
            _storage.Write(new[] { MatcherEntry.Message(firstPeer, MessageId.NextId(), new MessageTypeId("Abc.Message"), new byte[] { 0x07, 0x08, 0x09 }) });

            _peerStateRepository[firstPeer].NonAckedMessageCount.ShouldEqual(2);
            _peerStateRepository[secondPeer].NonAckedMessageCount.ShouldEqual(1);

            _storage.Write(new[] { MatcherEntry.Ack(firstPeer, MessageId.NextId()) });

            _peerStateRepository[firstPeer].NonAckedMessageCount.ShouldEqual(1);
            _peerStateRepository[secondPeer].NonAckedMessageCount.ShouldEqual(1);
        }
Ejemplo n.º 3
0
        public async Task should_write_ack_entry_fields_to_cassandra()
        {
            var messageId = MessageId.NextId();
            var peerId    = "Abc.Peer.0";

            await _storage.Write(new List <MatcherEntry> {
                MatcherEntry.Ack(new PeerId(peerId), messageId)
            });

            var retrievedMessage = DataContext.PersistentMessages.Execute().ExpectedSingle();

            retrievedMessage.TransportMessage.ShouldBeNull();
            retrievedMessage.BucketId.ShouldEqual(GetBucketIdFromMessageId(messageId));
            retrievedMessage.IsAcked.ShouldBeTrue();
            retrievedMessage.PeerId.ShouldEqual(peerId);
            retrievedMessage.UniqueTimestampInTicks.ShouldEqual(messageId.GetDateTime().Ticks);
            var writeTimeRow = DataContext.Session.Execute("SELECT WRITETIME(\"IsAcked\") FROM \"PersistentMessage\";").ExpectedSingle();

            writeTimeRow.GetValue <long>(0).ShouldEqual(ToUnixMicroSeconds(messageId.GetDateTime()) + 1);
        }
Ejemplo n.º 4
0
        public async Task should_load_previous_out_of_order_acks()
        {
            var peer = new PeerId("Abc.Testing.Target");

            var messageId = MessageId.NextId();
            await _storage.Write(new[] { MatcherEntry.Ack(peer, messageId) });

            _storage.Stop();

            _storage = new RocksDbStorage(_databaseDirectoryPath);
            _storage.Start();

            var message = MatcherEntry.Message(peer, messageId, MessageUtil.TypeId <Message1>(), Array.Empty <byte>());
            await _storage.Write(new[] { message });

            using (var messageReader = _storage.CreateMessageReader(peer))
            {
                messageReader.GetUnackedMessages()
                .Count()
                .ShouldEqual(0);
            }
        }
Ejemplo n.º 5
0
        public async Task should_not_get_acked_message()
        {
            var peer = new PeerId("Abc.Testing.Target");

            var message1 = GetMatcherEntryWithValidTransportMessage(peer, 1);
            var message2 = GetMatcherEntryWithValidTransportMessage(peer, 2);

            await _storage.Write(new[] { message1 });

            await _storage.Write(new[] { message2 });

            await _storage.Write(new[] { MatcherEntry.Ack(peer, message2.MessageId) });

            using (var reader = _storage.CreateMessageReader(peer))
            {
                reader.GetUnackedMessages()
                .Select(TransportMessageDeserializer.Deserialize)
                .Select(x => x.Id)
                .ToList()
                .ShouldBeEquivalentTo(message1.MessageId);
            }
        }
Ejemplo n.º 6
0
        public async Task should_update_non_ack_message_count()
        {
            var firstPeer  = new PeerId("Abc.Testing.Target");
            var secondPeer = new PeerId("Abc.Testing.OtherTarget");

            await _storage.Write(new[] { MatcherEntry.Message(firstPeer, MessageId.NextId(), new MessageTypeId("Abc.Message"), new byte[] { 0x01, 0x02, 0x03 }) });

            await _storage.Write(new[] { MatcherEntry.Message(secondPeer, MessageId.NextId(), new MessageTypeId("Abc.Message"), new byte[] { 0x04, 0x05, 0x06 }) });

            await _storage.Write(new[] { MatcherEntry.Message(firstPeer, MessageId.NextId(), new MessageTypeId("Abc.Message"), new byte[] { 0x07, 0x08, 0x09 }) });

            var nonAckedMessageCountsForUpdatedPeers = _storage.GetNonAckedMessageCounts();

            nonAckedMessageCountsForUpdatedPeers[firstPeer].ShouldEqual(2);
            nonAckedMessageCountsForUpdatedPeers[secondPeer].ShouldEqual(1);

            await _storage.Write(new[] { MatcherEntry.Ack(firstPeer, MessageId.NextId()) });

            nonAckedMessageCountsForUpdatedPeers = _storage.GetNonAckedMessageCounts();
            nonAckedMessageCountsForUpdatedPeers[firstPeer].ShouldEqual(1);
            nonAckedMessageCountsForUpdatedPeers[secondPeer].ShouldEqual(1);
        }
Ejemplo n.º 7
0
        public async Task should_support_out_of_order_acks_and_messages()
        {
            var inputMessage = CreateTestTransportMessage(1);
            var messageBytes = Serialization.Serializer.Serialize(inputMessage).ToArray();
            var messageId    = MessageId.NextId();

            var peerId = new PeerId("Abc.Peer.0");
            await _storage.Write(new List <MatcherEntry> {
                MatcherEntry.Ack(peerId, messageId)
            });

            await Task.Delay(50);

            await _storage.Write(new List <MatcherEntry> {
                MatcherEntry.Message(peerId, messageId, MessageTypeId.PersistenceStopping, messageBytes)
            });

            var messageReader = _storage.CreateMessageReader(peerId);

            messageReader.ShouldNotBeNull();
            var messages = messageReader.GetUnackedMessages().ToList();

            messages.ShouldBeEmpty();
        }
Ejemplo n.º 8
0
 private List <MatcherEntry> ToAckEntries(List <MatcherEntry> entriesToPersist)
 {
     return(entriesToPersist.Select(x => MatcherEntry.Ack(x.PeerId, x.MessageId)).ToList());
 }