-
Notifications
You must be signed in to change notification settings - Fork 864
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract gRPC exporter test into shared base class. (#3903)
* Extract gRPC exporter test into shared base class. * Split out config test
- Loading branch information
Showing
17 changed files
with
803 additions
and
1,170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
exporters/otlp/logs/src/test/java/io/opentelemetry/exporter/otlp/logs/ConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.otlp.logs; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import io.opentelemetry.exporter.otlp.internal.grpc.OkHttpGrpcExporterBuilder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.time.Duration; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ConfigTest { | ||
|
||
@Test | ||
@SuppressWarnings("PreferJavaTimeOverload") | ||
void validConfig() { | ||
assertThatCode(() -> OtlpGrpcLogExporter.builder().setTimeout(0, TimeUnit.MILLISECONDS)) | ||
.doesNotThrowAnyException(); | ||
assertThatCode(() -> OtlpGrpcLogExporter.builder().setTimeout(Duration.ofMillis(0))) | ||
.doesNotThrowAnyException(); | ||
assertThatCode(() -> OtlpGrpcLogExporter.builder().setTimeout(10, TimeUnit.MILLISECONDS)) | ||
.doesNotThrowAnyException(); | ||
assertThatCode(() -> OtlpGrpcLogExporter.builder().setTimeout(Duration.ofMillis(10))) | ||
.doesNotThrowAnyException(); | ||
|
||
assertThatCode(() -> OtlpGrpcLogExporter.builder().setEndpoint("http://localhost:4317")) | ||
.doesNotThrowAnyException(); | ||
assertThatCode(() -> OtlpGrpcLogExporter.builder().setEndpoint("http://localhost")) | ||
.doesNotThrowAnyException(); | ||
assertThatCode(() -> OtlpGrpcLogExporter.builder().setEndpoint("https://localhost")) | ||
.doesNotThrowAnyException(); | ||
assertThatCode(() -> OtlpGrpcLogExporter.builder().setEndpoint("http://foo:bar@localhost")) | ||
.doesNotThrowAnyException(); | ||
|
||
assertThatCode(() -> OtlpGrpcLogExporter.builder().setCompression("gzip")) | ||
.doesNotThrowAnyException(); | ||
assertThatCode(() -> OtlpGrpcLogExporter.builder().setCompression("none")) | ||
.doesNotThrowAnyException(); | ||
|
||
assertThatCode( | ||
() -> OtlpGrpcLogExporter.builder().addHeader("foo", "bar").addHeader("baz", "qux")) | ||
.doesNotThrowAnyException(); | ||
|
||
assertThatCode( | ||
() -> | ||
OtlpGrpcLogExporter.builder() | ||
.setTrustedCertificates("foobar".getBytes(StandardCharsets.UTF_8))) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
@SuppressWarnings("PreferJavaTimeOverload") | ||
void invalidConfig() { | ||
assertThatThrownBy(() -> OtlpGrpcLogExporter.builder().setTimeout(-1, TimeUnit.MILLISECONDS)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("timeout must be non-negative"); | ||
assertThatThrownBy(() -> OtlpGrpcLogExporter.builder().setTimeout(1, null)) | ||
.isInstanceOf(NullPointerException.class) | ||
.hasMessage("unit"); | ||
assertThatThrownBy(() -> OtlpGrpcLogExporter.builder().setTimeout(null)) | ||
.isInstanceOf(NullPointerException.class) | ||
.hasMessage("timeout"); | ||
|
||
assertThatThrownBy(() -> OtlpGrpcLogExporter.builder().setEndpoint(null)) | ||
.isInstanceOf(NullPointerException.class) | ||
.hasMessage("endpoint"); | ||
assertThatThrownBy(() -> OtlpGrpcLogExporter.builder().setEndpoint("😺://localhost")) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Invalid endpoint, must be a URL: 😺://localhost"); | ||
assertThatThrownBy(() -> OtlpGrpcLogExporter.builder().setEndpoint("localhost")) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Invalid endpoint, must start with http:// or https://: localhost"); | ||
assertThatThrownBy(() -> OtlpGrpcLogExporter.builder().setEndpoint("gopher://localhost")) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Invalid endpoint, must start with http:// or https://: gopher://localhost"); | ||
|
||
assertThatThrownBy(() -> OtlpGrpcLogExporter.builder().setCompression(null)) | ||
.isInstanceOf(NullPointerException.class) | ||
.hasMessage("compressionMethod"); | ||
assertThatThrownBy(() -> OtlpGrpcLogExporter.builder().setCompression("foo")) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage( | ||
"Unsupported compression method. Supported compression methods include: gzip, none."); | ||
} | ||
|
||
@Test | ||
void usingOkHttp() { | ||
assertThat(OtlpGrpcLogExporter.builder().delegate) | ||
.isInstanceOf(OkHttpGrpcExporterBuilder.class); | ||
} | ||
} |
Oops, something went wrong.