public async Task SqlSaveAsync(PostgreSqlDbContext db, List <EventStorageBufferWrap> eventWraps) { using (var trans = db.BeginTransaction()) { try { foreach (var wrap in eventWraps) { EventSingleStorageModel model = wrap.Value; var data = this.GetSerializer().Serialize(model.Event); wrap.Result = await db.ExecuteAsync(this.insertSql, new { StateId = model.StateId, RelationEvent = model.Event.RelationEvent, TypeCode = model.Event.TypeCode, Data = data, DataType = this.options.SerializationType, Version = model.Event.Version, AddTime = model.Event.Timestamp }) > 0; } trans.Commit(); eventWraps.ForEach(wrap => wrap.TaskSource.TrySetResult(wrap.Result)); } catch (Exception ex) { trans.Rollback(); eventWraps.ForEach(wrap => wrap.TaskSource.TrySetException(ex)); } } }
public void should_Save_IndexConstraint() { eventWraps = new List <EventStorageBufferWrap>(); for (int i = 0; i < 3; i++) { var e = TestEvent.Create(i); if (i == 2) { e.RelationEvent = "RelationEvent1"; } else { e.RelationEvent = "RelationEvent" + i; } e.StateId = 3000; EventSingleStorageModel model = new EventSingleStorageModel(e.StateId, e, this.EventSourceName, this.TableName); eventWraps.Add(new EventStorageBufferWrap(model)); } this.Given(f => f.Given_CreateTable()) .When(f => f.When_Save(eventWraps)) .Then(f => Then_Save_IndexConstraint(eventWraps)) .BDDfy(); }
public void should_GetList() { eventWraps = new List <EventStorageBufferWrap>(); for (int i = 0; i < 100; i++) { var e = TestEvent.Create(1); e.StateId = 4000 + i; if (i < 50) { e.RelationEvent = "Test"; } else { e.RelationEvent = "ABC"; } EventSingleStorageModel model = new EventSingleStorageModel(e.StateId, e, this.EventSourceName, this.TableName); eventWraps.Add(new EventStorageBufferWrap(model)); } this.Given(f => f.Given_CreateTable()) .When(f => f.When_Save(eventWraps)) .Then(f => f.Then_GetList_Success(eventWraps)) .BDDfy(); }
public async Task <bool> SaveAsync(IEvent <TStateKey> @event) { //Sharding processing string storageTableName = await this.GetEventTableName(); EventSingleStorageModel storageModel = new EventSingleStorageModel(@event.StateId, @event, this.Options.EventSourceName, storageTableName); var bufferWrap = new EventStorageBufferWrap(storageModel); return(await this._eventBufferBlock.SendAsync(bufferWrap)); }
public void should_Save_MickleSuccess() { eventWraps = new List <EventStorageBufferWrap>(); for (int i = 0; i < 100; i++) { var e = TestEvent.Create(1); e.StateId = 1001 + i; EventSingleStorageModel model = new EventSingleStorageModel(e.StateId, e, this.EventSourceName, this.TableName); eventWraps.Add(new EventStorageBufferWrap(model)); } this.Given(f => f.Given_CreateTable()) .When(f => f.When_Save(eventWraps)) .Then(f => f.Then_Save_MickleSuccess()) .BDDfy(); }
public void should_Save_UniqueConstraint() { eventWraps = new List <EventStorageBufferWrap>(); for (int i = 0; i < 3; i++) { var e = TestEvent.Create(i); if (i == 2) { e.Version = 1; } e.StateId = 2000; EventSingleStorageModel model = new EventSingleStorageModel(e.StateId, e, this.EventSourceName, this.TableName); eventWraps.Add(new EventStorageBufferWrap(model)); } this.Given(f => f.Given_CreateTable()) .Then(f => Then_Save_UniqueConstraint(eventWraps)) .BDDfy(); }
public void should_Save_SingleSuccess() { var e = TestEvent.Create(1); e.StateId = 1000; EventSingleStorageModel model = new EventSingleStorageModel(e.StateId, e, this.EventSourceName, this.TableName); eventWrap = new EventStorageBufferWrap(model); List <EventStorageBufferWrap> eventWraps = new List <EventStorageBufferWrap> { eventWrap }; this .Given(f => f.Given_CreateTable()) .When(f => f.When_Save(eventWraps)) .When(f => f.When_Get(e.StateId, e.Version)) .Then(f => f.Then_Save_SingleSuccess(e)) .BDDfy(); }
public EventStorageBufferWrap(EventSingleStorageModel @event) { this.Value = @event; this.TaskSource = new TaskCompletionSource <bool>(); }