Skip to content

Commit 7a7c426

Browse files
committed
Fix tests.
1 parent 5c126c9 commit 7a7c426

File tree

3 files changed

+44
-65
lines changed

3 files changed

+44
-65
lines changed

sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/entities/TestEntityProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ void defaults_includeServiceAndSdk() {
3333

3434
assertThat(EntityUtil.getEntities(provider.getResource()))
3535
.satisfiesExactlyInAnyOrder(
36-
e -> assertThat(e).hasType("service"), e -> assertThat(e).hasType("telemetry.sdk"));
36+
e -> assertThat(e.getType()).isEqualTo("service"),
37+
e -> assertThat(e.getType()).isEqualTo("telemetry.sdk"));
3738
}
3839

3940
@Test

sdk/common/src/main/java/io/opentelemetry/sdk/resources/internal/EntityUtil.java

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,8 @@ static Resource createResourceRaw(
6666
return (Resource) result;
6767
}
6868
}
69-
} catch (NoSuchMethodException nme) {
70-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", nme);
71-
} catch (IllegalAccessException iae) {
72-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", iae);
73-
} catch (InvocationTargetException ite) {
74-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", ite);
69+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
70+
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", e);
7571
}
7672
// Fall back to non-entity behavior?
7773
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource");
@@ -86,12 +82,8 @@ public static ResourceBuilder addEntity(ResourceBuilder rb, Entity e) {
8682
method.setAccessible(true);
8783
method.invoke(rb, e);
8884
}
89-
} catch (NoSuchMethodException nme) {
90-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", nme);
91-
} catch (IllegalAccessException iae) {
92-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", iae);
93-
} catch (InvocationTargetException ite) {
94-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", ite);
85+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
86+
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", ex);
9587
}
9688
return rb;
9789
}
@@ -104,12 +96,8 @@ public static ResourceBuilder addAllEntity(ResourceBuilder rb, Collection<Entity
10496
method.setAccessible(true);
10597
method.invoke(rb, e);
10698
}
107-
} catch (NoSuchMethodException nme) {
108-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", nme);
109-
} catch (IllegalAccessException iae) {
110-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", iae);
111-
} catch (InvocationTargetException ite) {
112-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", ite);
99+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
100+
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", ex);
113101
}
114102
return rb;
115103
}
@@ -127,12 +115,8 @@ public static Collection<Entity> getEntities(Resource r) {
127115
method.setAccessible(true);
128116
return (Collection<Entity>) method.invoke(r);
129117
}
130-
} catch (NoSuchMethodException nme) {
131-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", nme);
132-
} catch (IllegalAccessException iae) {
133-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", iae);
134-
} catch (InvocationTargetException ite) {
135-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", ite);
118+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
119+
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", e);
136120
}
137121
return Collections.emptyList();
138122
}
@@ -149,12 +133,8 @@ public static Attributes getRawAttributes(Resource r) {
149133
method.setAccessible(true);
150134
return (Attributes) method.invoke(r);
151135
}
152-
} catch (NoSuchMethodException nme) {
153-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", nme);
154-
} catch (IllegalAccessException iae) {
155-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", iae);
156-
} catch (InvocationTargetException ite) {
157-
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", ite);
136+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
137+
logger.log(Level.WARNING, "Attempting to use entities with unsupported resource", e);
158138
}
159139
return Attributes.empty();
160140
}

sdk/common/src/test/java/io/opentelemetry/sdk/resources/internal/EntityUtilTest.java

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ void testMerge_entities_same_types_and_id() {
3737
assertThat(merged).hasSize(1);
3838
assertThat(merged)
3939
.anySatisfy(
40-
entity ->
41-
assertThat(entity)
42-
.hasType("a")
43-
.hasSchemaUrl("one")
44-
.hasIdSatisfying(id -> assertThat(id).containsEntry("a.id", "a"))
45-
.hasDescriptionSatisfying(
46-
desc ->
47-
assertThat(desc)
48-
.containsEntry("a.desc1", "a")
49-
.containsEntry("a.desc2", "b")));
40+
entity -> {
41+
assertThat(entity.getType()).isEqualTo("a");
42+
assertThat(entity.getSchemaUrl()).isEqualTo("one");
43+
assertThat(entity.getId()).containsEntry("a.id", "a");
44+
assertThat(entity.getDescription())
45+
.containsEntry("a.desc1", "a")
46+
.containsEntry("a.desc2", "b");
47+
});
5048
}
5149

5250
@Test
@@ -69,17 +67,15 @@ void testMerge_entities_same_types_and_id_different_schema() {
6967
assertThat(merged).hasSize(1);
7068
assertThat(merged)
7169
.anySatisfy(
72-
entity ->
73-
assertThat(entity)
74-
.hasType("a")
75-
.hasSchemaUrl("one")
76-
.hasIdSatisfying(id -> assertThat(id).containsEntry("a.id", "a"))
77-
.hasDescriptionSatisfying(
78-
desc ->
79-
assertThat(desc)
80-
.containsEntry("a.desc1", "a")
81-
// Don't merge between versions.
82-
.doesNotContainKey("a.desc2")));
70+
entity -> {
71+
assertThat(entity.getType()).isEqualTo("a");
72+
assertThat(entity.getSchemaUrl()).isEqualTo("one");
73+
assertThat(entity.getId()).containsEntry("a.id", "a");
74+
assertThat(entity.getDescription())
75+
.containsEntry("a.desc1", "a")
76+
// Don't merge between versions.
77+
.doesNotContainKey("a.desc2");
78+
});
8379
}
8480

8581
@Test
@@ -102,15 +98,15 @@ void testMerge_entities_same_types_different_id() {
10298
assertThat(merged).hasSize(1);
10399
assertThat(merged)
104100
.satisfiesExactly(
105-
e ->
106-
assertThat(e)
107-
.hasSchemaUrl("one")
108-
.hasIdSatisfying(id -> assertThat(id).containsEntry("a.id", "a"))
109-
.hasDescriptionSatisfying(
110-
desc ->
111-
assertThat(desc)
112-
.containsEntry("a.desc1", "a")
113-
.doesNotContainKey("a.desc2")));
101+
entity -> {
102+
assertThat(entity.getType()).isEqualTo("a");
103+
assertThat(entity.getSchemaUrl()).isEqualTo("one");
104+
assertThat(entity.getId()).containsEntry("a.id", "a");
105+
assertThat(entity.getDescription())
106+
.containsEntry("a.desc1", "a")
107+
// Don't merge between different ids.
108+
.doesNotContainKey("a.desc2");
109+
});
114110
}
115111

116112
@Test
@@ -131,7 +127,8 @@ void testMerge_entities_separate_types_and_schema() {
131127
// Make sure we keep both entities when no conflict.
132128
assertThat(merged)
133129
.satisfiesExactlyInAnyOrder(
134-
a -> assertThat(a).hasType("a"), b -> assertThat(b).hasType("b"));
130+
a -> assertThat(a.getType()).isEqualTo("a"),
131+
b -> assertThat(b.getType()).isEqualTo("b"));
135132
}
136133

137134
@Test
@@ -220,7 +217,7 @@ void testRawAttributeMerge_entity_with_conflict() {
220217
Attributes.builder().put("b", 2).put("c", 2).build(),
221218
Arrays.asList(
222219
Entity.builder("c").withId(Attributes.builder().put("c", 1).build()).build()));
223-
assertThat(result.getConflicts()).satisfiesExactly(e -> assertThat(e).hasType("c"));
220+
assertThat(result.getConflicts()).satisfiesExactly(e -> assertThat(e.getType()).isEqualTo("c"));
224221
assertThat(result.getAttributes())
225222
.hasSize(3)
226223
.containsEntry("a", 1)
@@ -236,7 +233,7 @@ void testAddEntity_reflection() {
236233
Entity.builder("a").withId(Attributes.builder().put("a", 1).build()).build())
237234
.build();
238235
assertThat(EntityUtil.getEntities(result))
239-
.satisfiesExactlyInAnyOrder(e -> assertThat(e).hasType("a"));
236+
.satisfiesExactlyInAnyOrder(e -> assertThat(e.getType()).isEqualTo("a"));
240237
}
241238

242239
@Test
@@ -250,6 +247,7 @@ void testAddAllEntity_reflection() {
250247
.build();
251248
assertThat(EntityUtil.getEntities(result))
252249
.satisfiesExactlyInAnyOrder(
253-
e -> assertThat(e).hasType("a"), e -> assertThat(e).hasType("b"));
250+
e -> assertThat(e.getType()).isEqualTo("a"),
251+
e -> assertThat(e.getType()).isEqualTo("b"));
254252
}
255253
}

0 commit comments

Comments
 (0)