From 852c06f68c59db3fadabe9fc2ce01dd659d240c9 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Mon, 10 Aug 2020 22:30:52 -0700 Subject: [PATCH] remove unused files (#1041) --- .../Trace/ActivityProcessorPipelineBuilder.cs | 126 --------- .../Config/ActivityProcessorPipelineTests.cs | 239 ------------------ 2 files changed, 365 deletions(-) delete mode 100644 src/OpenTelemetry/Trace/ActivityProcessorPipelineBuilder.cs delete mode 100644 test/OpenTelemetry.Tests/Implementation/Trace/Config/ActivityProcessorPipelineTests.cs diff --git a/src/OpenTelemetry/Trace/ActivityProcessorPipelineBuilder.cs b/src/OpenTelemetry/Trace/ActivityProcessorPipelineBuilder.cs deleted file mode 100644 index b6943f03f95..00000000000 --- a/src/OpenTelemetry/Trace/ActivityProcessorPipelineBuilder.cs +++ /dev/null @@ -1,126 +0,0 @@ -// -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -using System; -using System.Collections.Generic; -using OpenTelemetry.Trace.Internal; - -namespace OpenTelemetry.Trace -{ - /// - /// Configures exporting pipeline with chains of processors and exporter. - /// - public class ActivityProcessorPipelineBuilder - { - private Func lastProcessorFactory; - private List> processorChain; - - internal ActivityProcessorPipelineBuilder() - { - } - - internal ActivityExporter Exporter { get; private set; } - - internal List Processors { get; private set; } - - /// - /// Adds chained processor to the pipeline. Processors are executed in the order they were added. - /// - /// Function that creates processor from the next one. - /// Returns . - public ActivityProcessorPipelineBuilder AddProcessor(Func processorFactory) - { - if (processorFactory == null) - { - throw new ArgumentNullException(nameof(processorFactory)); - } - - if (this.processorChain == null) - { - this.processorChain = new List>(); - } - - this.processorChain.Add(processorFactory); - - return this; - } - - /// - /// Configures last processor that invokes exporter. When not set, is used. - /// - /// Factory that creates exporting processor from the exporter. - /// Returns . - public ActivityProcessorPipelineBuilder SetExportingProcessor(Func processorFactory) - { - this.lastProcessorFactory = processorFactory ?? throw new ArgumentNullException(nameof(processorFactory)); - return this; - } - - /// - /// Configures exporter. - /// - /// Exporter instance. - /// Returns . - public ActivityProcessorPipelineBuilder SetExporter(ActivityExporter exporter) - { - this.Exporter = exporter ?? throw new ArgumentNullException(nameof(exporter)); - return this; - } - - internal ActivityProcessor Build() - { - this.Processors = new List(); - - ActivityProcessor exportingProcessor = null; - - // build or create default exporting processor - if (this.lastProcessorFactory != null) - { - exportingProcessor = this.lastProcessorFactory.Invoke(this.Exporter); - this.Processors.Add(exportingProcessor); - } - else if (this.Exporter != null) - { - exportingProcessor = new BatchingActivityProcessor(this.Exporter); - this.Processors.Add(exportingProcessor); - } - - if (this.processorChain == null) - { - // if there is no chain, return exporting processor. - if (exportingProcessor == null) - { - exportingProcessor = new NoopActivityProcessor(); - this.Processors.Add(exportingProcessor); - } - - return exportingProcessor; - } - - var next = exportingProcessor; - - // build chain from the end to the beginning - for (int i = this.processorChain.Count - 1; i >= 0; i--) - { - next = this.processorChain[i].Invoke(next); - this.Processors.Add(next); - } - - // return the last processor in the chain - it will be called first - return this.Processors[this.Processors.Count - 1]; - } - } -} diff --git a/test/OpenTelemetry.Tests/Implementation/Trace/Config/ActivityProcessorPipelineTests.cs b/test/OpenTelemetry.Tests/Implementation/Trace/Config/ActivityProcessorPipelineTests.cs deleted file mode 100644 index 2ade8097d07..00000000000 --- a/test/OpenTelemetry.Tests/Implementation/Trace/Config/ActivityProcessorPipelineTests.cs +++ /dev/null @@ -1,239 +0,0 @@ -// -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -using System; -using System.Linq; -using OpenTelemetry.Testing.Export; -using OpenTelemetry.Trace; -using OpenTelemetry.Trace.Internal; -using Xunit; - -namespace OpenTelemetry.Tests.Impl.Trace.Config -{ - public class ActivityProcessorPipelineTests - { - [Fact] - public void PipelineBuilder_BadArgs() - { - Assert.Throws(() => new ActivityProcessorPipelineBuilder().AddProcessor(null)); - Assert.Throws(() => new ActivityProcessorPipelineBuilder().SetExporter(null)); - Assert.Throws(() => new ActivityProcessorPipelineBuilder().SetExportingProcessor(null)); - } - - [Fact] - public void PipelineBuilder_Defaults() - { - var builder = new ActivityProcessorPipelineBuilder(); - Assert.Null(builder.Exporter); - Assert.Null(builder.Processors); - - var processor = builder.Build(); - - Assert.Null(builder.Exporter); - Assert.Single(builder.Processors); - Assert.IsType(builder.Processors[0]); - Assert.Same(processor, builder.Processors[0]); - } - - [Fact] - public void PipelineBuilder_AddExporter() - { - var builder = new ActivityProcessorPipelineBuilder(); - - var exporter = new TestActivityExporter(null); - builder.SetExporter(exporter); - - Assert.Same(exporter, builder.Exporter); - - var processor = builder.Build(); - - Assert.Single(builder.Processors); - Assert.IsType(builder.Processors.Single()); - Assert.Same(processor, builder.Processors[0]); - } - - [Fact] - public void PipelineBuilder_AddExporterAndExportingProcessor() - { - var builder = new ActivityProcessorPipelineBuilder(); - - var exporter = new TestActivityExporter(null); - builder.SetExporter(exporter); - - bool processorFactoryCalled = false; - builder.SetExportingProcessor(e => - { - processorFactoryCalled = true; - return new SimpleActivityProcessor(e); - }); - - var processor = builder.Build(); - - Assert.Single(builder.Processors); - Assert.True(processorFactoryCalled); - Assert.IsType(builder.Processors.Single()); - Assert.Same(processor, builder.Processors[0]); - } - - [Fact] - public void PipelineBuilder_AddExportingProcessor() - { - var builder = new ActivityProcessorPipelineBuilder(); - - bool processorFactoryCalled = false; - var processor = new TestProcessor(); - builder.SetExportingProcessor(e => - { - processorFactoryCalled = true; - Assert.Null(e); - return processor; - }); - - Assert.Same(processor, builder.Build()); - - Assert.Single(builder.Processors); - Assert.True(processorFactoryCalled); - Assert.Same(processor, builder.Processors.Single()); - } - - [Fact] - public void PipelineBuilder_AddProcessor() - { - var builder = new ActivityProcessorPipelineBuilder(); - - bool processorFactoryCalled = false; - var processor = new TestProcessor(); - builder.AddProcessor(e => - { - processorFactoryCalled = true; - return processor; - }); - - Assert.Same(processor, builder.Build()); - - Assert.Single(builder.Processors); - Assert.True(processorFactoryCalled); - Assert.Same(processor, builder.Processors.Single()); - } - - [Fact] - public void PipelineBuilder_AddProcessorChain() - { - var builder = new ActivityProcessorPipelineBuilder(); - - bool processorFactory1Called = false; - bool processorFactory2Called = false; - bool processorFactory3Called = false; - - builder - .AddProcessor(next => - { - processorFactory1Called = true; - Assert.NotNull(next); - return new TestProcessor(next, "1"); - }) - .AddProcessor(next => - { - processorFactory2Called = true; - Assert.NotNull(next); - return new TestProcessor(next, "2"); - }) - .AddProcessor(next => - { - processorFactory3Called = true; - Assert.Null(next); - return new TestProcessor(next, "3"); - }); - - var firstProcessor = (TestProcessor)builder.Build(); - - Assert.Equal(3, builder.Processors.Count); - Assert.True(processorFactory1Called); - Assert.True(processorFactory2Called); - Assert.True(processorFactory3Called); - - Assert.Equal("1", firstProcessor.Name); - - var secondProcessor = (TestProcessor)firstProcessor.Next; - Assert.Equal("2", secondProcessor.Name); - var thirdProcessor = (TestProcessor)secondProcessor.Next; - Assert.Equal("3", thirdProcessor.Name); - } - - [Fact] - public void PipelineBuilder_AddProcessorChainWithExporter() - { - var builder = new ActivityProcessorPipelineBuilder(); - - bool processorFactory1Called = false; - bool processorFactory2Called = false; - bool exportingFactory3Called = false; - - builder - .AddProcessor(next => - { - processorFactory1Called = true; - Assert.NotNull(next); - return new TestProcessor(next, "1"); - }) - .AddProcessor(next => - { - processorFactory2Called = true; - Assert.NotNull(next); - return new TestProcessor(next, "2"); - }) - .SetExportingProcessor(exporter => - { - exportingFactory3Called = true; - Assert.NotNull(exporter); - return new SimpleActivityProcessor(exporter); - }) - .SetExporter(new TestActivityExporter(null)); - - var firstProcessor = (TestProcessor)builder.Build(); - - Assert.Equal(3, builder.Processors.Count); - Assert.True(processorFactory1Called); - Assert.True(processorFactory2Called); - Assert.True(exportingFactory3Called); - - Assert.Equal("1", firstProcessor.Name); - - var secondProcessor = (TestProcessor)firstProcessor.Next; - Assert.Equal("2", secondProcessor.Name); - var thirdProcessor = secondProcessor.Next; - Assert.IsType(thirdProcessor); - } - - private class TestProcessor : ActivityProcessor - { - public readonly ActivityProcessor Next; - public readonly string Name; - - public TestProcessor() - { - this.Name = null; - this.Name = null; - } - - public TestProcessor(ActivityProcessor next, string name) - { - this.Next = next; - this.Name = name; - } - } - } -}