Skip to content

Commit 11ee390

Browse files
authored
feat: pass the force record flag to storage service (#428)
1 parent d3f17ac commit 11ee390

File tree

14 files changed

+28
-0
lines changed

14 files changed

+28
-0
lines changed

arex-instrumentation-api/src/main/java/io/arex/inst/runtime/context/ArexContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public void setExcludeMockTemplate(Map<String, Set<String>> excludeMockTemplate)
9191
}
9292

9393
public void setAttachment(String key, Object value) {
94+
if (value == null) {
95+
return;
96+
}
97+
9498
if (attachments == null) {
9599
attachments = new HashMap<>();
96100
}

arex-instrumentation-api/src/test/java/io/arex/inst/runtime/context/ArexContextTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@ void calculateSequence() {
1111
ArexContext arexContext = ArexContext.of("mock");
1212
assertEquals(0, arexContext.calculateSequence());
1313
}
14+
15+
@Test
16+
void setAttachment() {
17+
ArexContext arexContext = ArexContext.of("mock");
18+
arexContext.setAttachment("testKey", null);
19+
assertNull(arexContext.getAttachment("testKey"));
20+
}
1421
}

arex-instrumentation/dubbo/arex-dubbo-alibaba/src/main/java/io/arex/inst/dubbo/alibaba/DubboProviderExtractor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static void onServiceEnter(Invoker<?> invoker, Invocation invocation) {
2727
String excludeMockTemplate = adapter.getExcludeMockTemplate();
2828
RequestHandlerManager.preHandle(invocation.getAttachments(), MockCategoryType.DUBBO_PROVIDER.getName());
2929
CaseEventDispatcher.onEvent(CaseEvent.ofCreateEvent(EventSource.of(caseId, excludeMockTemplate)));
30+
ContextManager.currentContext().setAttachment(ArexConstants.FORCE_RECORD, adapter.forceRecord());
3031
RequestHandlerManager.handleAfterCreateContext(invocation.getAttachments(), MockCategoryType.DUBBO_PROVIDER.getName());
3132
invocation.getAttachments().put(ArexConstants.ORIGINAL_REQUEST, Serializer.serialize(invocation.getArguments()));
3233
}

arex-instrumentation/dubbo/arex-dubbo-alibaba/src/test/java/io/arex/inst/dubbo/alibaba/DubboProviderExtractorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static void setUp() {
4242
Mockito.mockStatic(RecordLimiter.class);
4343
Mockito.mockStatic(IgnoreUtils.class);
4444
Mockito.mockStatic(Config.class);
45+
Mockito.when(ContextManager.currentContext()).thenReturn(ArexContext.of("mock"));
4546
Mockito.when(Config.get()).thenReturn(Mockito.mock(Config.class));
4647
}
4748

arex-instrumentation/dubbo/arex-dubbo-apache-v2/src/main/java/io/arex/inst/dubbo/apache/v2/DubboProviderExtractor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static void onServiceEnter(Invoker<?> invoker, Invocation invocation) {
3030
String excludeMockTemplate = adapter.getExcludeMockTemplate();
3131
RequestHandlerManager.preHandle(invocation.getAttachments(), MockCategoryType.DUBBO_PROVIDER.getName());
3232
CaseEventDispatcher.onEvent(CaseEvent.ofCreateEvent(EventSource.of(caseId, excludeMockTemplate)));
33+
ContextManager.currentContext().setAttachment(ArexConstants.FORCE_RECORD, adapter.forceRecord());
3334
RequestHandlerManager.handleAfterCreateContext(invocation.getAttachments(), MockCategoryType.DUBBO_PROVIDER.getName());
3435
invocation.setAttachment(ArexConstants.ORIGINAL_REQUEST, Serializer.serialize(invocation.getArguments()));
3536
}

arex-instrumentation/dubbo/arex-dubbo-apache-v2/src/test/java/io/arex/inst/dubbo/apache/v2/DubboProviderExtractorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static void setUp() {
4242
Mockito.mockStatic(IgnoreUtils.class);
4343
Mockito.mockStatic(Config.class);
4444
Mockito.when(Config.get()).thenReturn(Mockito.mock(Config.class));
45+
Mockito.when(ContextManager.currentContext()).thenReturn(ArexContext.of("mock"));
4546
}
4647

4748
@AfterAll

arex-instrumentation/dubbo/arex-dubbo-apache-v3/src/main/java/io/arex/inst/dubbo/apache/v3/DubboProviderExtractor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static void onServiceEnter(Invoker<?> invoker, Invocation invocation) {
2727
String excludeMockTemplate = adapter.getExcludeMockTemplate();
2828
RequestHandlerManager.preHandle(invocation.getAttachments(), MockCategoryType.DUBBO_PROVIDER.getName());
2929
CaseEventDispatcher.onEvent(CaseEvent.ofCreateEvent(EventSource.of(caseId, excludeMockTemplate)));
30+
ContextManager.currentContext().setAttachment(ArexConstants.FORCE_RECORD, adapter.forceRecord());
3031
RequestHandlerManager.handleAfterCreateContext(invocation.getAttachments(), MockCategoryType.DUBBO_PROVIDER.getName());
3132
invocation.getAttributes().put(ArexConstants.ORIGINAL_REQUEST, Serializer.serialize(invocation.getArguments()));
3233
}

arex-instrumentation/dubbo/arex-dubbo-apache-v3/src/test/java/io/arex/inst/dubbo/apache/v3/DubboProviderExtractorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static void setUp() {
4242
Mockito.mockStatic(IgnoreUtils.class);
4343
Mockito.mockStatic(Config.class);
4444
Mockito.when(Config.get()).thenReturn(Mockito.mock(Config.class));
45+
Mockito.when(ContextManager.currentContext()).thenReturn(ArexContext.of("mock"));
4546
}
4647

4748
@AfterAll

arex-instrumentation/netty/arex-netty-v3/src/main/java/io/arex/inst/netty/v3/server/RequestTracingHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throw
3434

3535
String excludeMockTemplate = NettyHelper.getHeader(request, ArexConstants.HEADER_EXCLUDE_MOCK);
3636
CaseEventDispatcher.onEvent(CaseEvent.ofCreateEvent(EventSource.of(caseId, excludeMockTemplate)));
37+
ContextManager.currentContext().setAttachment(ArexConstants.FORCE_RECORD, NettyHelper.getHeader(request, ArexConstants.FORCE_RECORD));
3738
if (ContextManager.needRecordOrReplay()) {
3839
Mocker mocker = MockUtils.createNettyProvider(request.getUri());
3940
Mocker.Target target = mocker.getTargetRequest();

arex-instrumentation/netty/arex-netty-v3/src/test/java/io/arex/inst/netty/v3/server/RequestTracingHandlerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static void setUp() {
5252
Mockito.mockStatic(Config.class);
5353
Mockito.when(Config.get()).thenReturn(Mockito.mock(Config.class));
5454
Mockito.mockStatic(MockUtils.class);
55+
Mockito.when(ContextManager.currentContext()).thenReturn(ArexContext.of("mock"));
5556
}
5657

5758
@AfterAll

0 commit comments

Comments
 (0)