public void BeVerified() { var array = new PlainArray( new PlainBulkString("cat"), new Integer(500) ); var verifyingOutput = new VerifyingOutput(); array.Write(verifyingOutput); verifyingOutput.Completed().Should().BeTrue(); }
public async Task <T> ExecuteAsync <T>(Command <T> command) { var bulkWriteStream = new BulkWriteStream( stream, new MemoryStream() ); var output = new CompoundOutput( new VerifyingOutput(), new StreamOutput( bulkWriteStream ) ); var array = new PlainArray( command.Request(BulkStringFactory.Plain).ToList() ); array.Write(output); long number; using (var ticket = await cashier.AcquireTicketAsync().ConfigureAwait(false)) { await bulkWriteStream.FlushAsync().ConfigureAwait(false); number = ticket.Number; } while (true) { switch (TryAcquire(number)) { case AcquisitionResult.Acquired: var counter = responsesRead.Read(); do { var responses = await ReadResponsesAsync().ConfigureAwait(false); foreach (var item in responses) { var tcs = received.GetOrAdd(++counter, _ => new TaskCompletionSource <Input>()); tcs.SetResult(item); } } while (counter < number); activeResponseReaderNumber.Write(-1); received.TryRemove(number, out var tcs2); var result = await tcs2.Task.ConfigureAwait(false); //return command.Read(result); throw new NotImplementedException(); case AcquisitionResult.BusyByNext: var source = received.GetOrAdd(number, _ => new TaskCompletionSource <Input>()); var input = await source.Task.ConfigureAwait(false); received.TryRemove(number, out _); //return command.Read(input); throw new NotImplementedException(); case AcquisitionResult.BusyByPrevious: // todo wait break; default: throw new ArgumentOutOfRangeException(); } } }