예제 #1
0
        public void return_empty_slice_if_asked_to_read_from_end()
        {
            var read = _conn.ReadAllEventsForward(Position.End, 1, false);

            Assert.That(read.IsEndOfStream, Is.True);
            Assert.That(read.Events.Length, Is.EqualTo(0));
        }
        protected override void ReadEventsTill(IEventStoreConnection connection, bool resolveLinkTos,
                                               UserCredentials userCredentials, long?lastCommitPosition, int?lastEventNumber)
        {
            bool done;

            do
            {
                AllEventsSlice slice = connection.ReadAllEventsForward(_nextReadPosition, ReadBatchSize, resolveLinkTos, userCredentials);
                foreach (var e in slice.Events)
                {
                    if (e.OriginalPosition == null)
                    {
                        throw new Exception("Subscription event came up with no OriginalPosition.");
                    }
                    TryProcess(e);
                }
                _nextReadPosition = slice.NextPosition;

                done = lastCommitPosition == null
                               ? slice.IsEndOfStream
                               : slice.NextPosition >= new Position(lastCommitPosition.Value, lastCommitPosition.Value);

                if (!done && slice.IsEndOfStream)
                {
                    Thread.Sleep(1); // we are waiting for server to flush its data
                }
            } while (!done);

            if (Verbose)
            {
                Log.Debug("Catch-up Subscription to {0}: finished reading events, nextReadPosition = {1}.",
                          IsSubscribedToAll ? "<all>" : StreamId, _nextReadPosition);
            }
        }
예제 #3
0
        private void UpgradeProjectionPartitionCheckpoints()
        {
            Log("Looking for projection partition checkpoint streams");
            var from = Position.Start;

            _oldTfScanPercent = 0d;
            var lastSlice = _connection.ReadAllEventsBackward(Position.End, 1, false, _credentials);

            if (lastSlice.Events.Length == 0)
            {
                throw new Exception("Empty TF");
            }
            _lastTfPosition = lastSlice.Events[0].OriginalPosition.Value.PreparePosition;
            AllEventsSlice slice;

            do
            {
                slice = _connection.ReadAllEventsForward(@from, 100, false, _credentials);
                DisplayTfScanProgress(slice);
                foreach (var @event in slice.Events)
                {
                    if (@event.OriginalEventNumber == 0)
                    {
                        UpgradeStreamIfPartitionCheckpoint(@event.OriginalStreamId);
                    }
                }
                from = slice.NextPosition;
            } while (!slice.IsEndOfStream);
            Log("Completed looking for partition checkpoint streams");
        }
        public static void DeleteAllStreams(this IEventStoreConnection connection)
        {
            var slice = connection.ReadAllEventsForward(Position.Start, Int32.MaxValue, false,
                                                        EmbeddedEventStore.Instance.DefaultCredentials);
            var streams = slice.
                          Events.
                          Select(_ => _.OriginalStreamId).
                          Where(StreamNameIsNotReserved).
                          Distinct();

            foreach (var stream in
                     from _ in streams
                     let streamStatusSlice = connection.ReadStreamEventsForward(_, 0, 1, false)
                                             where streamStatusSlice.Status != SliceReadStatus.StreamDeleted &&
                                             streamStatusSlice.Status != SliceReadStatus.StreamNotFound
                                             select _)
            {
                connection.DeleteStream(stream, ExpectedVersion.Any, EmbeddedEventStore.Instance.DefaultCredentials);
            }
        }
예제 #5
0
        static void FromAll(IEventStoreConnection con, UserCredentials userCredentials)
        {
            var sub = con.SubscribeToAllFrom(Position.Start, true, Appeared, Live, Dropped, userCredentials);
            // sub.Start();

            var read = con.ReadAllEventsForward(Position.Start, 1000, true, userCredentials);
            var mre  = new ManualResetEvent(false);

            mre.WaitOne(3000);

            var rgpsa = events.GroupBy(g => g.Event.EventId).ToList();
            int i     = 0;
            var rgps  = events.Select(s => new { s, position = i++ }).GroupBy(g => g.s.Event.EventId).ToList();
            var rgps2 = read.Events.Select(s => new { s, position = i++ }).GroupBy(g => g.s.Event.EventId).ToList();

            foreach (var r in rgps)
            {
                var values = r.ToArray();
            }
            Console.ReadLine();
        }
        protected override void ReadEventsTill(IEventStoreConnection connection, bool resolveLinkTos, 
                                               UserCredentials userCredentials, long? lastCommitPosition, int? lastEventNumber)
        {
            bool done;
            do
            {
                AllEventsSlice slice = connection.ReadAllEventsForward(_nextReadPosition, ReadBatchSize, resolveLinkTos, userCredentials);
                foreach (var e in slice.Events)
                {
                    if (e.OriginalPosition == null) throw new Exception("Subscription event came up with no OriginalPosition.");
                    TryProcess(e);
                }
                _nextReadPosition = slice.NextPosition;

                done = lastCommitPosition == null
                               ? slice.IsEndOfStream
                               : slice.NextPosition >= new Position(lastCommitPosition.Value, lastCommitPosition.Value);

                if (!done && slice.IsEndOfStream)
                    Thread.Sleep(1); // we are waiting for server to flush its data
            } while (!done);

            if (Verbose) 
                Log.Debug("Catch-up Subscription to {0}: finished reading events, nextReadPosition = {1}.", 
                          IsSubscribedToAll ? "<all>" : StreamId, _nextReadPosition);
        }
예제 #7
0
 protected void ReadAllForward(string login, string password)
 {
     Connection.ReadAllEventsForward(Position.Start, 1, false,
                                     login == null && password == null ? null : new UserCredentials(login, password));
 }
예제 #8
0
        static void FromAll(IEventStoreConnection con, UserCredentials userCredentials)
        {
            var sub = con.SubscribeToAllFrom(Position.Start, true, Appeared, Live, Dropped, userCredentials);
            // sub.Start();

            var read = con.ReadAllEventsForward(Position.Start, 1000, true, userCredentials);
            var mre = new ManualResetEvent(false);
            mre.WaitOne(3000);

            var rgpsa = events.GroupBy(g => g.Event.EventId).ToList();
            int i = 0;
            var rgps = events.Select(s => new { s, position = i++ }).GroupBy(g => g.s.Event.EventId).ToList();
            var rgps2 = read.Events.Select(s => new { s, position = i++ }).GroupBy(g => g.s.Event.EventId).ToList();

            foreach (var r in rgps)
            {
                var values = r.ToArray();

            }
            Console.ReadLine();
        }