Skip to content

Commit 9d56de5

Browse files
committed
Makefile: support running examples
The `run-examples-scylla` target is added to the Makefile to run examples. The examples are built and run against a ScyllaDB instance running in a Docker container. The `SCYLLA_EXAMPLES_TO_RUN` variable is used to specify which examples to build and run. As some examples create the `examples` keyspace and some assume it is not present, a special example `drop_examples_keyspace` is added to drop the `examples` keyspace before running any example. This lets us avoid adding a dependency on `cqlsh` to the system.
1 parent f93be6e commit 9d56de5

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

Makefile

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ CASSANDRA_NO_VALGRIND_TEST_FILTER := $(subst ${SPACE},${EMPTY},AsyncTests.Integr
120120
:HeartbeatTests.Integration_Cassandra_HeartbeatFailed)
121121
endif
122122

123+
ifndef SCYLLA_EXAMPLES_URI
124+
SCYLLA_EXAMPLES_URI := 172.43.0.2
125+
endif
126+
123127
ifndef SCYLLA_EXAMPLES_TO_RUN
124128
SCYLLA_EXAMPLES_TO_RUN := \
125129
async \
@@ -246,7 +250,9 @@ build-integration-test-bin-if-missing:
246250
cmake -DCASS_BUILD_INTEGRATION_TESTS=ON -DCMAKE_BUILD_TYPE=Release .. && (make -j 4 || make);\
247251
}
248252

249-
SCYLLA_EXAMPLES_TO_RUN_SEMICOLON_SEPARATED := $(subst ${SPACE},;,${SCYLLA_EXAMPLES_TO_RUN})
253+
# The special example `drop_examples_keyspace` is used to drop the `examples` keyspace before running any example,
254+
# because some examples create the keyspace and some assume it is not present.
255+
SCYLLA_EXAMPLES_TO_RUN_SEMICOLON_SEPARATED := $(subst ${SPACE},;,${SCYLLA_EXAMPLES_TO_RUN});drop_examples_keyspace
250256

251257
build-examples:
252258
@{\
@@ -338,3 +344,28 @@ endif
338344

339345
run-test-unit: install-cargo-if-missing _update-rust-tooling
340346
@cd ${CURRENT_DIR}/scylla-rust-wrapper; RUSTFLAGS="${FULL_RUSTFLAGS}" cargo test
347+
348+
# Currently not used.
349+
CQLSH := cqlsh
350+
351+
run-examples-scylla: build-examples
352+
@sudo sh -c "echo 2097152 >> /proc/sys/fs/aio-max-nr"
353+
@# Keep `SCYLLA_EXAMPLES_URI` in sync with the `scylla` service in `docker-compose.yml`.
354+
@docker compose -f tests/examples_cluster/docker-compose.yml up -d --wait
355+
356+
@# Instead of using cqlsh, which would impose another dependency on the system,
357+
@# we use a special example `drop_examples_keyspace` to drop the `examples` keyspace.
358+
@# CQLSH_HOST=${SCYLLA_EXAMPLES_URI} ${CQLSH} -e "DROP KEYSPACE IF EXISTS EXAMPLES"; \
359+
360+
@echo "Running examples on scylla ${SCYLLA_VERSION}"
361+
@for example in ${SCYLLA_EXAMPLES_TO_RUN} ; do \
362+
echo -e "\nRunning example: $${example}"; \
363+
build/examples/drop_examples_keyspace/drop_examples_keyspace ${SCYLLA_EXAMPLES_URI} || exit 1; \
364+
build/examples/$${example}/$${example} ${SCYLLA_EXAMPLES_URI} || { \
365+
echo "Example \`$${example}\` has failed!"; \
366+
docker compose -f tests/examples_cluster/docker-compose.yml down; \
367+
exit 42; \
368+
}; \
369+
done
370+
371+
@docker compose -f tests/examples_cluster/docker-compose.yml down --remove-orphans

0 commit comments

Comments
 (0)