Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the developer experience when running tests #163

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-support/pulsar-test-service-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cd $SRC_DIR

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

CONTAINER_ID=$(docker run -i -p 8080:8080 -p 6650:6650 -p 8443:8443 -p 6651:6651 --rm --detach apachepulsar/pulsar:latest sleep 3600)
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)
echo $CONTAINER_ID > .tests-container-id.txt

docker cp tests/test-conf $CONTAINER_ID:/pulsar/test-conf
Expand Down
95 changes: 53 additions & 42 deletions build-support/start-test-service-inside-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,23 @@ bin/pulsar tokens create \
--secret-key file:///pulsar/data/tokens/secret.key \
> /pulsar/data/tokens/token.txt

# Unset the HTTP proxy to avoid the REST requests being affected
export http_proxy=
TOKEN=$(bin/pulsar tokens create \
--subject superUser \
--secret-key file:///pulsar/data/tokens/secret.key)

put() {
curl -H "Authorization: Bearer $TOKEN" \
-L http://localhost:8080/admin/v2/$1 \
-H 'Content-Type: application/json' \
-X PUT \
-d $(echo $2 | sed 's/ //g')
}

export PULSAR_STANDALONE_CONF=test-conf/standalone-ssl.conf
export PULSAR_PID_DIR=/tmp
sed -i 's/immediateFlush: false/immediateFlush: true/' conf/log4j2.yaml
bin/pulsar-daemon start standalone \
--no-functions-worker --no-stream-storage \
--bookkeeper-dir data/bookkeeper
Expand All @@ -48,57 +63,53 @@ echo "-- Pulsar service is ready -- Configure permissions"
export PULSAR_CLIENT_CONF=test-conf/client-ssl.conf

# Create "standalone" cluster if it does not exist
bin/pulsar-admin clusters list | grep -q '^standalone$' ||
bin/pulsar-admin clusters create \
standalone \
--url http://localhost:8080/ \
--url-secure https://localhost:8443/ \
--broker-url pulsar://localhost:6650/ \
--broker-url-secure pulsar+ssl://localhost:6651/
put clusters/standalone '{
"serviceUrl": "http://localhost:8080/",
"serviceUrlTls": "https://localhost:8443/",
"brokerServiceUrl": "pulsar://localhost:6650/",
"brokerServiceUrlTls": "pulsar+ssl://localhost:6651/"
}'

# Update "public" tenant
bin/pulsar-admin tenants create public -r "anonymous" -c "standalone"
put tenants/public '{
"adminRoles": ["anonymous"],
"allowedClusters": ["standalone"]
}'

# Update "public/default" with no auth required
bin/pulsar-admin namespaces create public/default -c standalone
bin/pulsar-admin namespaces grant-permission public/default \
--actions produce,consume \
--role "anonymous"
put namespaces/public/default '{
"auth_policies": {
"namespace_auth": {
"anonymous": ["produce", "consume"]
}
},
"replication_clusters": ["standalone"]
}'

# Create "public/default-2" with no auth required
bin/pulsar-admin namespaces create public/default-2 \
--clusters standalone
bin/pulsar-admin namespaces grant-permission public/default-2 \
--actions produce,consume \
--role "anonymous"

# Create "public/default-3" with no auth required
bin/pulsar-admin namespaces create public/default-3 \
--clusters standalone
bin/pulsar-admin namespaces grant-permission public/default-3 \
--actions produce,consume \
--role "anonymous"

# Create "public/default-4" with encryption required
bin/pulsar-admin namespaces create public/default-4 \
--clusters standalone
bin/pulsar-admin namespaces grant-permission public/default-4 \
--actions produce,consume \
--role "anonymous"
bin/pulsar-admin namespaces set-encryption-required public/default-4 -e

# Create "public/test-backlog-quotas" to test backlog quotas policy
bin/pulsar-admin namespaces create public/test-backlog-quotas \
--clusters standalone
put namespaces/public/default-2 '{
"auth_policies": {
"namespace_auth": {
"anonymous": ["produce", "consume"]
}
},
"replication_clusters": ["standalone"]
}'

# Create "private" tenant
bin/pulsar-admin tenants create private -r "" -c "standalone"
put tenants/private '{
"adminRoles": [],
"allowedClusters": ["standalone"]
}'

# Create "private/auth" with required authentication
bin/pulsar-admin namespaces create private/auth --clusters standalone

bin/pulsar-admin namespaces grant-permission private/auth \
--actions produce,consume \
--role "token-principal"
put namespaces/private/auth '{
"auth_policies": {
"namespace_auth": {
"token-principal": ["produce", "consume"]
}
},
"replication_clusters": ["standalone"]
}'

echo "-- Ready to start tests"
8 changes: 5 additions & 3 deletions tests/pulsar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
from urllib.request import urlopen, Request

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

def doHttpPost(url, data):
req = Request(url, data.encode())
Expand Down Expand Up @@ -1247,7 +1249,7 @@ def test_get_topics_partitions(self):
client.close()

def test_token_auth(self):
with open(".test-token.txt") as tf:
with open(TOKEN_PATH) as tf:
token = tf.read().strip()

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

def test_token_auth_supplier(self):
def read_token():
with open(".test-token.txt") as tf:
with open(TOKEN_PATH) as tf:
return tf.read().strip()

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