Search in sources :

Example 1 with KafkaListenerType

use of io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType in project strimzi by strimzi.

the class MultipleListenersST method generateTestCases.

/**
 * Generates stochastic count of GenericKafkaListener for each type. Every type of listener has it's own count and
 * port generation interval.
 * @return HashMap which holds all generated listeners
 */
private Map<KafkaListenerType, List<GenericKafkaListener>> generateTestCases() {
    LOGGER.info("Starting to generate test cases for multiple listeners");
    int stochasticCount;
    for (KafkaListenerType kafkaListenerType : KafkaListenerType.values()) {
        LOGGER.info("Generating {} listener", kafkaListenerType.name());
        List<GenericKafkaListener> testCaseListeners = new ArrayList<>(5);
        switch(kafkaListenerType) {
            case NODEPORT:
                stochasticCount = ThreadLocalRandom.current().nextInt(2, 5);
                for (int j = 0; j < stochasticCount; j++) {
                    boolean stochasticCommunication = ThreadLocalRandom.current().nextInt(2) == 0;
                    testCaseListeners.add(new GenericKafkaListenerBuilder().withName(KafkaListenerType.NODEPORT.toValue() + j).withPort(10900 + j).withType(KafkaListenerType.NODEPORT).withTls(stochasticCommunication).build());
                }
                break;
            case LOADBALANCER:
                stochasticCount = ThreadLocalRandom.current().nextInt(2, 3);
                for (int j = 0; j < stochasticCount; j++) {
                    boolean stochasticCommunication = ThreadLocalRandom.current().nextInt(2) == 0;
                    testCaseListeners.add(new GenericKafkaListenerBuilder().withName(KafkaListenerType.LOADBALANCER.toValue().substring(0, 5) + j).withPort(11900 + j).withType(KafkaListenerType.LOADBALANCER).withTls(stochasticCommunication).withNewConfiguration().withFinalizers(LB_FINALIZERS).endConfiguration().build());
                }
                break;
            case ROUTE:
                // TODO: bug with unique ports per listener which should be fixed now in Kafka 2.7.0
                testCaseListeners.add(new GenericKafkaListenerBuilder().withName(KafkaListenerType.ROUTE.toValue()).withPort(12091).withType(KafkaListenerType.ROUTE).withTls(true).build());
                break;
            case INTERNAL:
                stochasticCount = ThreadLocalRandom.current().nextInt(2, 4);
                for (int j = 0; j < stochasticCount; j++) {
                    boolean stochasticCommunication = ThreadLocalRandom.current().nextInt(2) == 0;
                    testCaseListeners.add(new GenericKafkaListenerBuilder().withName(KafkaListenerType.INTERNAL.toValue() + j).withPort(13900 + j).withType(KafkaListenerType.INTERNAL).withTls(stochasticCommunication).build());
                }
        }
        LOGGER.info("Generating listeners with type {} -> {}", kafkaListenerType.name(), testCaseListeners.toArray());
        testCases.put(kafkaListenerType, testCaseListeners);
    }
    LOGGER.info("Finished with generation of test cases for multiple listeners");
    return testCases;
}
Also used : KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ArrayList(java.util.ArrayList)

Example 2 with KafkaListenerType

use of io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType in project strimzi-kafka-operator by strimzi.

the class MultipleListenersST method generateTestCases.

/**
 * Generates stochastic count of GenericKafkaListener for each type. Every type of listener has it's own count and
 * port generation interval.
 * @return HashMap which holds all generated listeners
 */
private Map<KafkaListenerType, List<GenericKafkaListener>> generateTestCases() {
    LOGGER.info("Starting to generate test cases for multiple listeners");
    int stochasticCount;
    for (KafkaListenerType kafkaListenerType : KafkaListenerType.values()) {
        LOGGER.info("Generating {} listener", kafkaListenerType.name());
        List<GenericKafkaListener> testCaseListeners = new ArrayList<>(5);
        switch(kafkaListenerType) {
            case NODEPORT:
                stochasticCount = ThreadLocalRandom.current().nextInt(2, 5);
                for (int j = 0; j < stochasticCount; j++) {
                    boolean stochasticCommunication = ThreadLocalRandom.current().nextInt(2) == 0;
                    testCaseListeners.add(new GenericKafkaListenerBuilder().withName(KafkaListenerType.NODEPORT.toValue() + j).withPort(10900 + j).withType(KafkaListenerType.NODEPORT).withTls(stochasticCommunication).build());
                }
                break;
            case LOADBALANCER:
                stochasticCount = ThreadLocalRandom.current().nextInt(2, 3);
                for (int j = 0; j < stochasticCount; j++) {
                    boolean stochasticCommunication = ThreadLocalRandom.current().nextInt(2) == 0;
                    testCaseListeners.add(new GenericKafkaListenerBuilder().withName(KafkaListenerType.LOADBALANCER.toValue().substring(0, 5) + j).withPort(11900 + j).withType(KafkaListenerType.LOADBALANCER).withTls(stochasticCommunication).withNewConfiguration().withFinalizers(LB_FINALIZERS).endConfiguration().build());
                }
                break;
            case ROUTE:
                // TODO: bug with unique ports per listener which should be fixed now in Kafka 2.7.0
                testCaseListeners.add(new GenericKafkaListenerBuilder().withName(KafkaListenerType.ROUTE.toValue()).withPort(12091).withType(KafkaListenerType.ROUTE).withTls(true).build());
                break;
            case INTERNAL:
                stochasticCount = ThreadLocalRandom.current().nextInt(2, 4);
                for (int j = 0; j < stochasticCount; j++) {
                    boolean stochasticCommunication = ThreadLocalRandom.current().nextInt(2) == 0;
                    testCaseListeners.add(new GenericKafkaListenerBuilder().withName(KafkaListenerType.INTERNAL.toValue() + j).withPort(13900 + j).withType(KafkaListenerType.INTERNAL).withTls(stochasticCommunication).build());
                }
        }
        LOGGER.info("Generating listeners with type {} -> {}", kafkaListenerType.name(), testCaseListeners.toArray());
        testCases.put(kafkaListenerType, testCaseListeners);
    }
    LOGGER.info("Finished with generation of test cases for multiple listeners");
    return testCases;
}
Also used : KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ArrayList(java.util.ArrayList)

Aggregations

GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)2 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)2 KafkaListenerType (io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType)2 ArrayList (java.util.ArrayList)2