Skip to content

Commit 9b5c523

Browse files
Add integration tests
1 parent bf21e85 commit 9b5c523

File tree

19 files changed

+707
-77
lines changed

19 files changed

+707
-77
lines changed

.ci/helm.sh

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ function ci::verify_download_java_function_generic_auth() {
239239
}
240240

241241
function ci::verify_vpa_java_function() {
242-
kubectl wait -l name=function-sample-vpa-function --for=condition=RecommendationProvided --timeout=2m vpa && true
242+
kubectl wait -l name=function-sample-vpa --for=condition=RecommendationProvided --timeout=2m vpa
243243
cpu=`kubectl get vpa function-sample-vpa-function -o jsonpath='{.status.recommendation.containerRecommendations[0].target.cpu}'`
244244
memory=`kubectl get vpa function-sample-vpa-function -o jsonpath='{.status.recommendation.containerRecommendations[0].target.memory}'`
245245
resources='{"limits":{"cpu":"'$cpu'","memory":"'$memory'"},"requests":{"cpu":"'$cpu'","memory":"'$memory'"}}'
@@ -269,6 +269,39 @@ function ci::verify_vpa_java_function() {
269269
ci::verify_exclamation_function "persistent://public/default/input-vpa-java-topic" "persistent://public/default/output-vpa-java-topic" "test-message" "test-message!" 10
270270
}
271271

272+
function ci::verify_vpa_with_resource_unit() {
273+
name=$1
274+
kind=$2
275+
baseCpu=200 # cpu value of the resource unit
276+
baseMemory=`echo $((800*1024*1024))` # memory value of the resource unit
277+
vpaName="$1-$2"
278+
kubectl wait -l name=$name --for=condition=RecommendationProvided --timeout=2m vpa
279+
cpu=`kubectl get vpa $vpaName -o jsonpath='{.status.recommendation.containerRecommendations[0].target.cpu}'`
280+
cpu_value=${cpu%m}
281+
282+
quotient=$(($cpu_value / $baseCpu))
283+
remainder=$(($cpu_value % $baseCpu))
284+
285+
# If there's any remainder, we need to round up
286+
if [ $remainder -ne 0 ]; then
287+
multiple=$(($quotient + 1))
288+
else
289+
multiple=$quotient
290+
fi
291+
targetCpu=`echo $(($baseCpu* $multiple ))m`
292+
targetMemory=`echo $(($baseMemory * $multiple ))`
293+
294+
resources='{"limits":{"cpu":"'$targetCpu'","memory":"'$targetMemory'"},"requests":{"cpu":"'$targetCpu'","memory":"'$targetMemory'"}}'
295+
296+
realResource=`kubectl get $kind $name -o jsonpath='{.spec.resources}'`
297+
if [[ "$resources" != "$realResource" ]]; then
298+
echo "vpa tests failed for $kind"
299+
echo "recommend resource is: ${resources}, actual resource is ${realResource}"
300+
exit 1
301+
fi
302+
echo "vpa tests passed"
303+
}
304+
272305
function ci::verify_python_function() {
273306
ci::verify_exclamation_function "persistent://public/default/input-python-topic" "persistent://public/default/output-python-topic" "test-message" "test-message!" 10
274307
}
@@ -349,7 +382,8 @@ function ci::verify_exclamation_function() {
349382
timesleep=$5
350383
kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client produce -m "${inputmessage}" -n 1 "${inputtopic}"
351384
sleep "$timesleep"
352-
MESSAGE=$(kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client consume -n 1 -s "sub" --subscription-position Earliest "${outputtopic}")
385+
sub=`cat /dev/urandom | tr -dc 'a-z' | head -c 8`
386+
MESSAGE=$(kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client consume -n 1 -s "${sub}" --subscription-position Earliest "${outputtopic}")
353387
echo "$MESSAGE"
354388
if [[ "$MESSAGE" == *"$outputmessage"* ]]; then
355389
return 0
@@ -366,7 +400,8 @@ function ci::verify_exclamation_function_with_auth() {
366400
command="kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- sh -c 'bin/pulsar-client --auth-plugin \$brokerClientAuthenticationPlugin --auth-params \$brokerClientAuthenticationParameters produce -m \"${inputmessage}\" -n 1 \"${inputtopic}\"'"
367401
sh -c "$command"
368402
sleep "$timesleep"
369-
consumeCommand="kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- sh -c 'bin/pulsar-client --auth-plugin \$brokerClientAuthenticationPlugin --auth-params \$brokerClientAuthenticationParameters consume -n 1 -s "sub" --subscription-position Earliest \"${outputtopic}\"'"
403+
sub=`cat /dev/urandom | tr -dc 'a-z' | head -c 8`
404+
consumeCommand="kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- sh -c 'bin/pulsar-client --auth-plugin \$brokerClientAuthenticationPlugin --auth-params \$brokerClientAuthenticationParameters consume -n 1 -s \"${sub}\" --subscription-position Earliest \"${outputtopic}\"'"
370405
MESSAGE=$(sh -c "$consumeCommand")
371406
echo "$MESSAGE"
372407
if [[ "$MESSAGE" == *"$outputmessage"* ]]; then
@@ -383,7 +418,8 @@ function ci::verify_wordcount_function() {
383418
timesleep=$5
384419
kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client produce -m "${inputmessage}" -n 1 "${inputtopic}"
385420
sleep "$timesleep"
386-
MESSAGE=$(kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client consume -n 3 -s "sub" --subscription-position Earliest "${outputtopic}")
421+
sub=`cat /dev/urandom | tr -dc 'a-z' | head -c 8`
422+
MESSAGE=$(kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client consume -n 3 -s "${sub}" --subscription-position Earliest "${outputtopic}")
387423
echo "$MESSAGE"
388424
if [[ "$MESSAGE" == *"$outputmessage"* ]]; then
389425
return 0
@@ -453,12 +489,13 @@ function ci::verify_elasticsearch_sink() {
453489

454490
function ci::verify_mongodb_source() {
455491
timesleep=$1
456-
kubectl exec mongo-dbz-0 -c mongo -- mongo -u debezium -p dbz --authenticationDatabase admin localhost:27017/inventory --eval 'db.products.update({"_id":NumberLong(104)},{$set:{weight:1.25}})'
492+
kubectl exec mongo-dbz-0 -c mongo -- mongosh -u debezium -p dbz --authenticationDatabase admin localhost:27017/inventory --eval 'db.products.update({"_id":NumberLong(104)},{$set:{weight:1.25}})'
457493
sleep "$timesleep"
458494
kubectl logs --tail=-1 -l compute.functionmesh.io/name=source-sample | grep "records sent"
459495
if [ $? -eq 0 ]; then
460496
return 0
461497
fi
498+
kubectl logs --tail=-1 -l compute.functionmesh.io/name=source-sample
462499
return 1
463500
}
464501

@@ -484,7 +521,8 @@ function ci::verify_function_with_encryption() {
484521

485522
kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client produce -ekn "myapp1" -ekv "data:application/x-pem-file;base64,${correct_pubkey}" -m "${inputmessage}" -n 1 "${inputtopic}"
486523
sleep "$timesleep"
487-
MESSAGE=$(kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client consume -n 1 -s "sub" --subscription-position Earliest "${outputtopic}")
524+
sub=`cat /dev/urandom | tr -dc 'a-z' | head -c 8`
525+
MESSAGE=$(kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client consume -n 1 -s "${sub}" --subscription-position Earliest "${outputtopic}")
488526
echo "$MESSAGE"
489527
if [[ "$MESSAGE" == *"$outputmessage"* ]]; then
490528
return 0
@@ -573,7 +611,8 @@ function ci::verify_log_topic() {
573611
timesleep=$3
574612

575613
sleep "$timesleep"
576-
MESSAGE=$(kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client consume -n 1 -s "sub" --subscription-position Earliest "${logTopic}")
614+
sub=`cat /dev/urandom | tr -dc 'a-z' | head -c 8`
615+
MESSAGE=$(kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- bin/pulsar-client consume -n 1 -s "${sub}" --subscription-position Earliest "${logTopic}")
577616
echo "$MESSAGE"
578617
if [[ "$MESSAGE" == *"$message"* ]]; then
579618
return 0
@@ -588,7 +627,8 @@ function ci::verify_log_topic_with_auth() {
588627
timesleep=$3
589628

590629
sleep "$timesleep"
591-
consumeCommand="kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- sh -c 'bin/pulsar-client --auth-plugin \$brokerClientAuthenticationPlugin --auth-params \$brokerClientAuthenticationParameters consume -n 1 -s "sub" --subscription-position Earliest \"${logTopic}\"'"
630+
sub=`cat /dev/urandom | tr -dc 'a-z' | head -c 8`
631+
consumeCommand="kubectl exec -n ${NAMESPACE} ${CLUSTER}-pulsar-broker-0 -- sh -c 'bin/pulsar-client --auth-plugin \$brokerClientAuthenticationPlugin --auth-params \$brokerClientAuthenticationParameters consume -n 1 -s \"${sub}\" --subscription-position Earliest \"${logTopic}\"'"
592632
MESSAGE=$(sh -c "$consumeCommand")
593633
echo "$MESSAGE"
594634
if [[ "$MESSAGE" == *"$message"* ]]; then

.ci/tests/integration/cases/mongodb-source/manifests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
cpu: "0.1"
2424
memory: 1G
2525
sourceConfig:
26-
mongodb.hosts: rs0/mongo-dbz-0.mongo.default.svc.cluster.local:27017,rs0/mongo-dbz-1.mongo.default.svc.cluster.local:27017,rs0/mongo-dbz-2.mongo.default.svc.cluster.local:27017
26+
mongodb.hosts: rs0/mongo-dbz-0.mongo.default.svc.cluster.local:27017
2727
mongodb.name: dbserver1
2828
mongodb.user: debezium
2929
mongodb.password: dbz

.ci/tests/integration/cases/mongodb-source/mongodb-dbz.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ spec:
3535
matchLabels:
3636
role: mongo
3737
serviceName: "mongo"
38-
replicas: 3
38+
replicas: 1
3939
template:
4040
metadata:
4141
labels:
@@ -44,7 +44,7 @@ spec:
4444
terminationGracePeriodSeconds: 10
4545
containers:
4646
- name: mongo
47-
image: debezium/example-mongodb:0.10
47+
image: debezium/example-mongodb:2.6
4848
env:
4949
- name: MONGODB_USER
5050
value: "debezium"

.ci/tests/integration/cases/mongodb-source/verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function install_mongodb_server() {
4545
# install mongodb server
4646
kubectl apply -f "${mongodb_file}"
4747
num=0
48-
while [[ ${num} -lt 3 ]]; do
48+
while [[ ${num} -lt 1 ]]; do
4949
sleep 5
5050
kubectl get pods
5151
num=$(kubectl get pods -l role=mongo | wc -l)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
apiVersion: compute.functionmesh.io/v1alpha1
2+
kind: Sink
3+
metadata:
4+
name: vpa-sink-sample
5+
spec:
6+
className: org.apache.pulsar.io.datagenerator.DataGeneratorPrintSink
7+
replicas: 1
8+
sinkConfig:
9+
test: test
10+
input:
11+
topics:
12+
- persistent://public/default/input-vpa-sink-topic
13+
typeClassName: org.apache.pulsar.io.datagenerator.Person
14+
forwardSourceMessageProperty: true
15+
resources:
16+
limits:
17+
cpu: "0.2"
18+
memory: 1.1G
19+
requests:
20+
cpu: "0.1"
21+
memory: 1G
22+
pod:
23+
vpa:
24+
resourceUnit:
25+
cpu: 200m
26+
memory: 800Mi
27+
updatePolicy:
28+
updateMode: "Auto"
29+
resourcePolicy:
30+
containerPolicies:
31+
- containerName: "*"
32+
minAllowed:
33+
cpu: 200m
34+
memory: 100Mi
35+
maxAllowed:
36+
cpu: 1
37+
memory: 1000Mi
38+
pulsar:
39+
pulsarConfig: "test-sink"
40+
tlsConfig:
41+
enabled: false
42+
allowInsecure: false
43+
hostnameVerification: true
44+
certSecretName: sn-platform-tls-broker
45+
certSecretKey: ""
46+
image: streamnative/pulsar-io-data-generator:3.2.2.1
47+
java:
48+
jar: connectors/pulsar-io-data-generator-3.2.2.1.nar
49+
clusterName: test-pulsar
50+
---
51+
apiVersion: v1
52+
kind: ConfigMap
53+
metadata:
54+
name: test-sink
55+
data:
56+
webServiceURL: http://sn-platform-pulsar-broker.default.svc.cluster.local:8080
57+
brokerServiceURL: pulsar://sn-platform-pulsar-broker.default.svc.cluster.local:6650
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
set -e
22+
23+
E2E_DIR=$(dirname "$0")
24+
BASE_DIR=$(cd "${E2E_DIR}"/../../../../..;pwd)
25+
PULSAR_NAMESPACE=${PULSAR_NAMESPACE:-"default"}
26+
PULSAR_RELEASE_NAME=${PULSAR_RELEASE_NAME:-"sn-platform"}
27+
E2E_KUBECONFIG=${E2E_KUBECONFIG:-"/tmp/e2e-k8s.config"}
28+
29+
source "${BASE_DIR}"/.ci/helm.sh
30+
31+
if [ ! "$KUBECONFIG" ]; then
32+
export KUBECONFIG=${E2E_KUBECONFIG}
33+
fi
34+
35+
kubectl apply -f "${BASE_DIR}"/.ci/tests/integration/cases/vpa-with-resource-unit-sink/manifests.yaml > /dev/null 2>&1
36+
37+
verify_fm_result=$(ci::verify_function_mesh vpa-sink-sample 2>&1)
38+
if [ $? -ne 0 ]; then
39+
echo "$verify_fm_result"
40+
kubectl delete -f "${BASE_DIR}"/.ci/tests/integration/cases/vpa-with-resource-unit-sink/manifests.yaml > /dev/null 2>&1 || true
41+
exit 1
42+
fi
43+
44+
verify_java_result=$(NAMESPACE=${PULSAR_NAMESPACE} CLUSTER=${PULSAR_RELEASE_NAME} ci::verify_vpa_with_resource_unit vpa-sink-sample sink 2>&1)
45+
if [ $? -eq 0 ]; then
46+
echo "e2e-test: ok" | yq eval -
47+
else
48+
echo "$verify_java_result"
49+
fi
50+
kubectl delete -f "${BASE_DIR}"/.ci/tests/integration/cases/vpa-with-resource-unit-sink/manifests.yaml > /dev/null 2>&1 || true
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
apiVersion: compute.functionmesh.io/v1alpha1
2+
kind: Source
3+
metadata:
4+
name: vpa-source-sample
5+
spec:
6+
className: org.apache.pulsar.io.datagenerator.DataGeneratorSource
7+
replicas: 1
8+
output:
9+
producerConf:
10+
maxPendingMessages: 1000
11+
maxPendingMessagesAcrossPartitions: 50000
12+
useThreadLocalProducers: true
13+
topic: persistent://public/default/output-vpa-source-topic
14+
typeClassName: org.apache.pulsar.io.datagenerator.Person
15+
forwardSourceMessageProperty: true
16+
sourceConfig:
17+
test: test
18+
resources:
19+
limits:
20+
cpu: "0.2"
21+
memory: 1.1G
22+
requests:
23+
cpu: "0.1"
24+
memory: 1G
25+
pod:
26+
vpa:
27+
resourceUnit:
28+
cpu: 200m
29+
memory: 800Mi
30+
updatePolicy:
31+
updateMode: "Auto"
32+
resourcePolicy:
33+
containerPolicies:
34+
- containerName: "*"
35+
minAllowed:
36+
cpu: 200m
37+
memory: 100Mi
38+
maxAllowed:
39+
cpu: 1
40+
memory: 1000Mi
41+
pulsar:
42+
pulsarConfig: "test-source"
43+
tlsConfig:
44+
enabled: false
45+
allowInsecure: false
46+
hostnameVerification: true
47+
certSecretName: sn-platform-tls-broker
48+
certSecretKey: ""
49+
image: streamnative/pulsar-io-data-generator:3.2.2.1
50+
java:
51+
jar: connectors/pulsar-io-data-generator-3.2.2.1.nar
52+
clusterName: test-pulsar
53+
---
54+
apiVersion: v1
55+
kind: ConfigMap
56+
metadata:
57+
name: test-source
58+
data:
59+
webServiceURL: http://sn-platform-pulsar-broker.default.svc.cluster.local:8080
60+
brokerServiceURL: pulsar://sn-platform-pulsar-broker.default.svc.cluster.local:6650
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
set -e
22+
23+
E2E_DIR=$(dirname "$0")
24+
BASE_DIR=$(cd "${E2E_DIR}"/../../../../..;pwd)
25+
PULSAR_NAMESPACE=${PULSAR_NAMESPACE:-"default"}
26+
PULSAR_RELEASE_NAME=${PULSAR_RELEASE_NAME:-"sn-platform"}
27+
E2E_KUBECONFIG=${E2E_KUBECONFIG:-"/tmp/e2e-k8s.config"}
28+
29+
source "${BASE_DIR}"/.ci/helm.sh
30+
31+
if [ ! "$KUBECONFIG" ]; then
32+
export KUBECONFIG=${E2E_KUBECONFIG}
33+
fi
34+
35+
kubectl apply -f "${BASE_DIR}"/.ci/tests/integration/cases/vpa-with-resource-unit-source/manifests.yaml > /dev/null 2>&1
36+
37+
verify_fm_result=$(ci::verify_function_mesh vpa-source-sample 2>&1)
38+
if [ $? -ne 0 ]; then
39+
echo "$verify_fm_result"
40+
kubectl delete -f "${BASE_DIR}"/.ci/tests/integration/cases/vpa-with-resource-unit-source/manifests.yaml > /dev/null 2>&1 || true
41+
exit 1
42+
fi
43+
44+
verify_java_result=$(NAMESPACE=${PULSAR_NAMESPACE} CLUSTER=${PULSAR_RELEASE_NAME} ci::verify_vpa_with_resource_unit vpa-source-sample source 2>&1)
45+
if [ $? -eq 0 ]; then
46+
echo "e2e-test: ok" | yq eval -
47+
else
48+
echo "$verify_java_result"
49+
fi
50+
kubectl delete -f "${BASE_DIR}"/.ci/tests/integration/cases/vpa-with-resource-unit-source/manifests.yaml > /dev/null 2>&1 || true

0 commit comments

Comments
 (0)