aboutsummaryrefslogtreecommitdiff
path: root/avro-tools/test/rest-curl.yml
blob: 486392cfb3ffe87de4da194b7a87fa2c40500aa3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
---
kind: ConfigMap
metadata:
  name: rest-curl
  namespace: test-kafka
apiVersion: v1
data:

  setup.sh: |-
    touch /tmp/testlog

    # Keep starting up until rest proxy is up and running
    curl --retry 10 --retry-delay 30 --retry-connrefused -I -s $REST

    curl -s -H 'Accept: application/vnd.kafka.v2+json' $REST/brokers | egrep '."brokers":.0'

    curl -s -H 'Accept: application/vnd.kafka.v2+json' $REST/topics
    echo ""

    curl -s -H 'Accept: application/vnd.kafka.v2+json' $REST/topics/$TOPIC
    echo ""

    curl -X POST \
      -H "Content-Type: application/vnd.kafka.json.v2+json" -H "Accept: application/vnd.kafka.v2+json" \
      --data "{\"records\":[{\"value\":\"Test from $HOSTNAME at $(date -u -Iseconds)\"}]}" \
      $REST/topics/$TOPIC
    echo ""

    curl -s -H 'Accept: application/vnd.kafka.v2+json' $REST/topics/$TOPIC/partitions
    echo ""

    curl -X POST \
      -H "Content-Type: application/vnd.kafka.v2+json" \
      --data '{"name": "my_consumer_instance", "format": "json", "auto.offset.reset": "earliest"}' \
      $REST/consumers/my_json_consumer
    echo ""

    curl -X POST \
      -H "Content-Type: application/vnd.kafka.v2+json" \
      --data "{\"topics\":[\"$TOPIC\"]}" \
      $REST/consumers/my_json_consumer/instances/my_consumer_instance/subscription \
      -w "%{http_code}"
    echo ""

    curl -X GET \
      -H "Accept: application/vnd.kafka.json.v2+json" \
      $REST/consumers/my_json_consumer/instances/my_consumer_instance/records

    curl -X DELETE \
      -H "Content-Type: application/vnd.kafka.v2+json" \
      $REST/consumers/my_json_consumer/instances/my_consumer_instance

    # schema-registry

    curl -X GET $SCHEMAS/subjects
    echo ""

    curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
      --data '{"schema": "{\"type\": \"string\"}"}' \
      $SCHEMAS/subjects/$TOPIC-key/versions
    echo ""

    curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
      --data '{"schema": "{\"type\": \"string\"}"}' \
      $SCHEMAS/subjects/$TOPIC-value/versions
    echo ""

    curl -X GET $SCHEMAS/schemas/ids/1
    echo ""

    curl -X GET $SCHEMAS/subjects/$TOPIC-value/versions/1
    echo ""

    # rest + schema
    # TODO new topic needed because this breaks json consumer above

    curl -X POST -H "Content-Type: application/vnd.kafka.avro.v2+json" \
      -H "Accept: application/vnd.kafka.v2+json" \
      --data '{"value_schema": "{\"type\": \"record\", \"name\": \"User\", \"fields\": [{\"name\": \"name\", \"type\": \"string\"}]}", "records": [{"value": {"name": "testUser"}}]}' \
      $REST/topics/$TOPIC
    echo ""

    curl -X POST  -H "Content-Type: application/vnd.kafka.v2+json" \
      --data '{"name": "my_consumer_instance", "format": "avro", "auto.offset.reset": "earliest"}' \
      $REST/consumers/my_avro_consumer
    echo ""

    curl -X POST -H "Content-Type: application/vnd.kafka.v2+json" \
      --data "{\"topics\":[\"$TOPIC\"]}" \
      $REST/consumers/my_avro_consumer/instances/my_consumer_instance/subscription

    curl -X GET -H "Accept: application/vnd.kafka.avro.v2+json" \
      $REST/consumers/my_avro_consumer/instances/my_consumer_instance/records

    tail -f /tmp/testlog

  continue.sh: |-
    exit 0

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

    exit 0

---
apiVersion: batch/v1
kind: Job
metadata:
  name: rest-curl
  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-rest-curl
        - --partitions
        -   "1"
        - --replication-factor
        -   "1"
      restartPolicy: Never
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: rest-curl
  namespace: test-kafka
spec:
  replicas: 1
  selector:
    matchLabels:
      test-target: kafka-confluent-rest
      test-type: readiness
  template:
    metadata:
      labels:
        test-target: kafka-confluent-rest
        test-type: readiness
    spec:
      containers:
      - name: testcase
        image: solsson/curl@sha256:523319afd39573746e8f5a7c98d4a6cd4b8cbec18b41eb30c8baa13ede120ce3
        env:
        - name: SCHEMAS
          value: http://schemas.kafka.svc.cluster.local
        - name: REST
          value: http://rest.kafka.svc.cluster.local
        - name: TOPIC
          value: test-rest-curl
        # Test set up
        command:
        - /bin/bash
        - -e
        - /test/setup.sh
        # Test run, again and again
        readinessProbe:
          exec:
            command:
            - /bin/bash
            - -e
            - /test/run.sh
          # We haven't worked on timing
          periodSeconds: 60
        # Test quit on nonzero exit
        livenessProbe:
          exec:
            command:
            - /bin/bash
            - -e
            - /test/continue.sh
        volumeMounts:
        - name: config
          mountPath: /test
      volumes:
      - name: config
        configMap:
          name: rest-curl