public OptimisticEventStream(Snapshot snapshot, ICommitEvents persistence, int maxRevision) : this(snapshot.StreamId, persistence) { IEnumerable<Commit> commits = persistence.GetFrom(snapshot.StreamId, snapshot.StreamRevision, maxRevision); PopulateStream(snapshot.StreamRevision + 1, maxRevision, commits); StreamRevision = snapshot.StreamRevision + _committed.Count; }
public bool Save(string streamId, int streamVersion) { try { var innerPayload = snapshotContentDictionary .Values .Select(p => new TrackedTag(p.Id, p.Version)) .ToList <object>(); var snap = new NEventStoreSnapshot( streamId, streamVersion, innerPayload); var result = EventStore.Advanced.AddSnapshot(snap); return(result); } catch (Exception e) { throw e; } }
public virtual IEventStream OpenStream(Snapshot snapshot, int maxRevision) { if (snapshot == null) { throw new ArgumentNullException("snapshot"); } Logger.Debug(Resources.OpeningStreamWithSnapshot, snapshot.StreamId, snapshot.StreamRevision, maxRevision); maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision; return new OptimisticEventStream(snapshot, this, maxRevision); }
protected override void Context() { snapshot = new Snapshot(streamId, 1, "snapshot"); _committed = BuildCommitStub(1, 1); A.CallTo(() => Persistence.GetFrom(Bucket.Default, streamId, snapshot.StreamRevision, int.MaxValue)) .Returns(new[] { _committed }); }
protected override void Context() { _snapshot = new Snapshot(streamId, HeadStreamRevision, "snapshot"); _committed = new EnumerableCounter<ICommit>( new[] { BuildCommitStub(HeadStreamRevision, HeadCommitSequence)}); A.CallTo(() => Persistence.GetFrom(Bucket.Default, streamId, HeadStreamRevision, int.MaxValue)) .Returns(_committed); }
protected override void Context() { _snapshot = new Snapshot(streamId, 42, "snapshot"); _committed = new[] { BuildCommitStub(42, 0)}; A.CallTo(() => Persistence.GetFrom(Bucket.Default, streamId, 42, MaxRevision)).Returns(_committed); }
protected override void Context() { snapshot = new Snapshot(streamId, HeadStreamRevision, "snapshot"); Committed = new EnumerableCounter( new[] {BuildCommitStub(HeadStreamRevision, HeadCommitSequence)}); Persistence.Setup(x => x.GetFrom(streamId, HeadStreamRevision, int.MaxValue)).Returns(Committed); }
protected override void Context() { snapshot = new Snapshot(streamId, 1, "snapshot"); Committed = BuildCommitStub(1, 1); Persistence .Setup(x => x.GetFrom(streamId, snapshot.StreamRevision, int.MaxValue)) .Returns(new[] {Committed}); }
protected override void Context() { snapshot = new Snapshot(streamId, 42, "snapshot"); Committed = new[] {BuildCommitStub(42, 0)}; Persistence.Setup(x => x.GetFrom(streamId, 42, MaxRevision)).Returns(Committed); }
protected override Task Context() { snapshot = new Snapshot(streamId, 1, "snapshot"); _committed = BuildCommitStub(1, 1); //A.CallTo(() => Persistence.GetFrom(Bucket.Default, streamId, snapshot.StreamRevision, int.MaxValue)) // .Returns(new[] { _committed }.ToAsync()); Persistence.GetFrom(Bucket.Default, streamId, snapshot.StreamRevision, int.MaxValue) .Returns(new[] { _committed }.ToAsync()); return Task.FromResult(true); }
protected override Task Context() { _snapshot = new Snapshot(streamId, HeadStreamRevision, "snapshot"); _committed = new EnumerableCounter<ICommit>( new[] { BuildCommitStub(HeadStreamRevision, HeadCommitSequence)}); Persistence .GetFrom(Bucket.Default, streamId, HeadStreamRevision, int.MaxValue) .Returns(_committed.ToAsync()); //A.CallTo(() => Persistence.GetFrom(Bucket.Default, streamId, HeadStreamRevision, int.MaxValue)) // .Returns(_committed.ToAsync()); return Task.FromResult(true); }
protected override Task Context() { _snapshot = new Snapshot(streamId, 42, "snapshot"); _committed = new[] { BuildCommitStub(42, 0)}; Persistence.GetFrom(Bucket.Default, streamId, 42, MaxRevision).Returns(_committed.ToAsync()); //A.CallTo(() => Persistence.GetFrom(Bucket.Default, streamId, 42, MaxRevision)).Returns(_committed.ToAsync()); return Task.FromResult(true); }
public void When_using_snapshots_only_following_events_should_be_retrieved_when_reopening_the_stream() { var streamId = Guid.NewGuid(); var event1 = Event.Create(streamId, new SomethingHappened("data1")); var event2 = Event.Create(streamId, new SomethingHappened("data2")); var event3 = Event.Create(streamId, new SomethingHappened("data3")); using (var connection1 = CreateSqlConnection()) { using (var stream = connection1.OpenStream(streamId, 0)) { stream.Add(new EventMessage { Body = event1.Data }); stream.Add(new EventMessage { Body = event2.Data }); stream.Add(new EventMessage { Body = event3.Data }); stream.CommitChanges(event1.EventId); var snapshotData = new SomeSnapshot(new[] { event1.Data, event2.Data, event3.Data }); var snapshot = new Snapshot(stream.StreamId, stream.StreamRevision, snapshotData); connection1.Advanced.AddSnapshot(snapshot); stream.CommitChanges(Guid.NewGuid()); stream.CommittedEvents.Count.ShouldBe(3); } var snapshot2 = connection1.Advanced.GetSnapshot(streamId, int.MaxValue); ((SomeSnapshot)snapshot2.Payload).State.ShouldBe(new[] { "data1", "data2", "data3", }); using (var stream = connection1.OpenStream(snapshot2, int.MaxValue)) { stream.CommittedEvents.Count.ShouldBe(0); var event4 = Event.Create(streamId, new SomethingHappened("data4")); var event5 = Event.Create(streamId, new SomethingHappened("data5")); stream.Add(new EventMessage { Body = event4.Data }); stream.Add(new EventMessage { Body = event5.Data }); stream.CommitChanges(event4.EventId); } var snapshot3 = connection1.Advanced.GetSnapshot(streamId, int.MaxValue); ((SomeSnapshot)snapshot3.Payload).State.ShouldBe(new[] { "data1", "data2", "data3", }); using (var stream = connection1.OpenStream(snapshot3, int.MaxValue)) { stream.CommittedEvents.Count.ShouldBe(2); stream.CommittedEvents.Select(x => x.Body).OfType<SomethingHappened>().Select(x => x.Something) .ShouldBe(new[] { "data4", "data5" }); } } }