Skip to content

Commit d38c156

Browse files
Improve the developer experience when running tests (#163)
Migrate the PRs from the pulsar-client-cpp repo: - apache/pulsar-client-cpp#297 - apache/pulsar-client-cpp#236 - apache/pulsar-client-cpp#340
1 parent 99d65d3 commit d38c156

File tree

3 files changed

+59
-46
lines changed

3 files changed

+59
-46
lines changed

build-support/pulsar-test-service-start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cd $SRC_DIR
2525

2626
./build-support/pulsar-test-service-stop.sh
2727

28-
CONTAINER_ID=$(docker run -i -p 8080:8080 -p 6650:6650 -p 8443:8443 -p 6651:6651 --rm --detach apachepulsar/pulsar:latest sleep 3600)
28+
CONTAINER_ID=$(docker run -i --user $(id -u) -p 8080:8080 -p 6650:6650 -p 8443:8443 -p 6651:6651 --rm --detach apachepulsar/pulsar:latest sleep 3600)
2929
echo $CONTAINER_ID > .tests-container-id.txt
3030

3131
docker cp tests/test-conf $CONTAINER_ID:/pulsar/test-conf

build-support/start-test-service-inside-container.sh

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,23 @@ bin/pulsar tokens create \
3434
--secret-key file:///pulsar/data/tokens/secret.key \
3535
> /pulsar/data/tokens/token.txt
3636

37+
# Unset the HTTP proxy to avoid the REST requests being affected
38+
export http_proxy=
39+
TOKEN=$(bin/pulsar tokens create \
40+
--subject superUser \
41+
--secret-key file:///pulsar/data/tokens/secret.key)
42+
43+
put() {
44+
curl -H "Authorization: Bearer $TOKEN" \
45+
-L http://localhost:8080/admin/v2/$1 \
46+
-H 'Content-Type: application/json' \
47+
-X PUT \
48+
-d $(echo $2 | sed 's/ //g')
49+
}
50+
3751
export PULSAR_STANDALONE_CONF=test-conf/standalone-ssl.conf
3852
export PULSAR_PID_DIR=/tmp
53+
sed -i 's/immediateFlush: false/immediateFlush: true/' conf/log4j2.yaml
3954
bin/pulsar-daemon start standalone \
4055
--no-functions-worker --no-stream-storage \
4156
--bookkeeper-dir data/bookkeeper
@@ -48,57 +63,53 @@ echo "-- Pulsar service is ready -- Configure permissions"
4863
export PULSAR_CLIENT_CONF=test-conf/client-ssl.conf
4964

5065
# Create "standalone" cluster if it does not exist
51-
bin/pulsar-admin clusters list | grep -q '^standalone$' ||
52-
bin/pulsar-admin clusters create \
53-
standalone \
54-
--url http://localhost:8080/ \
55-
--url-secure https://localhost:8443/ \
56-
--broker-url pulsar://localhost:6650/ \
57-
--broker-url-secure pulsar+ssl://localhost:6651/
66+
put clusters/standalone '{
67+
"serviceUrl": "http://localhost:8080/",
68+
"serviceUrlTls": "https://localhost:8443/",
69+
"brokerServiceUrl": "pulsar://localhost:6650/",
70+
"brokerServiceUrlTls": "pulsar+ssl://localhost:6651/"
71+
}'
5872

5973
# Update "public" tenant
60-
bin/pulsar-admin tenants create public -r "anonymous" -c "standalone"
74+
put tenants/public '{
75+
"adminRoles": ["anonymous"],
76+
"allowedClusters": ["standalone"]
77+
}'
6178

6279
# Update "public/default" with no auth required
63-
bin/pulsar-admin namespaces create public/default -c standalone
64-
bin/pulsar-admin namespaces grant-permission public/default \
65-
--actions produce,consume \
66-
--role "anonymous"
80+
put namespaces/public/default '{
81+
"auth_policies": {
82+
"namespace_auth": {
83+
"anonymous": ["produce", "consume"]
84+
}
85+
},
86+
"replication_clusters": ["standalone"]
87+
}'
6788

6889
# Create "public/default-2" with no auth required
69-
bin/pulsar-admin namespaces create public/default-2 \
70-
--clusters standalone
71-
bin/pulsar-admin namespaces grant-permission public/default-2 \
72-
--actions produce,consume \
73-
--role "anonymous"
74-
75-
# Create "public/default-3" with no auth required
76-
bin/pulsar-admin namespaces create public/default-3 \
77-
--clusters standalone
78-
bin/pulsar-admin namespaces grant-permission public/default-3 \
79-
--actions produce,consume \
80-
--role "anonymous"
81-
82-
# Create "public/default-4" with encryption required
83-
bin/pulsar-admin namespaces create public/default-4 \
84-
--clusters standalone
85-
bin/pulsar-admin namespaces grant-permission public/default-4 \
86-
--actions produce,consume \
87-
--role "anonymous"
88-
bin/pulsar-admin namespaces set-encryption-required public/default-4 -e
89-
90-
# Create "public/test-backlog-quotas" to test backlog quotas policy
91-
bin/pulsar-admin namespaces create public/test-backlog-quotas \
92-
--clusters standalone
90+
put namespaces/public/default-2 '{
91+
"auth_policies": {
92+
"namespace_auth": {
93+
"anonymous": ["produce", "consume"]
94+
}
95+
},
96+
"replication_clusters": ["standalone"]
97+
}'
9398

9499
# Create "private" tenant
95-
bin/pulsar-admin tenants create private -r "" -c "standalone"
100+
put tenants/private '{
101+
"adminRoles": [],
102+
"allowedClusters": ["standalone"]
103+
}'
96104

97105
# Create "private/auth" with required authentication
98-
bin/pulsar-admin namespaces create private/auth --clusters standalone
99-
100-
bin/pulsar-admin namespaces grant-permission private/auth \
101-
--actions produce,consume \
102-
--role "token-principal"
106+
put namespaces/private/auth '{
107+
"auth_policies": {
108+
"namespace_auth": {
109+
"token-principal": ["produce", "consume"]
110+
}
111+
},
112+
"replication_clusters": ["standalone"]
113+
}'
103114

104115
echo "-- Ready to start tests"

tests/pulsar_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
from urllib.request import urlopen, Request
5757

5858
TM = 10000 # Do not wait forever in tests
59-
CERTS_DIR = os.path.dirname(os.path.abspath(__file__)) + "/test-conf/"
59+
TESTS_DIR = os.path.dirname(os.path.abspath(__file__))
60+
TOKEN_PATH = TESTS_DIR + "/.test-token.txt"
61+
CERTS_DIR = TESTS_DIR + "/test-conf/"
6062

6163
def doHttpPost(url, data):
6264
req = Request(url, data.encode())
@@ -1247,7 +1249,7 @@ def test_get_topics_partitions(self):
12471249
client.close()
12481250

12491251
def test_token_auth(self):
1250-
with open(".test-token.txt") as tf:
1252+
with open(TOKEN_PATH) as tf:
12511253
token = tf.read().strip()
12521254

12531255
# Use adminUrl to test both HTTP request and binary protocol
@@ -1266,7 +1268,7 @@ def test_token_auth(self):
12661268

12671269
def test_token_auth_supplier(self):
12681270
def read_token():
1269-
with open(".test-token.txt") as tf:
1271+
with open(TOKEN_PATH) as tf:
12701272
return tf.read().strip()
12711273

12721274
client = Client(self.serviceUrl, authentication=AuthenticationToken(read_token))

0 commit comments

Comments
 (0)