@Override
    public List<Object> handle(String targetName, List<Object> instances, RequestData requestData) {
        if (requestData == null) {
            return super.handle(targetName, instances, null);
        }
        if (!shouldHandle(instances)) {
            return instances;
        }
        List<Object> result = routerConfig.isUseRequestRouter()
                ? getTargetInstancesByRequest(targetName, instances, requestData.getTag())
                : getTargetInstancesByRules(targetName, instances, requestData.getPath(), requestData.getTag());
        return super.handle(targetName, result, requestData);
    }
@Test
    public void testGetTargetInstancesByRequestWithMismatch() {
        config.setUseRequestRouter(true);
        config.setRequestTags(Arrays.asList("foo", "bar", "version"));
        List<Object> instances = new ArrayList<>();
        ServiceInstance instance1 = TestDefaultServiceInstance.getTestDefaultServiceInstance("1.0.0",
                Collections.singletonMap("foo", "bar1"));
        instances.add(instance1);
        ServiceInstance instance2 = TestDefaultServiceInstance
                .getTestDefaultServiceInstance("1.0.1", Collections.singletonMap("bar", "bar2"));
        instances.add(instance2);
        ServiceInstance instance3 = TestDefaultServiceInstance.getTestDefaultServiceInstance("1.0.2");
        instances.add(instance3);

        // Bar does not match: If the bar1 instance does not match, the instance without the bar label is matched
        Map<String, List<String>> header = new HashMap<>();
        header.put("bar", Collections.singletonList("bar1"));
        List<Object> targetInstances = flowRouteHandler.handle("foo", instances, new RequestData(header, null, null));
        Assert.assertEquals(2, targetInstances.size());
        Assert.assertFalse(targetInstances.contains(instance2));

        // If the bar: bar1 instance does not match, the instance without the bar tag is preferentially matched,
        // and if there is no instance without the bar tag, an empty list is returned
        List<Object> sameInstances = new ArrayList<>();
        ServiceInstance sameInstance1 = TestDefaultServiceInstance.getTestDefaultServiceInstance("1.0.0",
                Collections.singletonMap("bar", "bar3"));
        sameInstances.add(sameInstance1);
        ServiceInstance sameInstance2 = TestDefaultServiceInstance
                .getTestDefaultServiceInstance("1.0.1", Collections.singletonMap("bar", "bar2"));
        sameInstances.add(sameInstance2);
        header.clear();
        header.put("bar", Collections.singletonList("bar1"));
        targetInstances = flowRouteHandler.handle("foo", sameInstances, new RequestData(header, null, null));
        Assert.assertEquals(0, targetInstances.size());

        // If the version: 1.0.3 instance does not match, all versions of the instance are returned
        header.clear();
        header.put("version", Collections.singletonList("1.0.3"));
        targetInstances = flowRouteHandler.handle("foo", instances, new RequestData(header, null, null));
        Assert.assertEquals(3, targetInstances.size());

        // If no header is passed, the instance without a tag is matched
        header.clear();
        targetInstances = flowRouteHandler.handle("foo", instances, new RequestData(header, null, null));
        Assert.assertEquals(1, targetInstances.size());
        Assert.assertEquals(instance3, targetInstances.get(0));

        // If no header is passed, the instance without a label is matched first,
        // and if there are no instances without a label, all instances are returned
        header.clear();
        targetInstances = flowRouteHandler.handle("foo", sameInstances, new RequestData(header, null, null));
        Assert.assertEquals(sameInstances, targetInstances);
    }