Skip to content

Commit 2646ed4

Browse files
committed
Fix failing test
1 parent e974692 commit 2646ed4

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/internal/RegistryCapturingClusterWrapperTest.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77

88
import static java.util.Collections.singletonList;
99
import static org.assertj.core.api.Assertions.assertThat;
10-
import static org.mockito.ArgumentMatchers.same;
11-
import static org.mockito.Mockito.mock;
12-
import static org.mockito.Mockito.when;
1310

1411
import org.apache.dubbo.common.URL;
1512
import org.apache.dubbo.rpc.Invocation;
1613
import org.apache.dubbo.rpc.Invoker;
1714
import org.apache.dubbo.rpc.Result;
1815
import org.apache.dubbo.rpc.cluster.Cluster;
16+
import org.apache.dubbo.rpc.cluster.Directory;
1917
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
2018
import org.junit.jupiter.api.Test;
2119

@@ -27,17 +25,44 @@ class RegistryCapturingClusterWrapperTest {
2725
@Test
2826
@SuppressWarnings("unchecked")
2927
void joinDoesNotWrapStaticDirectory() {
30-
Cluster inner = mock(Cluster.class);
31-
RegistryCapturingClusterWrapper wrapper = new RegistryCapturingClusterWrapper(inner);
3228
Invoker<Object> innerInvoker = new NoopInvoker(DUMMY_URL);
29+
RegistryCapturingClusterWrapper wrapper =
30+
new RegistryCapturingClusterWrapper(new FakeCluster(innerInvoker));
3331
StubInvoker stub = new StubInvoker(DUMMY_URL);
3432
StaticDirectory<Object> staticDir = new StaticDirectory<>(singletonList(stub));
35-
when(inner.join(same(staticDir))).thenReturn(innerInvoker);
3633

3734
Invoker<Object> out = wrapper.join(staticDir);
3835
assertThat(out).isSameAs(innerInvoker);
3936
}
4037

38+
/**
39+
* Fake {@link Cluster} that provides both the Dubbo 2.7 {@code join(Directory)} and 3.0.4+ {@code
40+
* join(Directory, boolean)} signatures, following the same pattern as {@link
41+
* RegistryCapturingClusterWrapper}.
42+
*/
43+
@SuppressWarnings("unchecked")
44+
private static class FakeCluster implements Cluster {
45+
private final Invoker<?> invoker;
46+
47+
FakeCluster(Invoker<?> invoker) {
48+
this.invoker = invoker;
49+
}
50+
51+
// Dubbo 2.7 signature
52+
// @Override — present in 2.7, removed in 3.0.4+
53+
@SuppressWarnings({"MissingOverride", "UnusedMethod", "UnusedVariable", "EffectivelyPrivate"})
54+
public <T> Invoker<T> join(Directory<T> directory) {
55+
return (Invoker<T>) invoker;
56+
}
57+
58+
// Dubbo 3.0.4+ signature
59+
// @Override — present in 3.0.4+, absent in 2.7
60+
@SuppressWarnings({"MissingOverride", "UnusedMethod", "UnusedVariable", "EffectivelyPrivate"})
61+
public <T> Invoker<T> join(Directory<T> directory, boolean buildFilterChain) {
62+
return (Invoker<T>) invoker;
63+
}
64+
}
65+
4166
private static class NoopInvoker implements Invoker<Object> {
4267
private final URL url;
4368

0 commit comments

Comments
 (0)