|
9 | 9 | import static org.assertj.core.api.Assertions.assertThat; |
10 | 10 | import static org.assertj.core.api.Assertions.assertThatCode; |
11 | 11 |
|
| 12 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 13 | +import com.fasterxml.jackson.databind.ObjectMapper; |
12 | 14 | import io.opentelemetry.api.common.AttributeKey; |
13 | 15 | import io.opentelemetry.api.common.AttributeType; |
14 | 16 | import io.opentelemetry.api.common.Attributes; |
@@ -164,29 +166,41 @@ void labelValueSerialization_Primitives() { |
164 | 166 | } |
165 | 167 |
|
166 | 168 | @Test |
167 | | - void labelValueSerialization_NonPrimitives() { |
| 169 | + void labelValueSerialization_NonPrimitives() throws JsonProcessingException { |
| 170 | + List<String> stringArrayValue = |
| 171 | + Arrays.asList("stringValue1", "\"+\\\\\\+\b+\f+\n+\r+\t+" + (char) 0); |
| 172 | + List<Boolean> booleanArrayValue = Arrays.asList(true, false); |
| 173 | + List<Long> longArrayValue = Arrays.asList(Long.MIN_VALUE, Long.MAX_VALUE); |
| 174 | + List<Double> doubleArrayValue = Arrays.asList(Double.MIN_VALUE, Double.MAX_VALUE); |
168 | 175 | Attributes attributes = |
169 | 176 | Attributes.builder() |
170 | | - .put( |
171 | | - AttributeKey.stringArrayKey("stringKey"), |
172 | | - Arrays.asList("stringValue1", "\"+\\\\\\+\b+\f+\n+\r+\t+" + (char) 0)) |
173 | | - .put(AttributeKey.booleanArrayKey("booleanKey"), Arrays.asList(true, false)) |
174 | | - .put(AttributeKey.longArrayKey("longKey"), Arrays.asList(12345L, 6789L)) |
175 | | - .put(AttributeKey.doubleArrayKey("doubleKey"), Arrays.asList(0.12345, 0.6789)) |
| 177 | + .put(AttributeKey.stringArrayKey("stringKey"), stringArrayValue) |
| 178 | + .put(AttributeKey.booleanArrayKey("booleanKey"), booleanArrayValue) |
| 179 | + .put(AttributeKey.longArrayKey("longKey"), longArrayValue) |
| 180 | + .put(AttributeKey.doubleArrayKey("doubleKey"), doubleArrayValue) |
176 | 181 | .build(); |
177 | 182 | MetricData metricData = |
178 | 183 | createSampleMetricData("sample", "1", MetricDataType.LONG_SUM, attributes, null); |
179 | 184 |
|
180 | 185 | MetricSnapshots snapshots = converter.convert(Collections.singletonList(metricData)); |
181 | 186 |
|
182 | | - assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("stringKey")) |
183 | | - .isEqualTo("[\"stringValue1\", \"\\\"+\\\\\\\\\\\\+\\b+\\f+\\n+\\r+\\t+\\u0000\"]"); |
184 | | - assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("booleanKey")) |
185 | | - .isEqualTo("[true, false]"); |
186 | | - assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("longKey")) |
187 | | - .isEqualTo("[12345, 6789]"); |
188 | | - assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("doubleKey")) |
189 | | - .isEqualTo("[0.12345, 0.6789]"); |
| 187 | + ObjectMapper objectMapper = new ObjectMapper(); |
| 188 | + assertThat( |
| 189 | + objectMapper.readTree( |
| 190 | + snapshots.get(0).getDataPoints().get(0).getLabels().get("stringKey"))) |
| 191 | + .isEqualTo(objectMapper.valueToTree(stringArrayValue)); |
| 192 | + assertThat( |
| 193 | + objectMapper.readTree( |
| 194 | + snapshots.get(0).getDataPoints().get(0).getLabels().get("booleanKey"))) |
| 195 | + .isEqualTo(objectMapper.valueToTree(booleanArrayValue)); |
| 196 | + assertThat( |
| 197 | + objectMapper.readTree( |
| 198 | + snapshots.get(0).getDataPoints().get(0).getLabels().get("longKey"))) |
| 199 | + .isEqualTo(objectMapper.valueToTree(longArrayValue)); |
| 200 | + assertThat( |
| 201 | + objectMapper.readTree( |
| 202 | + snapshots.get(0).getDataPoints().get(0).getLabels().get("doubleKey"))) |
| 203 | + .isEqualTo(objectMapper.valueToTree(doubleArrayValue)); |
190 | 204 | } |
191 | 205 |
|
192 | 206 | @Test |
|
0 commit comments