Example #1
0
        public static FeedElement ToAllEventsBackwardFeed(ClientMessage.ReadAllEventsBackwardCompleted msg, Uri requestedUrl, EmbedLevel embedContent)
        {
            var self = HostName.Combine(requestedUrl, "/streams/{0}", AllEscaped);
            var feed = new FeedElement();

            feed.SetTitle(string.Format("All events"));
            feed.SetId(self);
            feed.SetUpdated(msg.Events.Length > 0 && msg.Events[0].Event != null ? msg.Events[0].Event.TimeStamp : DateTime.MinValue.ToUniversalTime());
            feed.SetAuthor(AtomSpecs.Author);

            feed.AddLink("self", self);
            feed.AddLink("first", HostName.Combine(requestedUrl, "/streams/{0}/head/backward/{1}", AllEscaped, msg.MaxCount));
            if (!msg.IsEndOfStream)
            {
                feed.AddLink("last", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", AllEscaped, new TFPos(0, 0).AsString(), msg.MaxCount));
                feed.AddLink("next", HostName.Combine(requestedUrl, "/streams/{0}/{1}/backward/{2}", AllEscaped, msg.NextPos.AsString(), msg.MaxCount));
            }
            feed.AddLink("previous", HostName.Combine(requestedUrl, "/streams/{0}/{1}/forward/{2}", AllEscaped, msg.PrevPos.AsString(), msg.MaxCount));
            feed.AddLink("metadata", HostName.Combine(requestedUrl, "/streams/{0}/metadata", AllEscaped));
            for (int i = 0; i < msg.Events.Length; ++i)
            {
                feed.AddEntry(
                    ToEntry(
                        new ResolvedEvent(msg.Events[i].Event, msg.Events[i].Link, msg.Events[i].ResolveResult),
                        requestedUrl, embedContent));
            }
            return(feed);
        }
        public static ClientMessage.ReadAllEventsBackwardCompleted ReadAllEventsBackward(MiniClusterNode node,
                                                                                         long position)
        {
            ClientMessage.ReadAllEventsBackwardCompleted readResult = null;
            var resetEvent = new ManualResetEventSlim();
            var done       = false;

            while (!done)
            {
                resetEvent.Reset();
                var read = new ClientMessage.ReadAllEventsBackward(Guid.NewGuid(), Guid.NewGuid(), new CallbackEnvelope(
                                                                       msg => {
                    readResult = (ClientMessage.ReadAllEventsBackwardCompleted)msg;
                    resetEvent.Set();
                }),
                                                                   -1, -1, 100, false, false, null, SystemAccount.Principal);
                node.Node.MainQueue.Publish(read);

                if (!resetEvent.Wait(_timeout))
                {
                    Assert.Fail("Timed out waiting for events to be read backward");
                    return(null);
                }

                if (readResult.Result == ReadAllResult.Error)
                {
                    Assert.Fail("Failed to read backwards. Read result error: {0}", readResult.Error);
                    return(null);
                }

                done = readResult.NextPos.CommitPosition < position;
            }

            return(readResult);
        }
Example #3
0
        private static TcpPackage WrapReadAllEventsBackwardCompleted(ClientMessage.ReadAllEventsBackwardCompleted msg)
        {
            var dto = new TcpClientMessageDto.ReadAllEventsCompleted(
                msg.CurrentPos.CommitPosition, msg.CurrentPos.PreparePosition, ConvertToResolvedEvents(msg.Events),
                msg.NextPos.CommitPosition, msg.NextPos.PreparePosition,
                (TcpClientMessageDto.ReadAllEventsCompleted.ReadAllResult)msg.Result, msg.Error);

            return(new TcpPackage(TcpCommand.ReadAllEventsBackwardCompleted, msg.CorrelationId, dto.Serialize()));
        }
Example #4
0
        private static TcpPackage WrapReadAllEventsBackwardCompleted(ClientMessage.ReadAllEventsBackwardCompleted msg)
        {
            var dto = new ClientMessageDto.ReadAllEventsBackwardCompleted(msg.Result.CurrentPos.CommitPosition,
                                                                          msg.Result.CurrentPos.PreparePosition,
                                                                          msg.Result.Records.Select(x => new EventLinkPair(x.Event, x.Link)).ToArray(),
                                                                          msg.Result.NextPos.CommitPosition,
                                                                          msg.Result.NextPos.PreparePosition);

            return(new TcpPackage(TcpCommand.ReadAllEventsBackwardCompleted, msg.CorrelationId, dto.Serialize()));
        }
Example #5
0
        public InspectionResult InspectPackage(TcpPackage package)
        {
            try
            {
                if (package.Command != TcpCommand.ReadAllEventsBackwardCompleted)
                {
                    return(new InspectionResult(InspectionDecision.NotifyError,
                                                new CommandNotExpectedException(TcpCommand.ReadAllEventsBackwardCompleted.ToString(),
                                                                                package.Command.ToString())));
                }

                var data = package.Data;
                var dto  = data.Deserialize <ClientMessage.ReadAllEventsBackwardCompleted>();
                _result = dto;
                return(new InspectionResult(InspectionDecision.Succeed));
            }
            catch (Exception e)
            {
                return(new InspectionResult(InspectionDecision.NotifyError, e));
            }
        }
Example #6
0
        public void when_wrapping_read_all_events_backward_completed_with_deleted_event_should_not_downgrade_version_for_v2_clients()
        {
            var events = new ResolvedEvent[] {
                ResolvedEvent.ForUnresolvedEvent(CreateDeletedEventRecord(), 0),
            };
            var msg = new ClientMessage.ReadAllEventsBackwardCompleted(Guid.NewGuid(), ReadAllResult.Success, "", events,
                                                                       new StreamMetadata(), true, 10, new TFPos(0, 0),
                                                                       new TFPos(200, 200), new TFPos(0, 0), 100);

            var package = _dispatcher.WrapMessage(msg, (byte)ClientVersion.V2);

            Assert.IsNotNull(package, "Package is null");
            Assert.AreEqual(TcpCommand.ReadAllEventsBackwardCompleted, package.Value.Command, "TcpCommand");

            var dto = package.Value.Data.Deserialize <TcpClientMessageDto.ReadAllEventsCompleted>();

            Assert.IsNotNull(dto, "DTO is null");
            Assert.AreEqual(1, dto.Events.Count(), "Number of events");

            Assert.AreEqual(long.MaxValue, dto.Events[0].Event.EventNumber, "Event Number");
        }