-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gagan Juneja <gjjuneja@amazon.com>
- Loading branch information
Gagan Juneja
committed
Aug 11, 2023
1 parent
407079a
commit 707ac18
Showing
3 changed files
with
52 additions
and
5 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
48 changes: 48 additions & 0 deletions
48
...try-otel/src/test/java/org/opensearch/telemetry/tracing/OTelAttributesConverterTests.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,48 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.telemetry.tracing; | ||
|
||
import io.opentelemetry.api.common.AttributeType; | ||
import io.opentelemetry.api.internal.InternalAttributeKeyImpl; | ||
import java.util.Map; | ||
import org.opensearch.telemetry.tracing.attributes.Attributes; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class OTelAttributesConverterTests extends OpenSearchTestCase { | ||
|
||
private final OTelAttributesConverter converter = new OTelAttributesConverter(); | ||
|
||
public void testConverterNullAttributes() { | ||
io.opentelemetry.api.common.Attributes otelAttributes = converter.convert(null); | ||
assertEquals(0, otelAttributes.size()); | ||
} | ||
|
||
public void testConverterEmptyAttributes() { | ||
Attributes attributes = Attributes.EMPTY; | ||
io.opentelemetry.api.common.Attributes otelAttributes = converter.convert(null); | ||
assertEquals(0, otelAttributes.size()); | ||
} | ||
|
||
public void testConverterSingleAttributes() { | ||
Attributes attributes = Attributes.create().addAttribute("key1", "value"); | ||
io.opentelemetry.api.common.Attributes otelAttributes = converter.convert(attributes); | ||
assertEquals(1, otelAttributes.size()); | ||
assertEquals("value", otelAttributes.get(InternalAttributeKeyImpl.create("key1", AttributeType.STRING))); | ||
} | ||
|
||
public void testConverterMultipleAttributes() { | ||
Attributes attributes = Attributes.create().addAttribute("key1", 1l).addAttribute("key2", 1.0).addAttribute("key3", true).addAttribute("key4", "value4"); | ||
Map<String, ?> attributeMap = attributes.getAttributesMap(); | ||
io.opentelemetry.api.common.Attributes otelAttributes = converter.convert(attributes); | ||
assertEquals(4, otelAttributes.size()); | ||
otelAttributes.asMap().forEach( | ||
(x,y) -> assertEquals(attributeMap.get(x.getKey()), y) | ||
); | ||
} | ||
} |