aboutsummaryrefslogblamecommitdiff
path: root/kafka/test/consumer-group.yml
blob: 9184558e19265135271aa6b4a00331b2af7a9361 (plain) (tree)
1
2
3
4


               
                              













                        




                                                               


                                                                                                                                  

                                                       
                                                  
                                           
                                                                                                                                         


             










                             
                                         













                                                                                                          
                                       






                          
                              

                       
             

                
                                                      



                          
                                                        




















                                                                                                       
                                                                                         





                            















                                                                                                       
                           













                                           
                                      

                    
---
kind: ConfigMap
metadata:
  name: kafkacat-consumergroup
  namespace: test-kafka
apiVersion: v1
data:

  setup.sh: |-
    touch /tmp/testlog

    tail -f /tmp/testlog

  test.sh: |-
    exec >> /tmp/testlog
    exec 2>&1

    PC_WAIT=.2

    UNIQUE="${HOSTNAME}@$(date -u -Ins)"

    echo "${UNIQUE: -41:5}:Test $UNIQUE" >> /shared/produce.tmp
    sleep $PC_WAIT
    PREVIOUS=$(cat /shared/consumed.tmp | grep -v '%' || echo "-1")
    kafkacat -b $BOOTSTRAP -G test-kafkacat-consumergroup test-kafkacat-consumergroup -f '%o\n' -u -c 1 | tee /shared/consumed.tmp
    LAST=$(cat /shared/consumed.tmp | grep -v '%')
    [ -z "$LAST" ] && echo "Nothing consumed" && exit 1

    # should fail if the test has only one replica
    if (( ($PREVIOUS + 1) == $LAST )); then
      echo "Consumed offset increased from $PREVIOUS to $LAST. Diff should be >1 when there's more than 1 replica in the consumer group."
      exit 10
    fi

    exit 0

  quit-on-nonzero-exit.sh: |-
    exec >> /tmp/testlog
    exec 2>&1

    exit 0
---
apiVersion: batch/v1
kind: Job
metadata:
  name: topic-test-kafkacat-consumergroup
  namespace: test-kafka
spec:
  template:
    spec:
      containers:
      - name: topic-create
        image: solsson/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
        command:
        - ./bin/kafka-topics.sh
        - --zookeeper
        -   zookeeper.kafka.svc.cluster.local:2181
        - --create
        - --if-not-exists
        - --topic
        -   test-kafkacat-consumergroup
        - --partitions
        -   "1"
      restartPolicy: Never
---
apiVersion: apps/v1beta2
kind: ReplicaSet
metadata:
  name: kafkacat-consumergroup
  namespace: test-kafka
spec:
  replicas: 0
  selector:
    matchLabels:
      test-target: kafka-client-kafkacat-consumergroup
      test-type: readiness
  template:
    metadata:
      labels:
        test-target: kafka-client-kafkacat-consumergroup
        test-type: readiness
        # for example:
        # readonly - can be used in production
        # isolated - read/write but in a manner that does not affect other services
        # load - unsuitable for production because it uses significant resources
        # chaos - unsuitable for production because it injects failure modes
        #test-use:
    spec:
      containers:
      - name: producer
        image: solsson/kafkacat@sha256:b32eedf936f3cde44cd164ddc77dfcf7565a8af4e357ff6de1abe4389ca530c9
        env:
        - name: BOOTSTRAP
          value: bootstrap.kafka:9092
        command:
        - /bin/bash
        - -cex
        - >
          echo "--- start $HOSTNAME $(date --iso-8601='ns' -u) ---" >> /shared/produce.tmp
          ;
          tail -f /shared/produce.tmp |
          kafkacat -P -b $BOOTSTRAP -t test-kafkacat-consumergroup -v -T -d broker -K ':'
          ;
        volumeMounts:
        - name: config
          mountPath: /test
        - name: shared
          mountPath: /shared
      - name: testcase
        image: solsson/kafkacat@sha256:b32eedf936f3cde44cd164ddc77dfcf7565a8af4e357ff6de1abe4389ca530c9
        env:
        - name: BOOTSTRAP
          value: bootstrap.kafka:9092
        command:
        - /bin/bash
        - -e
        - /test/setup.sh
        readinessProbe:
          exec:
            command:
            - /bin/bash
            - -e
            - /test/test.sh
          initialDelaySeconds: 10
          periodSeconds: 35
        livenessProbe:
          exec:
            command:
            - /bin/bash
            - -e
            - /test/quit-on-nonzero-exit.sh
        volumeMounts:
        - name: config
          mountPath: /test
        - name: shared
          mountPath: /shared
      volumes:
      - name: config
        configMap:
          name: kafkacat-consumergroup
      - name: shared
        emptyDir: {}