-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split
simple-smoke-test.sh
to be used elsewhere [DI-215] (#790)
`simple-smoke-test.sh` is a useful suite of tests to validate a packaged Hazelcast instance - but is Docker-centric. - Refactored to split the script into two halves: - `abstract-simple-smoke-test` that tests against an abstract Hazelcast instance - `simple-smoke-test` a Docker-specific implementation - Refactored the metadata checks to search the instance's logs for the variant and version (i.e. OSS/EE, `5.5.0` etc) rather than inspecting the containers' filesystem - an existing test elsewhere in the codebase already does this so we already have some dependency on keeping the output consistent, although I can't currently find the test in question - Added extra coverage from [`hazelcast-packaging`'s `check-hazelcast-health.sh`](https://github.com/hazelcast/hazelcast-packaging/blob/bd417d0604b57ae2f72234d8781929fdf86b0687/check-hazelcast-health.sh) Required for [DI-215](https://hazelcast.atlassian.net/browse/DI-215) [DI-215]: https://hazelcast.atlassian.net/browse/DI-215?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
1 parent
3119434
commit cea9844
Showing
2 changed files
with
96 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit -o nounset -o pipefail | ||
|
||
# Performs simple validation tests on an already-running Hazelcast instance | ||
# Abstract as could be from Docker, Homebrew, local binary etc | ||
# Because abstract, expects callers to implement required, but absent functions | ||
function test_package() { | ||
local expected_distribution_type=$1 | ||
local expected_version=$2 | ||
|
||
test_health | ||
test_map_read_write | ||
|
||
# Deliberately last step as it doesn't block-and-wait until the instance is initialized | ||
# Otherwise would have false positives if instance still starting and logs empty | ||
check_metadata "${expected_distribution_type}" "${expected_version}" | ||
} | ||
|
||
# Search logs for entries _like_: | ||
# Hazelcast Platform 5.5.0 (20240725) starting at [172.17.0.2]:5701 | ||
# To validate the version and distribution is correct | ||
function check_metadata() { | ||
local expected_distribution_type=$1 | ||
local expected_version=$2 | ||
|
||
logs=$(get_hz_logs) | ||
|
||
if [[ -z "${logs}" ]]; then | ||
echoerr "Failed to read logs" | ||
exit 1; | ||
fi | ||
|
||
if grep -q "${expected_distribution_type} ${expected_version}" <<< "${logs}"; then | ||
echo "Expected contents (${expected_distribution_type}) and version (${expected_version}) identified." | ||
else | ||
echoerr "Failed to find ${expected_distribution_type} ${expected_version} in logs:" | ||
echoerr "${logs}" | ||
exit 1; | ||
fi | ||
} | ||
|
||
function test_health() { | ||
local attempts=0 | ||
local max_attempts=30 | ||
until curl --silent --fail "127.0.0.1:5701/hazelcast/health/ready"; do | ||
if [[ ${attempts} -eq ${max_attempts} ]];then | ||
echoerr "Hazelcast not responding" | ||
exit 1; | ||
fi | ||
printf '.' | ||
attempts=$((attempts+1)) | ||
sleep 2 | ||
done | ||
} | ||
|
||
function test_map_read_write() { | ||
install_clc | ||
|
||
local key="some-key" | ||
local expected="some-value" | ||
echo "Putting value '${expected}' for key '${key}'" | ||
clc --timeout 5s map set -n some-map "${key}" "${expected}" --log.path stderr | ||
echo "Getting value for key '${key}'" | ||
local actual | ||
actual=$(clc map get --format delimited -n some-map "${key}" --log.path stderr) | ||
|
||
if [[ "${expected}" != "${actual}" ]]; then | ||
echoerr "Expected to read '${expected}' but got '${actual}'" | ||
exit 1; | ||
fi | ||
} | ||
|
||
function install_clc() { | ||
while ! curl https://hazelcast.com/clc/install.sh | bash | ||
do | ||
echo "Retrying clc installation..." | ||
sleep 3 | ||
done | ||
export PATH=${PATH}:${HOME}/.hazelcast/bin | ||
clc config add default cluster.name=dev cluster.address=localhost | ||
} | ||
|
||
# Prints the given message to stderr | ||
function echoerr() { | ||
echo "ERROR - $*" 1>&2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters