public void checkpoint_suggested_at_the_start_position_throws_invalid_operation_exception()
 {
     _manager.CheckpointSuggested(
         CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
         { "a", 2 }, { "b", 2 }
     }), 77.7f);
 }
 protected override void When()
 {
     base.When();
     _exception = null;
     try
     {
         _manager.BeginLoadState();
         _manager.Start(CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
             { "a", 2 }, { "b", 2 }
         }));
         _manager.EventProcessed(
             @"{""state"":""state1""}", null,
             CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
             { "a", 2 }, { "b", 3 }
         }), 77.7f);
         _manager.EventProcessed(
             @"{""state"":""state2""}", null,
             CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
             { "a", 2 }, { "b", 4 }
         }), 77.7f);
     }
     catch (Exception ex)
     {
         _exception = ex;
     }
 }
 public void accepts_checkpoint_suggested()
 {
     _manager.CheckpointSuggested(
         CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
         { "a", 3 }, { "b", 6 }
     }), 77.7f);
 }
        protected override void When()
        {
            base.When();
            Action noop = () => { };

            _manager.Initialize();
            _checkpointReader.BeginLoadState();
            var checkpointLoaded =
                _consumer.HandledMessages.OfType <CoreProjectionProcessingMessage.CheckpointLoaded>().First();

            _checkpointWriter.StartFrom(checkpointLoaded.CheckpointTag, checkpointLoaded.CheckpointEventNumber);
            _manager.BeginLoadPrerecordedEvents(checkpointLoaded.CheckpointTag);

            _manager.Start(CheckpointTag.FromStreamPositions(0, new Dictionary <string, long> {
                { "pa", -1 }, { "pb", -1 }
            }),
                           null);
            _manager.RecordEventOrder(_event1,
                                      CheckpointTag.FromStreamPositions(0, new Dictionary <string, long> {
                { "pa", 1 }, { "pb", -1 }
            }),
                                      committed: noop);
            _manager.RecordEventOrder(_event2,
                                      CheckpointTag.FromStreamPositions(0, new Dictionary <string, long> {
                { "pa", 1 }, { "pb", 1 }
            }),
                                      committed: noop);
        }
        public ClientMessage.ReadStreamEventsBackwardCompleted ReadOrderStream(
            ClientMessage.ReadStreamEventsBackward message)
        {
            ResolvedEvent[] events;
            if (!_hasRead)
            {
                var checkpoint =
                    CheckpointTag.FromStreamPositions(0, new Dictionary <string, long> {
                    { "a", 5 }, { "b", 5 }, { "c", 5 }
                });
                events = IODispatcherTestHelpers.CreateResolvedEvent <TLogFormat, TStreamId>(message.EventStreamId, "$>",
                                                                                             "10@a", checkpoint.ToJsonString(new ProjectionVersion(3, 0, 1)));
                _hasRead = true;
            }
            else
            {
                events = new ResolvedEvent[0] {
                };
            }

            return(new ClientMessage.ReadStreamEventsBackwardCompleted(message.CorrelationId, message.EventStreamId,
                                                                       message.FromEventNumber,
                                                                       message.MaxCount, ReadStreamResult.Success, events, null, true, "",
                                                                       message.FromEventNumber - events.Length, message.FromEventNumber, true, 10000));
        }
        public void TestFixtureSetUp()
        {
            _ioDispatcher      = new IODispatcher(_bus, new PublishEnvelope(_bus), true);
            _projectionVersion = new ProjectionVersion(3, 1, 2);
            _projectionConfig  = new ProjectionConfig(SystemAccounts.System, 10, 1000, 1000, 10, true, true, true,
                                                      false,
                                                      false, 5000, 10);
            _positionTagger = new MultiStreamPositionTagger(3, _streams);
            _positionTagger.AdjustTag(CheckpointTag.FromStreamPositions(3,
                                                                        new Dictionary <string, long> {
                { "a", 0 }, { "b", 0 }, { "c", 0 }
            }));
            _namingBuilder = ProjectionNamesBuilder.CreateForTest("projection");

            IODispatcherTestHelpers.SubscribeIODispatcher(_ioDispatcher, _bus);
            _bus.Subscribe <ClientMessage.ReadStreamEventsBackward>(this);

            _coreProjectionCheckpointWriter = new CoreProjectionCheckpointWriter(
                _namingBuilder.MakeCheckpointStreamName(), _ioDispatcher,
                _projectionVersion, _projectionName);

            _checkpointManager = new MultiStreamMultiOutputCheckpointManager(_bus, _projectionId, _projectionVersion,
                                                                             SystemAccounts.System,
                                                                             _ioDispatcher, _projectionConfig, _projectionName, _positionTagger, _namingBuilder, true, true, false,
                                                                             _coreProjectionCheckpointWriter);

            When();
        }
 public void event_processed_at_the_start_position_throws_invalid_operation_exception()
 {
     _manager.EventProcessed(
         @"{""state"":""state""}", null,
         CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
         { "a", 2 }, { "b", 2 }
     }), 77.7f);
 }
Exemple #8
0
 public void projection_position_is_correct()
 {
     Assert.AreEqual(
         CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
         { "stream2", 1 }, { "stream3", 3 }
     }),
         _state.Position);
 }
        public void it_cannot_be_updated_with_other_streams()
        {
            var newTag = CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
                { "stream1", 10 }, { "stream3", 20 }
            });

            _positionTracker.UpdateByCheckpointTagInitial(newTag);
        }
        public void it_cannot_be_updated_forward()
        {
            var newTag = CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
                { "stream1", 10 }, { "stream2", 20 }
            });

            _positionTracker.UpdateByCheckpointTagForward(newTag);
        }
        public void cannot_update_to_the_same_postion()
        {
            var newTag = CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
                { "stream1", 1 }, { "stream2", 3 }
            });

            _positionTracker.UpdateByCheckpointTagForward(newTag);
        }
 public void accepts_event_processed()
 {
     _manager.EventProcessed(
         @"{""state"":""state""}", null,
         CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
         { "a", 3 }, { "b", 4 }
     }), 77.7f);
 }
Exemple #13
0
        public void is_message_after_checkpoint_tag_incompatible_streams_case()
        {
            var t      = new MultiStreamPositionTagger(new[] { "stream-other", "stream2" });
            var result = t.IsMessageAfterCheckpointTag(CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
                { "stream-other", 0 }, { "stream2", 0 }
            }), _firstEvent);

            Assert.IsFalse(result);
        }
Exemple #14
0
 public void cannot_update_to_the_same_postion()
 {
     Assert.Throws <InvalidOperationException>(() => {
         var newTag = CheckpointTag.FromStreamPositions(0, new Dictionary <string, long> {
             { "stream1", 1 }, { "stream2", 3 }
         });
         _positionTracker.UpdateByCheckpointTagForward(newTag);
     });
 }
 public void it_cannot_be_updated_forward()
 {
     Assert.Throws <InvalidOperationException>(() => {
         var newTag = CheckpointTag.FromStreamPositions(0, new Dictionary <string, long> {
             { "stream1", 10 }, { "stream2", 20 }
         });
         _positionTracker.UpdateByCheckpointTagForward(newTag);
     });
 }
        public void it_cannot_be_updated_with_other_stream()
        {
            // even not initialized (UpdateToZero can be removed)
            var newTag = CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
                { "stream1", 3 }, { "stream3", 2 }
            });

            _positionTracker.UpdateByCheckpointTagForward(newTag);
        }
Exemple #17
0
        public void adjust_compatible_tag_returns_the_same_tag()
        {
            var t   = new MultiStreamPositionTagger(0, new[] { "stream1", "stream2" });
            var tag = CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
                { "stream1", 1 }, { "stream2", 2 }
            });

            Assert.AreEqual(tag, t.AdjustTag(tag));
        }
 public void sends_correct_preprecoded_events_loaded_message()
 {
     Assert.AreEqual(1, _projection._prerecordedEventsLoadedMessages.Count);
     Assert.AreEqual(
         CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
         { "a", 1 }, { "b", 1 }, { "c", 1 }
     }),
         _projection._prerecordedEventsLoadedMessages.Single().CheckpointTag);
 }
        public void it_can_be_updated_with_correct_streams()
        {
            // even not initialized (UpdateToZero can be removed)
            var newTag = CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
                { "stream1", 10 }, { "stream2", 20 }
            });

            _positionTracker.UpdateByCheckpointTagInitial(newTag);
        }
Exemple #20
0
        public void initial_position_cannot_be_set_twice()
        {
            var newTag = CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
                { "stream1", 10 }, { "stream2", 20 }
            });

            _positionTracker.UpdateByCheckpointTagForward(newTag);
            _positionTracker.UpdateByCheckpointTagForward(newTag);
        }
Exemple #21
0
		public void streams_based_checkpoint_tag() {
			CheckpointTag tag = CheckpointTag.FromStreamPositions(1, new Dictionary<string, long> {{"a", 1}, {"b", 2}});
			byte[] bytes = tag.ToJsonBytes(_version);
			string instring = Helper.UTF8NoBom.GetString(bytes);
			Console.WriteLine(instring);

			CheckpointTag back = instring.ParseCheckpointTagJson();
			Assert.AreEqual(tag, back);
			Assert.IsNull(back.CommitPosition);
		}
        public void another_streams_checkpoint_tag_is_incompatible()
        {
            var t = new MultiStreamPositionTagger(new[] { "stream1", "stream2" });

            Assert.IsFalse(
                t.IsCompatible(
                    CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
                { "stream2", 100 }, { "stream3", 150 }
            })));
        }
 public void sends_correct_checkpoint_loaded_message()
 {
     Assert.AreEqual(1, _projection._checkpointLoadedMessages.Count);
     Assert.AreEqual(
         CheckpointTag.FromStreamPositions(new Dictionary <string, int> {
         { "a", 0 }, { "b", 0 }, { "c", 0 }
     }),
         _projection._checkpointLoadedMessages.Single().CheckpointTag);
     Assert.AreEqual("{}", _projection._checkpointLoadedMessages.Single().CheckpointData);
 }
Exemple #24
0
 public void it_cannot_be_updated_with_other_stream()
 {
     Assert.Throws <InvalidOperationException>(() => {
         // even not initialized (UpdateToZero can be removed)
         var newTag = CheckpointTag.FromStreamPositions(0, new Dictionary <string, long> {
             { "stream1", 3 }, { "stream3", 2 }
         });
         _positionTracker.UpdateByCheckpointTagForward(newTag);
     });
 }
Exemple #25
0
 protected override IReaderSubscription CreateProjectionSubscription()
 {
     return(new EventReorderingReaderSubscription(_bus,
                                                  _projectionCorrelationId,
                                                  CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
         { "a", ExpectedVersion.NoStream }, { "b", ExpectedVersion.NoStream }
     }),
                                                  _readerStrategy,
                                                  _checkpointUnhandledBytesThreshold, _checkpointProcessedEventsThreshold, _processingLagMs));
 }
        public void streams_checkpoint_tag_is_incompatible()
        {
            var t = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" });

            Assert.IsFalse(
                t.IsCompatible(
                    CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
                { "$et-type1", 100 }, { "$et-type2", 150 }
            })));
        }
Exemple #27
0
        public void can_adjust_stream_position_tag()
        {
            var t   = new MultiStreamPositionTagger(0, new[] { "stream1", "stream2" });
            var tag = CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
                { "stream1", 1 }, { "stream2", -1 }
            });
            var original = CheckpointTag.FromStreamPosition(0, "stream1", 1);

            Assert.AreEqual(tag, t.AdjustTag(original));
        }
Exemple #28
0
        public void the_same_stream_checkpoint_tag_is_compatible()
        {
            var t = new MultiStreamPositionTagger(0, new[] { "stream1", "stream2" });

            Assert.IsTrue(
                t.IsCompatible(
                    CheckpointTag.FromStreamPositions(0, new Dictionary <string, int> {
                { "stream1", 100 }, { "stream2", 150 }
            })));
        }
Exemple #29
0
        public void can_adjust_multi_stream_position_tag()
        {
            var t        = new StreamPositionTagger("stream1");
            var tag      = CheckpointTag.FromStreamPosition("stream1", 1);
            var original = CheckpointTag.FromStreamPositions(
                new Dictionary <string, int> {
                { "stream1", 1 }, { "stream2", 2 }
            });

            Assert.AreEqual(tag, t.AdjustTag(original));
        }
Exemple #30
0
            protected override IEnumerable <WhenStep> When()
            {
                var fromZeroPosition =
                    CheckpointTag.FromStreamPositions(0,
                                                      new Dictionary <string, long> {
                    { "stream-a", -1 }, { "stream-b", -1 }
                });

                yield return
                    (new ReaderSubscriptionManagement.Subscribe(
                         _subscriptionId, fromZeroPosition, _readerStrategy, _readerSubscriptionOptions));


                var correlationId = Guid.NewGuid();

                yield return
                    (new ClientMessage.TransactionStart(
                         Guid.NewGuid(), correlationId, new PublishEnvelope(GetInputQueue()), true, "stream-a", 0, null));

                var transactionId =
                    _consumer.HandledMessages.OfType <ClientMessage.TransactionStartCompleted>()
                    .Single(m => m.CorrelationId == correlationId)
                    .TransactionId;

                correlationId = Guid.NewGuid();
                yield return
                    (new ClientMessage.TransactionWrite(
                         Guid.NewGuid(), correlationId, new PublishEnvelope(GetInputQueue()), true, transactionId,
                         new[] { new Event(Guid.NewGuid(), "type1", true, "{Data: 3, Transacted=true}", "{}") }, null));

                correlationId = Guid.NewGuid();
                yield return
                    (new ClientMessage.WriteEvents(
                         Guid.NewGuid(), correlationId, new PublishEnvelope(GetInputQueue()), true, "stream-b", 0,
                         new[] { new Event(Guid.NewGuid(), "type1", true, "{Data: 4}", "{}") }, null));

                correlationId = Guid.NewGuid();
                yield return
                    (new ClientMessage.TransactionWrite(
                         Guid.NewGuid(), correlationId, new PublishEnvelope(GetInputQueue()), true, transactionId,
                         new[] { new Event(Guid.NewGuid(), "type1", true, "{Data: 5, Transacted=true}", "{}") }, null));

                correlationId = Guid.NewGuid();
                yield return
                    (new ClientMessage.TransactionCommit(
                         Guid.NewGuid(), correlationId, new PublishEnvelope(GetInputQueue()), true, transactionId, null));

                yield return(Yield);

                _timeProvider.AddToUtcTime(TimeSpan.FromMilliseconds(300));

                yield return(Yield);
            }