public boolean isMatch(Map<String, Pattern> patterns) {
        if (!patterns.isEmpty()) {
            return matchPatterns(patterns);
        }
        // Empty pattern is still considered as a match.
        return true;
    }
@Test
    public void testIsMatchMismatchFail() throws UnknownHostException {
        Uuid uuid = Uuid.randomUuid();
        ClientMetricsInstanceMetadata instanceMetadata = new ClientMetricsInstanceMetadata(uuid,
            ClientMetricsTestUtils.requestContext());

        Map<String, Pattern> patternMap = new HashMap<>();
        patternMap.put(ClientMetricsConfigs.CLIENT_INSTANCE_ID, Pattern.compile(uuid.toString()));
        patternMap.put(ClientMetricsConfigs.CLIENT_SOFTWARE_NAME, Pattern.compile("apache-kafka-.*"));
        patternMap.put(ClientMetricsConfigs.CLIENT_SOFTWARE_VERSION, Pattern.compile("3.5.2"));
        patternMap.put(ClientMetricsConfigs.CLIENT_SOURCE_ADDRESS, Pattern.compile(InetAddress.getLocalHost().getHostAddress()));

        // Client id is different.
        patternMap.put(ClientMetricsConfigs.CLIENT_ID, Pattern.compile("producer-2"));
        assertFalse(instanceMetadata.isMatch(patternMap));

        // Client instance id is different.
        patternMap.put(ClientMetricsConfigs.CLIENT_ID, Pattern.compile("producer-1"));
        patternMap.put(ClientMetricsConfigs.CLIENT_INSTANCE_ID, Pattern.compile(uuid + "random"));
        assertFalse(instanceMetadata.isMatch(patternMap));

        // Software name is different.
        patternMap.put(ClientMetricsConfigs.CLIENT_INSTANCE_ID, Pattern.compile(uuid.toString()));
        patternMap.put(ClientMetricsConfigs.CLIENT_SOFTWARE_NAME, Pattern.compile("apache-kafka-java-1"));
        assertFalse(instanceMetadata.isMatch(patternMap));

        // Software version is different.
        patternMap.put(ClientMetricsConfigs.CLIENT_SOFTWARE_NAME, Pattern.compile("apache-kafka-java"));
        patternMap.put(ClientMetricsConfigs.CLIENT_SOFTWARE_VERSION, Pattern.compile("3.5.x"));
        assertFalse(instanceMetadata.isMatch(patternMap));

        // Source address is different.
        patternMap.put(ClientMetricsConfigs.CLIENT_SOFTWARE_VERSION, Pattern.compile("3.5.2"));
        patternMap.put(ClientMetricsConfigs.CLIENT_SOURCE_ADDRESS, Pattern.compile("1.2.3.4"));
        assertFalse(instanceMetadata.isMatch(patternMap));

        // Source port is different.
        patternMap.put(ClientMetricsConfigs.CLIENT_SOURCE_ADDRESS, Pattern.compile(InetAddress.getLocalHost().getHostAddress()));
        patternMap.put(ClientMetricsConfigs.CLIENT_SOURCE_PORT, Pattern.compile("8080"));
        assertFalse(instanceMetadata.isMatch(patternMap));
    }