-
Notifications
You must be signed in to change notification settings - Fork 880
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve the issue of failing to retrieve attachments in dubbo 2.7.6 a…
…nd 2.7.7 (#12982) Co-authored-by: Lauri Tulmin <[email protected]> Co-authored-by: Lauri Tulmin <[email protected]>
- Loading branch information
1 parent
260f237
commit 3c94040
Showing
3 changed files
with
87 additions
and
2 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
54 changes: 54 additions & 0 deletions
54
...c/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetterTest.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,54 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.apachedubbo.v2_7; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.rpc.RpcContext; | ||
import org.apache.dubbo.rpc.RpcInvocation; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class DubboHeadersGetterTest { | ||
|
||
@Mock RpcContext context; | ||
@Mock RpcInvocation rpcInvocation; | ||
|
||
@Test | ||
void testKeys() throws Exception { | ||
when(context.getUrl()).thenReturn(new URL("http", "localhost", 1)); | ||
when(context.getRemoteAddress()).thenReturn(new InetSocketAddress(1)); | ||
when(context.getLocalAddress()).thenReturn(new InetSocketAddress(1)); | ||
|
||
// for latest dep tests call getObjectAttachments, otherwise call getAttachments | ||
if (Boolean.getBoolean("testLatestDeps")) { | ||
when(getObjectAttachments()).thenReturn(Collections.singletonMap("key", "value")); | ||
} else { | ||
when(rpcInvocation.getAttachments()).thenReturn(Collections.singletonMap("key", "value")); | ||
} | ||
DubboRequest request = DubboRequest.create(rpcInvocation, context); | ||
|
||
Iterator<String> iterator = DubboHeadersGetter.INSTANCE.keys(request).iterator(); | ||
assertThat(iterator.hasNext()).isTrue(); | ||
assertThat(iterator.next()).isEqualTo("key"); | ||
assertThat(iterator.hasNext()).isFalse(); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private Map<Object, Object> getObjectAttachments() throws Exception { | ||
return (Map<Object, Object>) | ||
RpcInvocation.class.getMethod("getObjectAttachments").invoke(rpcInvocation); | ||
} | ||
} |