public async void AppendAsync_ShouldFlushWhenItReachesTheBatchSize() { var span = Substitute.For <IJaegerCoreSpan>(); var tracer = Substitute.For <IJaegerCoreTracer>(); span.Tracer.Returns(tracer); var cts = new CancellationTokenSource(); var jProcess = Substitute.For <JaegerProcess>(); _mockJaegerThriftSerialization.BuildJaegerProcessThrift(Arg.Is(tracer)).Returns(jProcess); var jSpan = Substitute.For <JaegerSpan>(); _mockJaegerThriftSerialization.BuildJaegerThriftSpan(Arg.Is(span)).Returns(jSpan); _mockSender.BufferItem(Arg.Is(jSpan)).Returns(_batchSize); _mockSender.FlushAsync(Arg.Any <JaegerProcess>(), Arg.Any <CancellationToken>()).Returns(_batchSize); var sent = await _testingTransport.AppendAsync(span, cts.Token); Assert.Equal(_batchSize, sent); _mockJaegerThriftSerialization.Received(1).BuildJaegerProcessThrift(Arg.Is(tracer)); _mockJaegerThriftSerialization.Received(1).BuildJaegerThriftSpan(Arg.Is(span)); _mockSender.Received(1).BufferItem(Arg.Is(jSpan)); await _mockSender.Received(1).FlushAsync(Arg.Any <JaegerProcess>(), Arg.Any <CancellationToken>()); }
public async void AppendAsync_ShouldCallSerializationAndProtocolAppendLogicAsync() { var span = Substitute.For <IJaegerCoreSpan>(); var tracer = Substitute.For <IJaegerCoreTracer>(); span.Tracer.Returns(tracer); var cts = new CancellationTokenSource(); var jProcess = Substitute.For <JaegerProcess>(); _mockJaegerThriftSerialization.BuildJaegerProcessThrift(Arg.Is(tracer)).Returns(jProcess); var jSpan = Substitute.For <JaegerSpan>(); _mockJaegerThriftSerialization.BuildJaegerThriftSpan(Arg.Is(span)).Returns(jSpan); //_mockSender.BufferItem(Arg.Is(jSpan)).Returns(2); _testingTransport.ProtocolAppendLogicAsync(Arg.Is(jSpan), Arg.Any <CancellationToken>()).Returns(2); var sent = await _testingTransport.AppendAsync(span, cts.Token); Assert.Equal(2, sent); _mockJaegerThriftSerialization.Received(1).BuildJaegerProcessThrift(Arg.Is(tracer)); _mockJaegerThriftSerialization.Received(1).BuildJaegerThriftSpan(Arg.Is(span)); //_mockSender.Received(1).BufferItem(Arg.Is(jSpan)); await _testingTransport.Received(1).ProtocolAppendLogicAsync(Arg.Is(jSpan), Arg.Any <CancellationToken>()); await _mockSender.Received(0).FlushAsync(Arg.Any <JaegerProcess>(), Arg.Any <CancellationToken>()); }