diff --git a/README.txt b/README.txt index 9808c01..4d94e1d 100644 --- a/README.txt +++ b/README.txt @@ -11,7 +11,7 @@ work, but rather as a set of reference projects for the book. Points of Interest ------------------- +================== The iddd_agilepm project uses a key-value store as its underlying persistence mechanism, and in particular @@ -53,8 +53,46 @@ liter each project. This is not a recommendation, but it did work well and save a considerable amount of work while producing the samples. +Usage +===== + +Requires +-------- + +- Java 7 (8+ does not work) +- MySQL Client + Server +- RabbitMQ + +Setup (with Docker) +------------------- + +To make it easy to run the tests and it requirements, +the `startContainers.sh` script is provided. Which +will start a: +- MySQL Server container +- RabbitMQ Server container +- RabbitMQ Management container + +If the `mysql` command is available, which is the mysql client, +also the required SQL scripts will be imported into the MySQL +Server. + +If you use the `startContainers.sh` script, you don't need +MySQL Server and RabbitMQ installed locally. Instead, +Docker needs to be installed as the script will start +MySQL and RabbitMQ in Docker containers. + Build ------ + +You can build the project by running: + +``` +./gradlew build +``` + +This automatically downloads Gradle and builds the project, including running the tests. + The Gradle build using Maven repositories was provided by Michael Andrews (Github michaelajr and Twitter @MichaelAJr). Thanks much! diff --git a/iddd_common/src/main/mysql/common.sql b/iddd_common/src/main/mysql/common.sql index d74d93c..991f570 100644 --- a/iddd_common/src/main/mysql/common.sql +++ b/iddd_common/src/main/mysql/common.sql @@ -7,6 +7,8 @@ -- ============================================================= -- ============================================================= +USE iddd_common_test; + CREATE TABLE `tbl_es_event_store` ( `event_id` bigint(20) NOT NULL auto_increment, `event_body` varchar(65000) NOT NULL, diff --git a/startContainers.sh b/startContainers.sh new file mode 100755 index 0000000..c2bcc34 --- /dev/null +++ b/startContainers.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +host="0.0.0.0" + +mysqlUser="root" +mysqlPassword="root" +mysqlContainerName="iddd-mysql" +mysqlPort="3306" + +rabbitmqNodeName="$(hostname)" +rabbitmqContainerName="iddd-rabbitmq" +rabbitmqManagementHttpPort="8080" + +containers[0]="${mysqlContainerName}" +containers[1]="${rabbitmqContainerName}" + +function start() { + echo "Starting MySQL Server container..." + docker rm -f "${mysqlContainerName}" + docker run --name "${mysqlContainerName}" -p "${mysqlPort}":3306 -e MYSQL_ROOT_PASSWORD="${mysqlPassword}" -d mysql + + echo "Waiting for MySQL Server to be up and running..." + waitForContainer "${mysqlContainerName}" "mysqld: ready for connections." + + local testSqlFiles="$(find $(pwd) -name *.sql | grep -i "test")" + local sqlFiles="$(find $(pwd) -name *.sql | grep -vi "test")" + if which mysql > /dev/null; then + for sql in ${testSqlFiles}; do + echo "Importing [${sql}]" + $(mysql --host="${host}" --port=3306 --protocol=TCP --user="${mysqlUser}" --password="${mysqlPassword}" < ${sql}) + done + for sql in ${sqlFiles}; do + echo "Importing [${sql}]" + $(mysql --host="${host}" --port=3306 --protocol=TCP --user="${mysqlUser}" --password="${mysqlPassword}" < ${sql}) + done + else + echo -e + echo "!! mysql command not found" + echo "!! You need to import the following SQL files into MySQL Server, yourself:" + for sql in ${testSqlFiles}; do + echo ${sql} + done + for sql in ${sqlFiles}; do + echo ${sql} + done + echo -e + echo "You can find MySQL Server on [localhost] port [${mysqlPort}]" + echo -e + read -rsp "Press any key to continue..." + echo -e + fi + + echo "Starting RabbitMQ container..." + docker rm -f "${rabbitmqContainerName}" + docker run --name "${rabbitmqContainerName}" -p 5672:5672 -p "${rabbitmqManagementHttpPort}":15672 -e RABBITMQ_NODENAME="${rabbitmqNodeName}" -d rabbitmq:3-management + echo "Waiting for RabbitMQ to be up and running..." + waitForContainer "${rabbitmqContainerName}" "Server startup complete;" + + echo -e + echo "RabbitMQ Management available at [http://localhost:${rabbitmqManagementHttpPort}]" + echo "(Login with user/pass of [guest/guest])" +} + +function status() { + docker ps -a | head -1 + for name in ${containers[@]}; do + docker ps -a | grep "${name}" + done +} + +function stop() { + for name in ${containers[@]}; do + echo "Stopping container [${name}]..." + docker stop "${name}" > /dev/null 2>&1 + done +} + +function usage() { + echo "Usage: $(basename $0) []" + echo -e + echo "Available commands:" + echo " start Start external dependencies for this project in Docker containers" + echo " (incl. MySQL Server and RabbitMQ)" + echo " stop Stop the Docker containers" + echo -e +} + +function requires() { + local command=$1 + which ${command} > /dev/null 2>&1 || { echo "!! This script requires [${command}] to be installed" && exit 1; } +} + +function waitForContainer() { + local containerName="$1" + local logMsg="$2" + until docker logs ${containerName} 2>&1 | grep "${logMsg}" > /dev/null; do + sleep 1s + done +} + + +requires 'docker' + +command=$1; shift +case "${command}" in + start) + start + ;; + stop) + stop + ;; + status) + status + ;; + *) + usage + exit 1 + ;; +esac