spring-kafkaspring-kafka-test

how to set adminTimeout value with @EmbeddedKafka Annotation (junit5)?


While using parallel gradle tests (org.gradle.parallel=true) to minimize overall test-execution time with junit5 and the @EmbeddedKafka annotation (I need to do integration-tests for > 20 different kafka-based micro-services; using parallel-testing allows me to divide execution-time by a factor 10), I started experimenting timeout exceptions as part of the createTopics method of EmbeddedKafkaBroker.
This problem could be easily remediated by setting up a custom value for the adminTimeout member of EmbeddedKafkaBroker...The problem is I can't see how to achieve this while using junit5 and @EmbeddedKafka annotation...any suggestion ?
thanks a lot in advance for your expertise and your time.
Best Regards


Solution

  • The method of the EmbeddedKafkaBroker:

    /**
     * Set the timeout in seconds for admin operations (e.g. topic creation, close).
     * Default 30 seconds.
     * @param adminTimeout the timeout.
     * @since 2.2
     */
    public void setAdminTimeout(int adminTimeout) {
    

    is just not exposed into an @EmbeddedKafka.

    Feel free to raise a GH issue so we will consider to add it in the future.

    As a workaround you can setup such an embedded broker manually: private static EmbeddedKafkaBroker embeddedKafka;

    @BeforeAll
    static void setup() {
        embeddedKafka = new EmbeddedKafkaBroker(1, true, topic1, topic2);
        embeddedKafka.setAdminTimeout(100);
        embeddedKafka.afterPropertiesSet();
    }
    
    @AfterAll
    static void tearDown() {
        embeddedKafka.destroy();
    }