Skip to content

Commit

Permalink
fix(remove-testExporter): replaced TestExporter with InMemoryExporter (
Browse files Browse the repository at this point in the history
…open-telemetry#497)

* fix(remove-testexporter): replaced TestExporter with InMemoryExporter
  • Loading branch information
samimusallam authored Jul 11, 2022
1 parent c8af3e9 commit 230895b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPkgVer)" />
<PackageReference Include="Moq" Version="$(MoqPkgVer)" />
<PackageReference Include="OpenTelemetry.Exporter.InMemory" Version="$(OpenTelemetryApiPkgVer)" />
<PackageReference Include="xunit" Version="$(XUnitPkgVer)" />
<PackageReference Condition="$([MSBuild]::IsOsPlatform('Windows'))" Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioPkgVer)">
<PrivateAssets>all</PrivateAssets>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
using Google.Cloud.Trace.V2;
using Grpc.Core;
using Moq;
using OpenTelemetry.Contrib.Exporter.Stackdriver.Tests.Shared;
using OpenTelemetry.Exporter;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

Expand Down Expand Up @@ -94,6 +94,7 @@ public void StackdriverExporter_TraceClientThrows_ExportResultFailure()
{
Exception exception = null;
ExportResult result = ExportResult.Success;
var exportedItems = new List<Activity>();
const string ActivitySourceName = "stackdriver.test";
var source = new ActivitySource(ActivitySourceName);
var traceClientMock = new Mock<TraceServiceClient>(MockBehavior.Strict);
Expand All @@ -102,9 +103,8 @@ public void StackdriverExporter_TraceClientThrows_ExportResultFailure()
.Throws(new RpcException(Status.DefaultCancelled))
.Verifiable($"{nameof(TraceServiceClient.BatchWriteSpans)} was never called");
var activityExporter = new StackdriverTraceExporter("test", traceClientMock.Object);
var testExporter = new TestExporter<Activity>(RunTest);

var processor = new BatchActivityExportProcessor(testExporter);
var processor = new BatchActivityExportProcessor(new InMemoryExporter<Activity>(exportedItems));

for (int i = 0; i < 10; i++)
{
Expand All @@ -114,6 +114,9 @@ public void StackdriverExporter_TraceClientThrows_ExportResultFailure()

processor.Shutdown();

var batch = new Batch<Activity>(exportedItems.ToArray(), exportedItems.Count);
RunTest(batch);

void RunTest(Batch<Activity> batch)
{
exception = Record.Exception(() =>
Expand All @@ -132,16 +135,16 @@ public void StackdriverExporter_TraceClientDoesNotTrow_ExportResultSuccess()
{
Exception exception = null;
ExportResult result = ExportResult.Failure;
var exportedItems = new List<Activity>();
const string ActivitySourceName = "stackdriver.test";
var source = new ActivitySource(ActivitySourceName);
var traceClientMock = new Mock<TraceServiceClient>(MockBehavior.Strict);
traceClientMock.Setup(x =>
x.BatchWriteSpans(It.IsAny<BatchWriteSpansRequest>(), It.IsAny<CallSettings>()))
.Verifiable($"{nameof(TraceServiceClient.BatchWriteSpans)} was never called");
var activityExporter = new StackdriverTraceExporter("test", traceClientMock.Object);
var testExporter = new TestExporter<Activity>(RunTest);

var processor = new BatchActivityExportProcessor(testExporter);
var processor = new BatchActivityExportProcessor(new InMemoryExporter<Activity>(exportedItems));

for (int i = 0; i < 10; i++)
{
Expand All @@ -151,6 +154,9 @@ public void StackdriverExporter_TraceClientDoesNotTrow_ExportResultSuccess()

processor.Shutdown();

var batch = new Batch<Activity>(exportedItems.ToArray(), exportedItems.Count);
RunTest(batch);

void RunTest(Batch<Activity> batch)
{
exception = Record.Exception(() =>
Expand Down

0 comments on commit 230895b

Please sign in to comment.