protected override IEnumerable <WhenStep> When() { var fromZeroPosition = CheckpointTag.FromEventTypeIndexPositions( 0, new TFPos(0, -1), new Dictionary <string, long> { { "type1", -1 }, { "type2", -1 } }); yield return (new ReaderSubscriptionManagement.Subscribe( _subscriptionId, fromZeroPosition, _readerStrategy, _readerSubscriptionOptions)); // simulate index-by-type system projection yield return (new ClientMessage.WriteEvents( Guid.NewGuid(), Guid.NewGuid(), new NoopEnvelope(), false, "$et-type1", ExpectedVersion.Any, new Event(Guid.NewGuid(), "$>", false, "0@test-stream", TFPosToMetadata(_tfPos1)), user: null)); // simulate index-by-type system projection (the second event write is delayed - awaiting for ACK from the previous write) yield return (new ClientMessage.WriteEvents( Guid.NewGuid(), Guid.NewGuid(), new NoopEnvelope(), false, "$et-type2", ExpectedVersion.Any, new Event(Guid.NewGuid(), "$>", false, "2@test-stream", TFPosToMetadata(_tfPos3)), user: null)); // simulate index-by-type system projection (ACK received - writing the next event) yield return (new ClientMessage.WriteEvents( Guid.NewGuid(), Guid.NewGuid(), new NoopEnvelope(), false, "$et-type1", ExpectedVersion.Any, new Event(Guid.NewGuid(), "$>", false, "1@test-stream", TFPosToMetadata(_tfPos2)), user: null)); }
protected override void Given() { base.Given(); _tfPos1 = ExistingEvent("test-stream", "type1", "{}", "{Data: 1}"); _tfPos2 = ExistingEvent("test-stream", "type1", "{}", "{Data: 2}"); _tfPos3 = ExistingEvent("test-stream", "type2", "{}", "{Data: 3}"); // writes reordered due to batching or timeouts in system projection ExistingEvent("$et-type1", "$>", TFPosToMetadata(_tfPos1), "0@test-stream"); ExistingEvent("$et-type2", "$>", TFPosToMetadata(_tfPos3), "2@test-stream"); ExistingEvent("$et-type1", "$>", TFPosToMetadata(_tfPos2), "1@test-stream"); NoStream("$et"); _querySourcesDefinition = new QuerySourcesDefinition { AllStreams = true, Events = new[] { "type1", "type2" }, Options = new QuerySourcesDefinitionOptions { } }; _fromPosition = CheckpointTag.FromEventTypeIndexPositions( new TFPos(0, -1), new Dictionary <string, int> { { "type1", -1 }, { "type2", -1 } }); _maxEvents = 3; }
//private TFPos _tfPos2; //private TFPos _tfPos3; protected override void Given() { base.Given(); _tfPos1 = ExistingEvent("test-stream", "type1", "{}", "{Data: 1}"); //_tfPos2 = ExistingEvent("test-stream", "type1", "{}", "{Data: 2}"); //_tfPos3 = ExistingEvent("test-stream", "type2", "{}", "{Data: 3}"); ExistingEvent("$et-type1", "$>", TFPosToMetadata(_tfPos1), "0@test-stream"); NoStream("$et-type2"); NoStream("$et"); //NOTE: the following events should be late written //ExistingEvent("$et-type2", "$>", "", "2@test-stream"); //ExistingEvent("$et-type1", "$>", "", "1@test-stream"); _querySourcesDefinition = new QuerySourcesDefinition { AllStreams = true, Events = new[] { "type1", "type2" }, Options = new QuerySourcesDefinitionOptions { } }; _fromPosition = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(0, -1), new Dictionary <string, long> { { "type1", -1 }, { "type2", -1 } }); _maxEvents = 1; // reading the first event }
public void cannot_update_to_the_same_position() { var newTag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(20, 15), new Dictionary <string, long> { { "type1", 1 }, { "type2", 3 } }); Assert.Throws <InvalidOperationException>(() => { _positionTracker.UpdateByCheckpointTagForward(newTag); }); }
public void it_cannot_be_updated_forward() { var newTag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(100, 50), new Dictionary <string, int> { { "type1", 10 }, { "type2", 20 } }); _positionTracker.UpdateByCheckpointTagForward(newTag); }
public void it_cannot_be_updated_with_other_event_types() { var newTag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(100, 50), new Dictionary <string, int> { { "type1", 10 }, { "type3", 20 } }); _positionTracker.UpdateByCheckpointTagInitial(newTag); }
public void can_update_to_the_same_index_position_but_tf() { var newTag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(30, 25), new Dictionary <string, int> { { "type1", 1 }, { "type2", 3 } }); _positionTracker.UpdateByCheckpointTagForward(newTag); }
public void it_cannot_be_updated_forward() { var newTag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(100, 50), new Dictionary <string, long> { { "type1", 10 }, { "type2", 20 } }); Assert.Throws <InvalidOperationException>(() => { _positionTracker.UpdateByCheckpointTagForward(newTag); }); }
public void it_cannot_be_updated_with_other_stream() { // even not initialized (UpdateToZero can be removed) var newTag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(30, 25), new Dictionary <string, long> { { "type1", 1 }, { "type3", 3 } }); Assert.Throws <InvalidOperationException>(() => { _positionTracker.UpdateByCheckpointTagForward(newTag); }); }
public void it_cannot_be_updated_with_other_stream() { // even not initialized (UpdateToZero can be removed) var newTag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(30, 25), new Dictionary <string, int> { { "type1", 1 }, { "type3", 3 } }); _positionTracker.UpdateByCheckpointTagForward(newTag); }
public void it_can_be_updated_with_correct_event_types() { // even not initialized (UpdateToZero can be removed) var newTag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(100, 50), new Dictionary <string, long> { { "type1", 10 }, { "type2", 20 } }); _positionTracker.UpdateByCheckpointTagInitial(newTag); }
public void returns_correct_last_reader_position() { var feedPage = _consumer.HandledMessages.OfType <FeedReaderMessage.FeedPage>().Single(); Assert.AreEqual( CheckpointTag.FromEventTypeIndexPositions(0, _tfPos1, new Dictionary <string, long> { { "type1", 0 }, { "type2", -1 } }), feedPage.LastReaderPosition); }
public void adjust_compatible_tag_returns_the_same_tag() { var t = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); var tag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(100, 50), new Dictionary <string, int> { { "type1", 1 }, { "type2", 2 } }); Assert.AreEqual(tag, t.AdjustTag(tag)); }
public void projection_position_is_correct() { var pos = GetTfPos("stream2", 1); Assert.That( CheckpointTag.FromEventTypeIndexPositions(0, pos, new Dictionary <string, int> { { "type3", 1 } }) <= _state.Position); }
public void projection_position_is_correct() { var pos = GetTfPos("stream5", 0); Assert.AreEqual( CheckpointTag.FromEventTypeIndexPositions(0, pos, new Dictionary <string, int> { { "type1", 1 }, { "type3", 1 } }), _state.Position); }
protected override void When() { //projection subscribes here _bus.Publish( new EventReaderSubscriptionMessage.CheckpointSuggested( _subscriptionId, CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(140, 130), new Dictionary <string, int> { { "non-existing", -1 } }), 55.5f, 0)); }
public void the_same_events_checkpoint_tag_is_compatible() { var t = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); Assert.IsTrue( t.IsCompatible( CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(100, 50), new Dictionary <string, int> { { "type1", 100 }, { "type2", 150 } }))); }
public void event_by_type_index_based_checkpoint_tag() { CheckpointTag tag = CheckpointTag.FromEventTypeIndexPositions( 0, new TFPos(100, 50), 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); }
public void can_adjust_tf_position_tag() { var t = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); var tag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(100, 50), new Dictionary <string, int> { { "type1", 1 }, { "type2", 2 } }); var original = CheckpointTag.FromPosition(0, 100, 50); Assert.AreEqual(tag, t.AdjustTag(original)); }
protected override IEnumerable <WhenStep> When() { var fromZeroPosition = CheckpointTag.FromEventTypeIndexPositions( 0, new TFPos(0, -1), new Dictionary <string, long> { { "type1", -1 }, { "type2", -1 } }); yield return (new ReaderSubscriptionManagement.Subscribe( _subscriptionId, fromZeroPosition, _readerStrategy, _readerSubscriptionOptions)); }
public void is_message_after_checkpoint_tag_tf_only_after_case() { var t = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); var result = t.IsMessageAfterCheckpointTag( CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(10, 5), new Dictionary <string, int> { { "type1", 0 }, { "type2", 0 } }), _firstEvent); Assert.IsTrue(result); }
public void cannot_update_by_prior_tf_position() { var t = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); var linkEvent = ReaderSubscriptionMessage.CommittedEventDistributed.Sample( Guid.NewGuid(), new TFPos(180, 170), "$et-type2", 1, false, Guid.NewGuid(), "$>", false, Helper.UTF8NoBom.GetBytes("0@stream2"), new byte[0]); var tag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(270, 260), new Dictionary <string, int> { { "type1", 2 }, { "type2", 2 } }); t.MakeCheckpointTag(tag, linkEvent); }
public void is_message_after_checkpoint_tag_before_case() { var t = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); var result = t.IsMessageAfterCheckpointTag( CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(40, 35), new Dictionary <string, long> { { "type1", 2 }, { "type2", 2 } }), _firstEvent); Assert.IsFalse(result); }
public void is_message_after_checkpoint_tag_incompatible_streams_case() { var t = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); var result = t.IsMessageAfterCheckpointTag( CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(30, 20), new Dictionary <string, int> { { "type1", -1 }, { "type3", -1 } }), _firstEvent); Assert.IsFalse(result); }
public void When() { // given _tagger = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); _positionTracker = new PositionTracker(_tagger); var newTag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(10, 5), new Dictionary <string, int> { { "type1", 1 }, { "type2", 2 } }); var newTag2 = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(20, 15), new Dictionary <string, int> { { "type1", 1 }, { "type2", 3 } }); _positionTracker.UpdateByCheckpointTagInitial(newTag); _positionTracker.UpdateByCheckpointTagForward(newTag2); }
public void can_update_by_tf_event_if_with_prior_index_position() { var t = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); var linkEvent = ReaderSubscriptionMessage.CommittedEventDistributed.Sample( Guid.NewGuid(), new TFPos(180, 170), "$et-type2", 1, false, Guid.NewGuid(), "$>", false, Helper.UTF8NoBom.GetBytes("0@stream2"), new byte[0]); var tag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(70, 60), new Dictionary <string, int> { { "type1", 2 }, { "type2", 2 } }); var updated = t.MakeCheckpointTag(tag, linkEvent); Assert.AreEqual(new TFPos(180, 170), updated.Position); Assert.AreEqual(2, updated.Streams["type1"]); Assert.AreEqual(2, updated.Streams["type2"]); }
public void When() { // given var tagger = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); var tracker = new PositionTracker(tagger); var newTag = CheckpointTag.FromEventTypeIndexPositions(0, new TFPos(10, 5), new Dictionary <string, int> { { "type1", 1 }, { "type2", 2 } }); tracker.UpdateByCheckpointTagInitial(newTag); _tag = tracker.LastTag; _tagger = new EventByTypeIndexPositionTagger(0, new[] { "type1", "type2" }); _positionTracker = new PositionTracker(_tagger); // when _positionTracker.UpdateByCheckpointTagInitial(_tag); }
protected override IEnumerable <WhenStep> When() { var fromZeroPosition = CheckpointTag.FromEventTypeIndexPositions( new TFPos(0, -1), new Dictionary <string, int> { { "type1", -1 }, { "type2", -1 } }); yield return (new ReaderSubscriptionManagement.Subscribe( _subscriptionId, fromZeroPosition, _readerStrategy, _readerSubscriptionOptions)); DisableTimer(); yield return (CreateWriteEvent("test-stream", "type1", "{Data: 3}", "{}")); _tfPos3 = _all.Last(v => v.Value.EventStreamId == "test-stream").Key; yield return (CreateWriteEvent("$et-type1", "$>", "2@test-stream", TFPosToMetadata(_tfPos3), isJson: false)); yield return(CreateWriteEvent("$et-type2", "$>", "1@test-stream", TFPosToMetadata(_tfPos2))); yield return (CreateWriteEvent("$et", "$Checkpoint", TFPosToMetadata(_tfPos2), TFPosToMetadata(_tfPos2))); // we are still in index-based reading mode Assert.IsEmpty(_consumer.HandledMessages.OfType <ClientMessage.ReadAllEventsForward>()); // simulate late response to the read request in this particular order yield return (_consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsBackward>() .Single(v => v.EventStreamId == "$et")); yield return (_consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>() .Single(v => v.EventStreamId == "$et-type2")); EnableTimer(); }