@Override
    public <T> Invoker<T> buildInvokerChain(final Invoker<T> originalInvoker, String key, String group) {
        Invoker<T> last = originalInvoker;
        URL url = originalInvoker.getUrl();
        List<ModuleModel> moduleModels = getModuleModelsFromUrl(url);
        List<Filter> filters;
        if (moduleModels != null && moduleModels.size() == 1) {
            filters = ScopeModelUtil.getExtensionLoader(Filter.class, moduleModels.get(0))
                    .getActivateExtension(url, key, group);
        } else if (moduleModels != null && moduleModels.size() > 1) {
            filters = new ArrayList<>();
            List<ExtensionDirector> directors = new ArrayList<>();
            for (ModuleModel moduleModel : moduleModels) {
                List<Filter> tempFilters = ScopeModelUtil.getExtensionLoader(Filter.class, moduleModel)
                        .getActivateExtension(url, key, group);
                filters.addAll(tempFilters);
                directors.add(moduleModel.getExtensionDirector());
            }
            filters = sortingAndDeduplication(filters, directors);

        } else {
            filters = ScopeModelUtil.getExtensionLoader(Filter.class, null).getActivateExtension(url, key, group);
        }

        if (!CollectionUtils.isEmpty(filters)) {
            for (int i = filters.size() - 1; i >= 0; i--) {
                final Filter filter = filters.get(i);
                final Invoker<T> next = last;
                last = new CopyOfFilterChainNode<>(originalInvoker, next, filter);
            }
            return new CallbackRegistrationInvoker<>(last, filters);
        }

        return last;
    }
@Test
    void testBuildInvokerChainForLocalReference() {
        DefaultFilterChainBuilder defaultFilterChainBuilder = new DefaultFilterChainBuilder();

        // verify that no filter is built by default
        URL urlWithoutFilter =
                URL.valueOf("injvm://127.0.0.1/DemoService").addParameter(INTERFACE_KEY, DemoService.class.getName());
        urlWithoutFilter = urlWithoutFilter.setScopeModel(ApplicationModel.defaultModel());
        AbstractInvoker<DemoService> invokerWithoutFilter =
                new AbstractInvoker<DemoService>(DemoService.class, urlWithoutFilter) {
                    @Override
                    protected Result doInvoke(Invocation invocation) {
                        return null;
                    }
                };

        Invoker<?> invokerAfterBuild =
                defaultFilterChainBuilder.buildInvokerChain(invokerWithoutFilter, REFERENCE_FILTER_KEY, CONSUMER);

        // verify that if LogFilter is configured, LogFilter should exist in the filter chain
        URL urlWithFilter = URL.valueOf("injvm://127.0.0.1/DemoService")
                .addParameter(INTERFACE_KEY, DemoService.class.getName())
                .addParameter(REFERENCE_FILTER_KEY, "log");
        urlWithFilter = urlWithFilter.setScopeModel(ApplicationModel.defaultModel());
        AbstractInvoker<DemoService> invokerWithFilter =
                new AbstractInvoker<DemoService>(DemoService.class, urlWithFilter) {
                    @Override
                    protected Result doInvoke(Invocation invocation) {
                        return null;
                    }
                };
        invokerAfterBuild =
                defaultFilterChainBuilder.buildInvokerChain(invokerWithFilter, REFERENCE_FILTER_KEY, CONSUMER);
        Assertions.assertTrue(invokerAfterBuild instanceof FilterChainBuilder.CallbackRegistrationInvoker);
    }