Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remove tag issue for DubboProviderInterceptor in consumer side #1652

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ protected ExecuteContext doBefore(ExecuteContext context) {

@Override
protected ExecuteContext doAfter(ExecuteContext context) {
if (isConsumer(context)) {
return context;
}

TrafficUtils.removeTrafficTag();
return context;
}
Expand Down Expand Up @@ -123,6 +127,9 @@ protected Map<String, List<String>> extractTrafficTagFromCarrier(RpcInvocation i

@Override
public ExecuteContext onThrow(ExecuteContext context) {
if (isConsumer(context)) {
return context;
}
TrafficUtils.removeTrafficTag();
return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@ public void testAlibabaDubboProvider() {
interceptor.after(returnContext);
}

@Test
public void testConsumerSideRemoveTrafficTag() {
// If interceptor is invoked in consumer side, it should not remove traffic tag in after method.
Map<String, List<String>> expectTag = buildExpectTrafficTag("id", "name");
TrafficUtils.setTrafficTag(new TrafficTag(expectTag));

ExecuteContext context = buildContext(new RpcInvocation(), new HashMap<>(), "consumer");
interceptor.before(context);
Assert.assertEquals(TrafficUtils.getTrafficTag().getTag(), expectTag);
interceptor.after(context);
Assert.assertEquals(TrafficUtils.getTrafficTag().getTag(), expectTag);
}

@Test
public void testProviderSideRemoveTrafficTag() {
// If interceptor is invoked in provider side, it should remove traffic tag in after method.
Map<String, List<String>> expectTag = buildExpectTrafficTag("id", "name");
TrafficUtils.setTrafficTag(new TrafficTag(expectTag));

ExecuteContext context = buildContext(new RpcInvocation(), new HashMap<>(), "provider");
interceptor.before(context);
Assert.assertEquals(TrafficUtils.getTrafficTag().getTag(), expectTag);
interceptor.after(context);
Assert.assertNull(TrafficUtils.getTrafficTag());
}

private ExecuteContext buildContext(RpcInvocation rpcInvocation, Map<String, String> headers, String side) {
URL url = new URL("http", "127.0.0.1", 8080);
url = url.addParameter("side", side);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,18 @@ protected ExecuteContext doBefore(ExecuteContext context) {

@Override
protected ExecuteContext doAfter(ExecuteContext context) {
if (isConsumer(context)) {
return context;
}
TrafficUtils.removeTrafficTag();
return context;
}

@Override
public ExecuteContext onThrow(ExecuteContext context) {
if (isConsumer(context)) {
return context;
}
TrafficUtils.removeTrafficTag();
return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ public void testApacheDubboProvider() {
interceptor.after(returnContext);
}

@Test
public void testConsumerSideRemoveTrafficTag() {
// If interceptor is invoked in consumer side, it should not remove traffic tag in after method.
Map<String, List<String>> expectTag = buildExpectTrafficTag("id", "name");
TrafficUtils.setTrafficTag(new TrafficTag(expectTag));

ExecuteContext context = buildContext(new RpcInvocation(), new HashMap<>(), "consumer");
interceptor.before(context);
Assert.assertEquals(TrafficUtils.getTrafficTag().getTag(), expectTag);
interceptor.after(context);
Assert.assertEquals(TrafficUtils.getTrafficTag().getTag(), expectTag);
}

@Test
public void testProviderSideRemoveTrafficTag() {
// If interceptor is invoked in provider side, it should remove traffic tag in after method.
Map<String, List<String>> expectTag = buildExpectTrafficTag("id", "name");
TrafficUtils.setTrafficTag(new TrafficTag(expectTag));

ExecuteContext context = buildContext(new RpcInvocation(), new HashMap<>(), "provider");
interceptor.before(context);
Assert.assertEquals(TrafficUtils.getTrafficTag().getTag(), expectTag);
interceptor.after(context);
Assert.assertNull(TrafficUtils.getTrafficTag());
}

private ExecuteContext buildContext(RpcInvocation rpcInvocation, Map<String, String> headers, String side) {
URL url = new URL("http", "127.0.0.1", 8080);
url = url.addParameter("side", side);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,18 @@ protected ExecuteContext doBefore(ExecuteContext context) {

@Override
protected ExecuteContext doAfter(ExecuteContext context) {
if (isConsumer(context)) {
return context;
}
TrafficUtils.removeTrafficTag();
return context;
}

@Override
public ExecuteContext onThrow(ExecuteContext context) {
if (isConsumer(context)) {
return context;
}
TrafficUtils.removeTrafficTag();
return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ public void testApacheDubboProvider() {
interceptor.after(returnContext);
}

@Test
public void testConsumerSideRemoveTrafficTag() {
// If interceptor is invoked in consumer side, it should not remove traffic tag in after method.
Map<String, List<String>> expectTag = buildExpectTrafficTag("id", "name");
TrafficUtils.setTrafficTag(new TrafficTag(expectTag));

ExecuteContext context = buildContext(new RpcInvocation(), new HashMap<>(), "consumer");
interceptor.before(context);
Assert.assertEquals(TrafficUtils.getTrafficTag().getTag(), expectTag);
interceptor.after(context);
Assert.assertEquals(TrafficUtils.getTrafficTag().getTag(), expectTag);
}

@Test
public void testProviderSideRemoveTrafficTag() {
// If interceptor is invoked in provider side, it should remove traffic tag in after method.
Map<String, List<String>> expectTag = buildExpectTrafficTag("id", "name");
TrafficUtils.setTrafficTag(new TrafficTag(expectTag));

ExecuteContext context = buildContext(new RpcInvocation(), new HashMap<>(), "provider");
interceptor.before(context);
Assert.assertEquals(TrafficUtils.getTrafficTag().getTag(), expectTag);
interceptor.after(context);
Assert.assertNull(TrafficUtils.getTrafficTag());
}

private ExecuteContext buildContext(RpcInvocation rpcInvocation, Map<String, String> headers, String side) {
URL url = new URL("http", "127.0.0.1", 8080);
url = url.addParameter("side", side);
Expand Down
Loading