@Test
    public void testOnCommitChain() {
        List<ConsumerInterceptor<Integer, Integer>> interceptorList = new ArrayList<>();
        // we are testing two different interceptors by configuring the same interceptor differently, which is not
        // how it would be done in KafkaConsumer, but ok for testing interceptor callbacks
        FilterConsumerInterceptor<Integer, Integer> interceptor1 = new FilterConsumerInterceptor<>(filterPartition1);
        FilterConsumerInterceptor<Integer, Integer> interceptor2 = new FilterConsumerInterceptor<>(filterPartition2);
        interceptorList.add(interceptor1);
        interceptorList.add(interceptor2);
        ConsumerInterceptors<Integer, Integer> interceptors = new ConsumerInterceptors<>(interceptorList);

        // verify that onCommit is called for all interceptors in the chain
        Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>();
        offsets.put(tp, new OffsetAndMetadata(0));
        interceptors.onCommit(offsets);
        assertEquals(2, onCommitCount);

        // verify that even if one of the interceptors throws an exception, all interceptors' onCommit are called
        interceptor1.injectOnCommitError(true);
        interceptors.onCommit(offsets);
        assertEquals(4, onCommitCount);

        interceptors.close();
    }
Test consumer interceptor that filters records in onConsume() intercept
clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerInterceptorsTest.java