Skip to content

Commit 8a80342

Browse files
committed
Add Clouseau to the developer setup
Provide a way to the developers to deploy and launch the Clouseau search module more easily, therefore making it more accessible. This can help with running the Search-based Elixir tests as well as the Mango `text` search tests. This could allow us to catch more bugs ahead of time and might even inspire more improvements in the area. The extension is designed in a way to make it simple to integrate with the CI — only the Java environment of the proper version needs to be deployed, everything else could be managed from this repository. Such as bumping the version of Clouseau or fine-tuning the configuration parameters. This is an opt-in feature on two levels. First, one has to tell `./configure --enable-clouseau` to instantiate Clouseau locally. This will create the `clouseau` sub-directory that holds the contents of the Clouseau distribution of the specified version, which currently defaults to 2.22.0 (the latest). If an older version is needed, use the `--clouseau-version` flag. Then the `mango-test` and `elixir-search` targets will try to use Clouseau automatically just to make it easy to use in the old way. However, the `dev/run` script will not do the same. It requires the `--with-clouseau` flag to be passed for that. That is because the developer may not necessarily want to launch Clouseau ad hoc, even if it is available. With this, note that `elixir-search` is added to the `check` target. In lack of a configured Clouseau instance, it will become a no-op and a warning is emitted.
1 parent 46a781f commit 8a80342

File tree

4 files changed

+271
-20
lines changed

4 files changed

+271
-20
lines changed

Makefile

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ check: all
158158
@$(MAKE) eunit
159159
@$(MAKE) mango-test
160160
@$(MAKE) elixir
161+
@$(MAKE) elixir-search
161162
@$(MAKE) weatherreport-test
162163
@$(MAKE) nouveau-test
163164

@@ -275,12 +276,17 @@ elixir: elixir-init devclean
275276
--no-eval 'mix test --trace --include test/elixir/test/config/suite.elixir --exclude test/elixir/test/config/skip.elixir $(EXUNIT_OPTS)'
276277

277278
.PHONY: elixir-search
278-
# target: elixir-search - Run search tests, requires a running Clouseau instance
279+
# target: elixir-search - Run search tests, requires a configured Clouseau instance
279280
elixir-search: export MIX_ENV=integration
280281
elixir-search: elixir-init devclean
282+
ifeq ($(with_clouseau), 1)
281283
@dev/run -n 1 -q -a adm:pass \
284+
--with-clouseau \
282285
--locald-config test/config/test-config.ini \
283286
--no-eval 'mix test --trace --include test/elixir/test/config/search.elixir'
287+
else
288+
@echo "Warning: Clouseau is not enabled, \`elixir-search\` cannot be run."
289+
endif
284290

285291
.PHONY: elixir-source-checks
286292
# target: elixir-source-checks - Check source code formatting of Elixir test files
@@ -325,19 +331,24 @@ list-eunit-suites:
325331
build-test:
326332
@test/build/test-configure.sh
327333

334+
ifeq ($(with_clouseau), 1)
335+
_WITH_CLOUSEAU="--with-clouseau"
336+
endif
328337

329338
.PHONY: mango-test
330339
# target: mango-test - Run Mango tests
331340
mango-test: export COUCHDB_TEST_ADMIN_PARTY_OVERRIDE=1
332-
mango-test: devclean all
333-
@cd src/mango && \
334-
python3 -m venv .venv && \
335-
.venv/bin/python3 -m pip install -r requirements.txt
336-
@cd src/mango && \
337-
../../dev/run "$(TEST_OPTS)" \
341+
mango-test: all devclean
342+
@python3 -m venv src/mango/.venv && \
343+
src/mango/.venv/bin/python3 -m pip install -r src/mango/requirements.txt
344+
@dev/run \
345+
"$(TEST_OPTS)" \
346+
"$(_WITH_CLOUSEAU)" \
338347
-n 1 \
339-
--admin=adm:pass \
340-
'COUCH_USER=adm COUCH_PASS=pass .venv/bin/python3 -m nose2 $(MANGO_TEST_OPTS)'
348+
-a adm:pass \
349+
--no-eval "\
350+
COUCH_USER=adm COUCH_PASS=pass \
351+
src/mango/.venv/bin/nose2 -s src/mango/test -c src/mango/unittest.cfg $(MANGO_TEST_OPTS)"
341352

342353

343354
.PHONY: weatherreport-test

README-DEV.rst

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ Configure the source by running::
152152

153153
./configure
154154

155-
If you intend to run the test suites::
155+
If you intend to run the test suites with Clouseau::
156156

157-
./configure -c
157+
./configure --enable-clouseau
158158

159159
If you don't want to build Fauxton or documentation specify
160160
``--disable-fauxton`` and/or ``--disable-docs`` arguments for ``configure`` to
@@ -237,14 +237,8 @@ but it could be done manually via the corresponding target::
237237

238238
make elixir-search
239239

240-
Note that this requires a running Clouseau instance with the name
241-
``clouseau@127.0.0.1``. The easiest way to get it is to clone the
242-
`cloudant-labs/clouseau <https://github.com/cloudant-labs/clouseau>`_
243-
repository and launch it run there once all the prerequisites (JDK,
244-
Scala, and Maven) have been installed successfully, e.g.::
245-
246-
git clone https://github.com/cloudant-labs/clouseau
247-
mvn -f clouseau/pom.xml scala:run
240+
Note that this requires Clouseau to be configured for running, see
241+
above.
248242

249243
Mango Integration Tests
250244
~~~~~~~~~~~~~~~~~~~~~~~
@@ -262,7 +256,7 @@ the implementation. Consult its documentation for more information.
262256

263257
Tests that rely on text indexes are run only if the ``search`` feature
264258
is reported to be available (i.e. a working Clouseau instance is
265-
connected), otherwise they will be skipped.
259+
configured and working), otherwise they will be skipped.
266260

267261
Note that the databases that are created during the tests will be all
268262
removed after each of the suites completed. However, with the help of
@@ -272,6 +266,51 @@ to keep those databases around for further investigation::
272266
MANGO_TESTS_KEEP_DBS=please \
273267
make mango-test MANGO_TEST_OPTS='03-operator-test'
274268

269+
Running Clouseau
270+
~~~~~~~~~~~~~~~~
271+
272+
When configured with the ``./configure`` script, the ``./dev/run``
273+
script is capable of launching Clouseau instances alongside the
274+
CouchDB nodes and hooking them up. This is what the ``mango-test``
275+
and ``elixir-search`` targets also use to run their respective test
276+
suites and let Clouseau automatically managed for them.
277+
278+
Although the ``./configure`` and the ``./dev/run`` scripts try to take
279+
care of the details of the Clouseau deployment, it is still the
280+
responsibility of the user to provide a suitable Java environment for
281+
running. Clouseau can run with JRE 1.7 and 1.8 only. Also, when
282+
Nouveau is in use, which uses a more recent Java environment, the old
283+
JDK has to be installed separately and the ``CLOUSEAU_JAVA_HOME``
284+
environment variable has to be set to point its location.
285+
286+
Fortunately, the ```asdf`` tool <https://asdf-vm.com/>` provides a
287+
convenient way to install old versions of JDK through its ```java``
288+
plugin <https://github.com/halcyon/asdf-java>`::
289+
290+
asdf plugin add java
291+
292+
Then use ``asdf`` to install it::
293+
294+
asdf install java zulu-jre-8.74.0.17
295+
296+
Finally, use ``asdf`` to set the ``CLOUSEAU_JAVA_HOME`` environment
297+
variable::
298+
299+
export CLOUSEAU_JAVA_HOME=$(asdf where java zulu-jre-8.74.0.17)
300+
301+
If the use of ``asdf`` is not an option, `the Zulu site
302+
<https://cdn.azul.com/zulu/bin/>` could be used directly to get the
303+
distribution package for the appropriate JRE version. But this is
304+
just one of the possibilities to access installers for old Java
305+
environments.
306+
307+
Once both Clouseau and the corresponding Java environment are set,
308+
they are not put in use automatically. In order to do so, the
309+
``./dev/run`` script needs to be run with Clouseau enabled as
310+
follows::
311+
312+
dev/run --with-clouseau
313+
275314
Static Code Analysis
276315
~~~~~~~~~~~~~~~~~~~~
277316

configure

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ WITH_PROPER="true"
2929
WITH_FAUXTON=1
3030
WITH_DOCS=1
3131
WITH_NOUVEAU=0
32+
WITH_CLOUSEAU=0
3233
ERLANG_MD5="false"
3334
SKIP_DEPS=0
3435

@@ -38,6 +39,8 @@ run_erlang() {
3839

3940
COUCHDB_USER="$(whoami 2>/dev/null || echo couchdb)"
4041
SM_VSN=${SM_VSN:-"91"}
42+
CLOUSEAU_VSN=${CLOUSEAU_VSN:-"2.22.0"}
43+
CLOUSEAU_DIR="$(pwd)"/clouseau
4144
ARCH="$(uname -m)"
4245
ERLANG_VER="$(run_erlang 'io:put_chars(erlang:system_info(otp_release)).')"
4346
ERLANG_OS="$(run_erlang 'case os:type() of {OS, _} -> io:format("~s~n", [OS]) end.')"
@@ -59,9 +62,11 @@ Options:
5962
--disable-fauxton do not build Fauxton
6063
--disable-docs do not build any documentation or manpages
6164
--enable-nouveau enable the new experimental search module
65+
--enable-clouseau enable the Clouseau search module
6266
--erlang-md5 use erlang for md5 hash operations
6367
--dev alias for --disable-docs --disable-fauxton
6468
--spidermonkey-version VSN specify the version of SpiderMonkey to use (defaults to $SM_VSN)
69+
--clouseau-version VSN specify the version of Clouseau to use (defaults to $CLOUSEAU_VSN)
6570
--skip-deps do not update erlang dependencies
6671
--rebar=PATH use rebar by specified path (version >=2.6.0 && <3.0 required)
6772
--rebar3=PATH use rebar3 by specified path
@@ -101,6 +106,12 @@ parse_opts() {
101106
continue
102107
;;
103108

109+
--enable-clouseau)
110+
WITH_CLOUSEAU=1
111+
shift
112+
continue
113+
;;
114+
104115
--erlang-md5)
105116
ERLANG_MD5="true"
106117
shift
@@ -202,6 +213,24 @@ parse_opts() {
202213
exit 1
203214
;;
204215

216+
--clouseau-version)
217+
if [ -n "$2" ]; then
218+
eval CLOUSEAU_SVN=$2
219+
shift 2
220+
continue
221+
else
222+
printf 'ERROR: "--clouseau-version" requires a non-empty argument.\n' >&2
223+
exit 1
224+
fi
225+
;;
226+
--clouseau-version=?*)
227+
eval CLOUSEAU_VSN=${1#*=}
228+
;;
229+
--clouseau-version=)
230+
printf 'ERROR: "--clouseau-version" requires a non-empty argument.\n' >&2
231+
exit 1
232+
;;
233+
205234
--) # End of options
206235
shift
207236
break
@@ -298,6 +327,7 @@ package_author_name = $PACKAGE_AUTHOR_NAME
298327
with_fauxton = $WITH_FAUXTON
299328
with_docs = $WITH_DOCS
300329
with_nouveau = $WITH_NOUVEAU
330+
with_clouseau = $WITH_CLOUSEAU
301331
302332
user = $COUCHDB_USER
303333
spidermonkey_version = $SM_VSN
@@ -345,6 +375,45 @@ install_local_erlfmt() {
345375
fi
346376
}
347377

378+
install_local_clouseau() {
379+
_DIST_URL=https://github.com/cloudant-labs/clouseau/releases/download/"$CLOUSEAU_VSN"/clouseau-"$CLOUSEAU_VSN"-dist.zip
380+
_MAVEN_BASE_URI=https://repo1.maven.org/maven2
381+
382+
_SLF4J_SIMPLE_VSN=${SLF4J_SIMPLE_VERSION:-1.7.36}
383+
_SLF4J_SIMPLE_JAR=slf4j-simple-"$_SLF4J_SIMPLE_VSN".jar
384+
_SLF4J_SIMPLE_URL="$_MAVEN_BASE_URI"/org/slf4j/slf4j-simple/"$_SLF4J_SIMPLE_VSN"/"$_SLF4J_SIMPLE_JAR"
385+
386+
rm -rf "$CLOUSEAU_DIR"
387+
mkdir -p "$CLOUSEAU_DIR"
388+
389+
if ! curl -sSL --max-redirs 1 -o clouseau.zip "$_DIST_URL"; then
390+
printf "ERROR: %s could not be downloaded.\n" "$_DIST_URL" >&2
391+
exit 1
392+
fi
393+
394+
if ! unzip -q -j clouseau.zip -d "$CLOUSEAU_DIR"; then
395+
printf "ERROR: Clouseau distribution package (clouseau.zip) could not be extracted.\n" >&2
396+
exit 1
397+
fi
398+
399+
rm clouseau.zip
400+
401+
if ! curl -sSL --max-redirs 1 -o "$CLOUSEAU_DIR"/"$_SLF4J_SIMPLE_JAR" "$_SLF4J_SIMPLE_URL"; then
402+
printf "ERROR: %s could not be downloaded.\n" "$_SLF4J_SIMPLE_URL" >&2
403+
exit 1
404+
fi
405+
406+
cat <<EOF > "$CLOUSEAU_DIR"/clouseau.ini
407+
[clouseau]
408+
EOF
409+
cat <<EOF > "$CLOUSEAU_DIR"/log4j.properties
410+
log4j.rootLogger=debug, CONSOLE
411+
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
412+
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
413+
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %c [%p] %m%n
414+
EOF
415+
}
416+
348417
if [ -z "${REBAR}" ]; then
349418
install_local_rebar
350419
REBAR=${rootdir}/bin/rebar
@@ -360,6 +429,12 @@ if [ -z "${ERLFMT}" ]; then
360429
ERLFMT=${rootdir}/bin/erlfmt
361430
fi
362431

432+
if [ $WITH_CLOUSEAU -ne 0 ]; then
433+
install_local_clouseau
434+
else
435+
rm -rf "$CLOUSEAU_DIR"
436+
fi
437+
363438
# only update dependencies, when we are not in a release tarball
364439
if [ -d .git -a $SKIP_DEPS -ne 1 ]; then
365440
echo "==> updating dependencies"

0 commit comments

Comments
 (0)