test_class.declarator: contextFilter = new ContextFilter()
test_class.original_string: Filter contextFilter = new ContextFilter();
test_class.type: Filter
test_class.var_name: contextFilter
test_class.declarator: invoker
test_class.original_string: Invoker<DemoService> invoker;
test_class.type: Invoker<DemoService>
test_class.var_name: invoker
test_class.declarator: invocation
test_class.original_string: Invocation invocation;
test_class.type: Invocation
test_class.var_name: invocation
test_class.file: dubbo-rpc/dubbo-rpc-api/src/test/java/com/alibaba/dubbo/rpc/filter/ContextFilterTest.java
test_class.identifier: ContextFilterTest
test_case.body: @SuppressWarnings("unchecked")
      @Test
      public void testSetContext() {
          invocation = mock(Invocation.class);
          given(invocation.getMethodName()).willReturn("$enumlength");
          given(invocation.getParameterTypes()).willReturn(new Class<?>[]{Enum.class});
          given(invocation.getArguments()).willReturn(new Object[]{"hello"});
          given(invocation.getAttachments()).willReturn(null);
  
          invoker = mock(Invoker.class);
          given(invoker.isAvailable()).willReturn(true);
          given(invoker.getInterface()).willReturn(DemoService.class);
          RpcResult result = new RpcResult();
          result.setValue("High");
          given(invoker.invoke(invocation)).willReturn(result);
          URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
          given(invoker.getUrl()).willReturn(url);
  
          contextFilter.invoke(invoker, invocation);
          assertNull(RpcContext.getContext().getInvoker());
      }
test_case.class_method_signature: ContextFilterTest.testSetContext()
test_case.full_signature: @SuppressWarnings("unchecked") @Test public void testSetContext()
test_case.identifier: testSetContext
test_case.invocations: mock willReturn given getMethodName willReturn given getParameterTypes willReturn given getArguments willReturn given getAttachments mock willReturn given isAvailable willReturn given getInterface setValue willReturn given invoke valueOf willReturn given getUrl invoke assertNull getInvoker getContext
test_case.modifiers: @SuppressWarnings("unchecked") @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testSetContext()
focal_class.file: dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/ContextFilter.java
focal_class.identifier: ContextFilter
focal_class.interfaces: implements Filter
focal_class.class_method_signature: ContextFilter.invoke(Invoker<?> invoker, Invocation invocation)
focal_class.full_signature: @Override public Result invoke(Invoker<?> invoker, Invocation invocation)
focal_class.identifier: invoke
focal_class.modifiers: @Override public
focal_class.parameters: (Invoker<?> invoker, Invocation invocation)
focal_class.return: Result
focal_class.signature: Result invoke(Invoker<?> invoker, Invocation invocation)
focal_method.body: @Override
      public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
          Map<String, String> attachments = invocation.getAttachments();
          if (attachments != null) {
              attachments = new HashMap<String, String>(attachments);
              attachments.remove(Constants.PATH_KEY);
              attachments.remove(Constants.GROUP_KEY);
              attachments.remove(Constants.VERSION_KEY);
              attachments.remove(Constants.DUBBO_VERSION_KEY);
              attachments.remove(Constants.TOKEN_KEY);
              attachments.remove(Constants.TIMEOUT_KEY);
              attachments.remove(Constants.ASYNC_KEY);// Remove async property to avoid being passed to the following invoke chain.
          }
          RpcContext.getContext()
                  .setInvoker(invoker)
                  .setInvocation(invocation)
  //                .setAttachments(attachments)  // merged from dubbox
                  .setLocalAddress(invoker.getUrl().getHost(),
                          invoker.getUrl().getPort());
  
          // mreged from dubbox
          // we may already added some attachments into RpcContext before this filter (e.g. in rest protocol)
          if (attachments != null) {
              if (RpcContext.getContext().getAttachments() != null) {
                  RpcContext.getContext().getAttachments().putAll(attachments);
              } else {
                  RpcContext.getContext().setAttachments(attachments);
              }
          }
  
          if (invocation instanceof RpcInvocation) {
              ((RpcInvocation) invocation).setInvoker(invoker);
          }
          try {
              RpcResult result = (RpcResult) invoker.invoke(invocation);
              // pass attachments to result
              result.addAttachments(RpcContext.getServerContext().getAttachments());
              return result;
          } finally {
              RpcContext.removeContext();
              RpcContext.getServerContext().clearAttachments();
          }
      }
focal_method.class_method_signature: ContextFilter.invoke(Invoker<?> invoker, Invocation invocation)
focal_method.full_signature: @Override public Result invoke(Invoker<?> invoker, Invocation invocation)
focal_method.identifier: invoke
focal_method.invocations: getAttachments remove remove remove remove remove remove remove setLocalAddress setInvocation setInvoker getContext getHost getUrl getPort getUrl getAttachments getContext putAll getAttachments getContext setAttachments getContext setInvoker invoke addAttachments getAttachments getServerContext removeContext clearAttachments getServerContext
focal_method.modifiers: @Override public
focal_method.parameters: (Invoker<?> invoker, Invocation invocation)
focal_method.return: Result
focal_method.signature: Result invoke(Invoker<?> invoker, Invocation invocation)