Skip to content

Commit

Permalink
Shutdown ManagedChannel resources in tests (#5114)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg committed Jan 12, 2023
1 parent f3b1f4a commit 727850e
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
Expand Down Expand Up @@ -43,11 +44,11 @@ void testSetRetryPolicyOnDelegate() {
@Test
@SuppressWarnings("deprecation") // testing deprecated feature
void usingGrpc() throws Exception {
try (Closeable exporter =
OtlpGrpcMetricExporter.builder()
.setChannel(InProcessChannelBuilder.forName("test").build())
.build()) {
ManagedChannel channel = InProcessChannelBuilder.forName("test").build();
try (Closeable exporter = OtlpGrpcMetricExporter.builder().setChannel(channel).build()) {
assertThat(exporter).extracting("delegate").isInstanceOf(UpstreamGrpcExporter.class);
} finally {
channel.shutdownNow();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
Expand Down Expand Up @@ -43,11 +44,11 @@ void testSetRetryPolicyOnDelegate() {
@Test
@SuppressWarnings("deprecation") // testing deprecated feature
void usingGrpc() throws Exception {
try (Closeable exporter =
OtlpGrpcSpanExporter.builder()
.setChannel(InProcessChannelBuilder.forName("test").build())
.build()) {
ManagedChannel channel = InProcessChannelBuilder.forName("test").build();
try (Closeable exporter = OtlpGrpcSpanExporter.builder().setChannel(channel).build()) {
assertThat(exporter).extracting("delegate").isInstanceOf(UpstreamGrpcExporter.class);
} finally {
channel.shutdownNow();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
Expand All @@ -31,11 +32,11 @@ class OtlpGrpcNettyShadedMetricExporterTest
@Test
@SuppressWarnings("deprecation") // testing deprecated feature
void usingGrpc() throws Exception {
try (Closeable exporter =
OtlpGrpcMetricExporter.builder()
.setChannel(InProcessChannelBuilder.forName("test").build())
.build()) {
ManagedChannel channel = InProcessChannelBuilder.forName("test").build();
try (Closeable exporter = OtlpGrpcMetricExporter.builder().setChannel(channel).build()) {
assertThat(exporter).extracting("delegate").isInstanceOf(UpstreamGrpcExporter.class);
} finally {
channel.shutdownNow();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
Expand All @@ -31,11 +32,11 @@ class OtlpGrpcNettyShadedSpanExporterTest
@Test
@SuppressWarnings("deprecation") // testing deprecated feature
void usingGrpc() throws Exception {
try (Closeable exporter =
OtlpGrpcSpanExporter.builder()
.setChannel(InProcessChannelBuilder.forName("test").build())
.build()) {
ManagedChannel channel = InProcessChannelBuilder.forName("test").build();
try (Closeable exporter = OtlpGrpcSpanExporter.builder().setChannel(channel).build()) {
assertThat(exporter).extracting("delegate").isInstanceOf(UpstreamGrpcExporter.class);
} finally {
channel.shutdownNow();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
Expand All @@ -31,11 +32,11 @@ class OtlpGrpcOkHttpMetricExporterTest
@Test
@SuppressWarnings("deprecation") // testing deprecated featurea
void usingGrpc() throws Exception {
try (Closeable exporter =
OtlpGrpcMetricExporter.builder()
.setChannel(InProcessChannelBuilder.forName("test").build())
.build()) {
ManagedChannel channel = InProcessChannelBuilder.forName("test").build();
try (Closeable exporter = OtlpGrpcMetricExporter.builder().setChannel(channel).build()) {
assertThat(exporter).extracting("delegate").isInstanceOf(UpstreamGrpcExporter.class);
} finally {
channel.shutdownNow();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
Expand All @@ -31,11 +32,11 @@ class OtlpGrpcOkHttpSpanExporterTest
@Test
@SuppressWarnings("deprecation") // testing deprecated feature
void usingGrpc() throws Exception {
try (Closeable exporter =
OtlpGrpcSpanExporter.builder()
.setChannel(InProcessChannelBuilder.forName("test").build())
.build()) {
ManagedChannel channel = InProcessChannelBuilder.forName("test").build();
try (Closeable exporter = OtlpGrpcSpanExporter.builder().setChannel(channel).build()) {
assertThat(exporter).extracting("delegate").isInstanceOf(UpstreamGrpcExporter.class);
} finally {
channel.shutdownNow();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
Expand Down Expand Up @@ -43,11 +44,11 @@ void testSetRetryPolicyOnDelegate() {
@Test
@SuppressWarnings("deprecation") // testing deprecated feature
void usingGrpc() throws Exception {
try (Closeable exporter =
OtlpGrpcLogRecordExporter.builder()
.setChannel(InProcessChannelBuilder.forName("test").build())
.build()) {
ManagedChannel channel = InProcessChannelBuilder.forName("test").build();
try (Closeable exporter = OtlpGrpcLogRecordExporter.builder().setChannel(channel).build()) {
assertThat(exporter).extracting("delegate").isInstanceOf(UpstreamGrpcExporter.class);
} finally {
channel.shutdownNow();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
Expand All @@ -31,11 +32,11 @@ class OtlpGrpcNettyShadedLogRecordExporterTest
@Test
@SuppressWarnings("deprecation") // testing deprecated feature
void usingGrpc() throws Exception {
try (Closeable exporter =
OtlpGrpcLogRecordExporter.builder()
.setChannel(InProcessChannelBuilder.forName("test").build())
.build()) {
ManagedChannel channel = InProcessChannelBuilder.forName("test").build();
try (Closeable exporter = OtlpGrpcLogRecordExporter.builder().setChannel(channel).build()) {
assertThat(exporter).extracting("delegate").isInstanceOf(UpstreamGrpcExporter.class);
} finally {
channel.shutdownNow();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.opentelemetry.exporter.internal.grpc.UpstreamGrpcExporter;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
Expand All @@ -31,11 +32,11 @@ class OtlpGrpcNettyOkHttpLogRecordExporterTest
@Test
@SuppressWarnings("deprecation") // testing deprecated feature
void usingGrpc() throws Exception {
try (Closeable exporter =
OtlpGrpcLogRecordExporter.builder()
.setChannel(InProcessChannelBuilder.forName("test").build())
.build()) {
ManagedChannel channel = InProcessChannelBuilder.forName("test").build();
try (Closeable exporter = OtlpGrpcLogRecordExporter.builder().setChannel(channel).build()) {
assertThat(exporter).extracting("delegate").isInstanceOf(UpstreamGrpcExporter.class);
} finally {
channel.shutdownNow();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,30 @@ void multipleItems() {
void compressionWithNone() {
TelemetryExporter<T> exporter =
exporterBuilder().setEndpoint(server.httpUri().toString()).setCompression("none").build();
// UpstreamGrpcExporter doesn't support compression, so we skip the assertion
assumeThat(exporter.unwrap())
.extracting("delegate")
.isNotInstanceOf(UpstreamGrpcExporter.class);
assertThat(exporter.unwrap()).extracting("delegate.compressionEnabled").isEqualTo(false);
try {
// UpstreamGrpcExporter doesn't support compression, so we skip the assertion
assumeThat(exporter.unwrap())
.extracting("delegate")
.isNotInstanceOf(UpstreamGrpcExporter.class);
assertThat(exporter.unwrap()).extracting("delegate.compressionEnabled").isEqualTo(false);
} finally {
exporter.shutdown();
}
}

@Test
void compressionWithGzip() {
TelemetryExporter<T> exporter =
exporterBuilder().setEndpoint(server.httpUri().toString()).setCompression("gzip").build();
// UpstreamGrpcExporter doesn't support compression, so we skip the assertion
assumeThat(exporter.unwrap())
.extracting("delegate")
.isNotInstanceOf(UpstreamGrpcExporter.class);
assertThat(exporter.unwrap()).extracting("delegate.compressionEnabled").isEqualTo(true);
try {
// UpstreamGrpcExporter doesn't support compression, so we skip the assertion
assumeThat(exporter.unwrap())
.extracting("delegate")
.isNotInstanceOf(UpstreamGrpcExporter.class);
assertThat(exporter.unwrap()).extracting("delegate.compressionEnabled").isEqualTo(true);
} finally {
exporter.shutdown();
}
}

@Test
Expand Down

0 comments on commit 727850e

Please sign in to comment.