public with_snapshots() { Snapshots = new DefaultSnapshotStore(new InMemoryPersistence()); Persistence.AppendAsync("Ticket_1", 1, new Changeset(1, new TicketSold())).Wait(); Persistence.AppendAsync("Ticket_1", 2, new Changeset(2, new TicketRefunded())).Wait(); }
public virtual async Task <IChunk> AppendAsync( object payload, string operationId, CancellationToken cancellation ) { for (var retries = 0; retries < 10; retries++) { try { if (_lastIndex == -1) { var last = await PeekAsync(cancellation).ConfigureAwait(false); _lastIndex = last?.Index ?? 0; } var index = _lastIndex + 1; var chunk = await Persistence.AppendAsync(this.Id, index, payload, operationId, cancellation) .ConfigureAwait(false); _lastIndex = chunk.Index; return(chunk); } catch (DuplicateStreamIndexException) { _lastIndex = -1; } } throw new AppendFailedException(this.Id, "Too many retries"); }
public async Task <IChunk> AppendAsync(object payload, string operationId, CancellationToken cancellation) { IChunk chunk = null; if (Version == -1) { throw new AppendFailedException(this.Id, $@"Cannot append on stream {this.Id} Append can be called only after a Read operation. If you don't need to read use {typeof(Stream).Name} instead of {GetType().Name}.") ; } long desiredVersion = this.Version + 1; try { chunk = await Persistence.AppendAsync(this.Id, desiredVersion, payload, operationId, cancellation).ConfigureAwait(false); } catch (DuplicateStreamIndexException e) { throw new ConcurrencyException($"Concurrency exception on StreamId: {this.Id}", e); } this.Version = desiredVersion; return(chunk); }
public virtual Task <IChunk> AppendAsync( object payload, string operationId, CancellationToken cancellation ) { return(Persistence.AppendAsync(this.Id, -1, payload, operationId, cancellation)); }
public async Task AppendAsync(object payload, string operationId, CancellationToken cancellation) { if (Version == -1) { throw new AppendFailedException(this.Id, $@"Cannot append on stream {this.Id} Append can be called only after a Read operation. If you don't need to read use {typeof(Stream).Name} instead of {GetType().Name}.") ; } long desiredVersion = this.Version + 1; await Persistence.AppendAsync(this.Id, desiredVersion, payload, operationId, cancellation).ConfigureAwait(false); this.Version = desiredVersion; }
public Task <IChunk> PersistAsync(object payload, long index, string operationId, CancellationToken cancellation) { return(Persistence.AppendAsync(this.Id, index, payload, operationId, cancellation)); }
public with_populated_stream() { Persistence.AppendAsync("Ticket_1", 1, new Changeset(1, new TicketSold())).Wait(); Persistence.AppendAsync("Ticket_1", 2, new Changeset(2, new TicketRefunded())).Wait(); }