Skip to content

Commit e44adfe

Browse files
committed
polish: adding tests.
1 parent 37ac611 commit e44adfe

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporterTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,36 @@ void log() throws Exception {
4545
assertThat(message).doesNotContain("\n");
4646
}
4747

48+
@Test
49+
void logWithWrapperJsonObjectFalse() throws Exception {
50+
// Test that wrapperJsonObject=false produces the same output as the default create()
51+
LogRecordExporter exporterWithoutWrapper = OtlpJsonLoggingLogRecordExporter.create(false);
52+
testDataExporter.export(exporterWithoutWrapper);
53+
54+
assertThat(logs.getEvents())
55+
.hasSize(1)
56+
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
57+
String message = logs.getEvents().get(0).getMessage();
58+
String expectedJson = testDataExporter.getExpectedJson(false);
59+
JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false);
60+
assertThat(message).doesNotContain("\n");
61+
}
62+
63+
@Test
64+
void logWithWrapperJsonObjectTrue() throws Exception {
65+
// Test that wrapperJsonObject=true produces wrapper format (enables low allocation)
66+
LogRecordExporter exporterWithWrapper = OtlpJsonLoggingLogRecordExporter.create(true);
67+
testDataExporter.export(exporterWithWrapper);
68+
69+
assertThat(logs.getEvents())
70+
.hasSize(1)
71+
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
72+
String message = logs.getEvents().get(0).getMessage();
73+
String expectedJson = testDataExporter.getExpectedJson(true);
74+
JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false);
75+
assertThat(message).doesNotContain("\n");
76+
}
77+
4878
@Test
4979
void shutdown() {
5080
assertThat(exporter.shutdown().isSuccess()).isTrue();

exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporterTest.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ void getAggregationTemporality() {
4747
.isEqualTo(AggregationTemporality.DELTA);
4848
}
4949

50+
@Test
51+
void getAggregationTemporalityWithWrapperJsonObject() {
52+
// Test that the new create method with wrapperJsonObject parameter maintains correct aggregation temporality
53+
assertThat(
54+
OtlpJsonLoggingMetricExporter.create(AggregationTemporality.CUMULATIVE, false)
55+
.getAggregationTemporality(InstrumentType.COUNTER))
56+
.isEqualTo(AggregationTemporality.CUMULATIVE);
57+
assertThat(
58+
OtlpJsonLoggingMetricExporter.create(AggregationTemporality.DELTA, false)
59+
.getAggregationTemporality(InstrumentType.COUNTER))
60+
.isEqualTo(AggregationTemporality.DELTA);
61+
assertThat(
62+
OtlpJsonLoggingMetricExporter.create(AggregationTemporality.CUMULATIVE, true)
63+
.getAggregationTemporality(InstrumentType.COUNTER))
64+
.isEqualTo(AggregationTemporality.CUMULATIVE);
65+
assertThat(
66+
OtlpJsonLoggingMetricExporter.create(AggregationTemporality.DELTA, true)
67+
.getAggregationTemporality(InstrumentType.COUNTER))
68+
.isEqualTo(AggregationTemporality.DELTA);
69+
}
70+
5071
@Test
5172
void log() throws Exception {
5273
testDataExporter.export(exporter);
@@ -60,6 +81,51 @@ void log() throws Exception {
6081
assertThat(message).doesNotContain("\n");
6182
}
6283

84+
@Test
85+
void logWithWrapperJsonObjectFalse() throws Exception {
86+
// Test that wrapperJsonObject=false produces the same output as the default create()
87+
MetricExporter exporterWithoutWrapper = OtlpJsonLoggingMetricExporter.create(AggregationTemporality.CUMULATIVE, false);
88+
testDataExporter.export(exporterWithoutWrapper);
89+
90+
assertThat(logs.getEvents())
91+
.hasSize(1)
92+
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
93+
String message = logs.getEvents().get(0).getMessage();
94+
String expectedJson = testDataExporter.getExpectedJson(false);
95+
JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false);
96+
assertThat(message).doesNotContain("\n");
97+
}
98+
99+
@Test
100+
void logWithWrapperJsonObjectTrue() throws Exception {
101+
// Test that wrapperJsonObject=true produces wrapper format (enables low allocation)
102+
MetricExporter exporterWithWrapper = OtlpJsonLoggingMetricExporter.create(AggregationTemporality.CUMULATIVE, true);
103+
testDataExporter.export(exporterWithWrapper);
104+
105+
assertThat(logs.getEvents())
106+
.hasSize(1)
107+
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
108+
String message = logs.getEvents().get(0).getMessage();
109+
String expectedJson = testDataExporter.getExpectedJson(true);
110+
JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false);
111+
assertThat(message).doesNotContain("\n");
112+
}
113+
114+
@Test
115+
void logWithWrapperJsonObjectTrueAndDeltaTemporality() throws Exception {
116+
// Test that wrapperJsonObject=true works with DELTA temporality too
117+
MetricExporter exporterWithWrapper = OtlpJsonLoggingMetricExporter.create(AggregationTemporality.DELTA, true);
118+
testDataExporter.export(exporterWithWrapper);
119+
120+
assertThat(logs.getEvents())
121+
.hasSize(1)
122+
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
123+
String message = logs.getEvents().get(0).getMessage();
124+
String expectedJson = testDataExporter.getExpectedJson(true);
125+
JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false);
126+
assertThat(message).doesNotContain("\n");
127+
}
128+
63129
@Test
64130
void flush() {
65131
assertThat(exporter.flush().isSuccess()).isTrue();

exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporterTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,36 @@ void log() throws Exception {
4646
assertThat(message).doesNotContain("\n");
4747
}
4848

49+
@Test
50+
void logWithWrapperJsonObjectFalse() throws Exception {
51+
// Test that wrapperJsonObject=false produces the same output as the default create()
52+
SpanExporter exporterWithoutWrapper = OtlpJsonLoggingSpanExporter.create(false);
53+
testDataExporter.export(exporterWithoutWrapper);
54+
55+
assertThat(logs.getEvents())
56+
.hasSize(1)
57+
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
58+
String message = logs.getEvents().get(0).getMessage();
59+
String expectedJson = testDataExporter.getExpectedJson(false);
60+
JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false);
61+
assertThat(message).doesNotContain("\n");
62+
}
63+
64+
@Test
65+
void logWithWrapperJsonObjectTrue() throws Exception {
66+
// Test that wrapperJsonObject=true produces wrapper format (enables low allocation)
67+
SpanExporter exporterWithWrapper = OtlpJsonLoggingSpanExporter.create(true);
68+
testDataExporter.export(exporterWithWrapper);
69+
70+
assertThat(logs.getEvents())
71+
.hasSize(1)
72+
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
73+
String message = logs.getEvents().get(0).getMessage();
74+
String expectedJson = testDataExporter.getExpectedJson(true);
75+
JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false);
76+
assertThat(message).doesNotContain("\n");
77+
}
78+
4979
@Test
5080
void flush() {
5181
assertThat(exporter.flush().isSuccess()).isTrue();

0 commit comments

Comments
 (0)