From e30dc2df28b8d034871855e0b9f7d2a8b3d3829a Mon Sep 17 00:00:00 2001 From: salaboy Date: Mon, 5 Aug 2024 08:30:47 +0100 Subject: [PATCH 1/2] Initial Testcontainers integration for Dapr (#1085) * initial testcontainers pr Signed-off-by: salaboy * fixing variable reference Signed-off-by: salaboy * adding equals to spotbug issues Signed-off-by: salaboy * adding http port to run tests Signed-off-by: salaboy * updating pom Signed-off-by: salaboy * fixing style Signed-off-by: salaboy * extracting classes Signed-off-by: salaboy * removing restassured dependency Signed-off-by: salaboy * refactoring IT out to sdk-tests Signed-off-by: salaboy * adding correct wiremock dep version Signed-off-by: salaboy * missing header Signed-off-by: salaboy * fixing spotbugs issue Signed-off-by: salaboy * adding hashcode too Signed-off-by: salaboy * testing configure method Signed-off-by: salaboy * making inmutable collections and maps Signed-off-by: salaboy * checkstyle Signed-off-by: salaboy * removing space Signed-off-by: salaboy * Refactor tracking of alpha artifact version Signed-off-by: Artur Souza Signed-off-by: salaboy * Use Usage: docker compose [OPTIONS] COMMAND Define and run multi-container applications with Docker Options: --all-resources Include all resources, even those not used by services --ansi string Control when to print ANSI control characters ("never"|"always"|"auto") (default "auto") --compatibility Run compose in backward compatibility mode --dry-run Execute command in dry run mode --env-file stringArray Specify an alternate environment file -f, --file stringArray Compose configuration files --parallel int Control max parallelism, -1 for unlimited (default -1) --profile stringArray Specify a profile to enable --progress string Set type of progress output (auto, tty, plain, quiet) (default "auto") --project-directory string Specify an alternate working directory (default: the path of the, first specified, Compose file) -p, --project-name string Project name Commands: attach Attach local standard input, output, and error streams to a service's running container build Build or rebuild services config Parse, resolve and render compose file in canonical format cp Copy files/folders between a service container and the local filesystem create Creates containers for a service down Stop and remove containers, networks events Receive real time events from containers exec Execute a command in a running container images List images used by the created containers kill Force stop service containers logs View output from containers ls List running compose projects pause Pause services port Print the public port for a port binding ps List containers pull Pull service images push Push service images restart Restart service containers rm Removes stopped service containers run Run a one-off command on a service scale Scale services start Start services stats Display a live stream of container(s) resource usage statistics stop Stop services top Display the running processes unpause Unpause services up Create and start containers version Show the Docker Compose version information wait Block until the first service container stops watch Watch build context for service and rebuild/refresh containers when files are updated Run 'docker compose COMMAND --help' for more information on a command. instead of docker-compose Signed-off-by: Artur Souza Signed-off-by: salaboy * removing version from docker compose Signed-off-by: salaboy * Update README.md Signed-off-by: Artur Souza --------- Signed-off-by: salaboy Signed-off-by: Artur Souza Co-authored-by: Artur Souza --- .github/scripts/update_sdk_version.sh | 19 +- .github/workflows/build.yml | 2 +- README.md | 4 +- examples/pom.xml | 2 +- .../io/dapr/examples/bindings/http/README.md | 6 +- .../http/docker-compose-single-kafka.yml | 1 - .../io/dapr/examples/querystate/README.md | 4 +- .../docker-compose-single-mongo.yml | 1 - .../java/io/dapr/examples/state/README.md | 4 +- .../state/docker-compose-single-mongo.yml | 1 - pom.xml | 6 +- sdk-tests/pom.xml | 21 ++ .../it/testcontainers/DaprContainerTest.java | 162 +++++++++ testcontainers-dapr/pom.xml | 111 ++++++ .../io/dapr/testcontainers/Component.java | 83 +++++ .../io/dapr/testcontainers/DaprContainer.java | 341 ++++++++++++++++++ .../io/dapr/testcontainers/DaprLogLevel.java | 21 ++ .../DaprPlacementContainer.java | 75 ++++ .../io/dapr/testcontainers/DaprProtocol.java | 29 ++ .../io/dapr/testcontainers/MetadataEntry.java | 40 ++ .../io/dapr/testcontainers/Subscription.java | 52 +++ .../testcontainers/DaprComponentTest.java | 141 ++++++++ .../DaprPlacementContainerTest.java | 29 ++ .../resources/dapr-resources/statestore.yaml | 14 + 24 files changed, 1148 insertions(+), 21 deletions(-) create mode 100644 sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprContainerTest.java create mode 100644 testcontainers-dapr/pom.xml create mode 100644 testcontainers-dapr/src/main/java/io/dapr/testcontainers/Component.java create mode 100644 testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainer.java create mode 100644 testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprLogLevel.java create mode 100644 testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprPlacementContainer.java create mode 100644 testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprProtocol.java create mode 100644 testcontainers-dapr/src/main/java/io/dapr/testcontainers/MetadataEntry.java create mode 100644 testcontainers-dapr/src/main/java/io/dapr/testcontainers/Subscription.java create mode 100644 testcontainers-dapr/src/test/java/io/dapr/testcontainers/DaprComponentTest.java create mode 100644 testcontainers-dapr/src/test/java/io/dapr/testcontainers/DaprPlacementContainerTest.java create mode 100644 testcontainers-dapr/src/test/resources/dapr-resources/statestore.yaml diff --git a/.github/scripts/update_sdk_version.sh b/.github/scripts/update_sdk_version.sh index f51c33474..307a150c0 100755 --- a/.github/scripts/update_sdk_version.sh +++ b/.github/scripts/update_sdk_version.sh @@ -4,14 +4,23 @@ set -uex DAPR_JAVA_SDK_VERSION=$1 -# The workflows sdk tracks the regular SDK minor and patch versions, just not the major. -# Replaces the workflows SDK major version to 0 until it is stable. -DAPR_JAVA_WORKFLOWS_SDK_VERSION=`echo $DAPR_JAVA_SDK_VERSION | sed 's/^[0-9]*\./0./'` +# Alpha artifacts of the sdk tracks the regular SDK minor and patch versions, just not the major. +# Replaces the SDK major version to 0 for alpha artifacts. +DAPR_JAVA_SDK_ALPHA_VERSION=`echo $DAPR_JAVA_SDK_VERSION | sed 's/^[0-9]*\./0./'` mvn versions:set -DnewVersion=$DAPR_JAVA_SDK_VERSION +mvn versions:set-property -Dproperty=dapr.sdk.alpha.version -DnewVersion=$DAPR_JAVA_SDK_ALPHA_VERSION mvn versions:set-property -Dproperty=dapr.sdk.version -DnewVersion=$DAPR_JAVA_SDK_VERSION -f sdk-tests/pom.xml +mvn versions:set-property -Dproperty=dapr.sdk.alpha.version -DnewVersion=$DAPR_JAVA_SDK_ALPHA_VERSION -f sdk-tests/pom.xml -mvn versions:set -DnewVersion=$DAPR_JAVA_WORKFLOWS_SDK_VERSION -f sdk-workflows/pom.xml -mvn versions:set-property -Dproperty=dapr.sdk-workflows.version -DnewVersion=$DAPR_JAVA_WORKFLOWS_SDK_VERSION +################### +# Alpha artifacts # +################### + +# sdk-workflows +mvn versions:set -DnewVersion=$DAPR_JAVA_SDK_ALPHA_VERSION -f sdk-workflows/pom.xml + +# testcontainers-dapr +mvn versions:set -DnewVersion=$DAPR_JAVA_SDK_ALPHA_VERSION -f testcontainers-dapr/pom.xml git clean -f diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4585d41bf..44077e121 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -99,7 +99,7 @@ jobs: ./dist/linux_amd64/release/placement & - name: Spin local environment run: | - docker-compose -f ./sdk-tests/deploy/local-test.yml up -d mongo kafka + docker compose -f ./sdk-tests/deploy/local-test.yml up -d mongo kafka docker ps - name: Install local ToxiProxy to simulate connectivity issues to Dapr sidecar run: | diff --git a/README.md b/README.md index 9c0efdd5d..ece881458 100644 --- a/README.md +++ b/README.md @@ -237,13 +237,13 @@ Similarly, all of these need to be run for running the ITs either individually o Run the following commands from the root of the repo to start all the docker containers that the tests depend on. ```bash -docker-compose -f ./sdk-tests/deploy/local-test.yml up -d +docker compose -f ./sdk-tests/deploy/local-test.yml up -d ``` To stop the containers and services, run the following commands. ```bash -docker-compose -f ./sdk-tests/deploy/local-test.yml down +docker compose -f ./sdk-tests/deploy/local-test.yml down ``` diff --git a/examples/pom.xml b/examples/pom.xml index ea8d5dda7..566c76504 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -113,7 +113,7 @@ io.dapr dapr-sdk-workflows - ${dapr.sdk-workflows.version} + ${dapr.sdk.alpha.version} io.dapr diff --git a/examples/src/main/java/io/dapr/examples/bindings/http/README.md b/examples/src/main/java/io/dapr/examples/bindings/http/README.md index ad529013e..cd9ce4206 100644 --- a/examples/src/main/java/io/dapr/examples/bindings/http/README.md +++ b/examples/src/main/java/io/dapr/examples/bindings/http/README.md @@ -58,13 +58,11 @@ Before getting into the application code, follow these steps in order to set up ```bash -docker-compose -f ./src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml up -d +docker compose -f ./src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml up -d ``` @@ -248,7 +246,7 @@ name: Cleanup Kafka containers --> ```bash -docker-compose -f ./src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml down +docker compose -f ./src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml down ``` diff --git a/examples/src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml b/examples/src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml index bf60826b1..949adf234 100644 --- a/examples/src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml +++ b/examples/src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml @@ -1,4 +1,3 @@ -version: '3' services: zookeeper: image: confluentinc/cp-zookeeper:7.4.4 diff --git a/examples/src/main/java/io/dapr/examples/querystate/README.md b/examples/src/main/java/io/dapr/examples/querystate/README.md index 2b25909e9..2b5320cd1 100644 --- a/examples/src/main/java/io/dapr/examples/querystate/README.md +++ b/examples/src/main/java/io/dapr/examples/querystate/README.md @@ -44,7 +44,7 @@ sleep: 5 --> ```bash -docker-compose -f ./src/main/java/io/dapr/examples/querystate/docker-compose-single-mongo.yml up -d +docker compose -f ./src/main/java/io/dapr/examples/querystate/docker-compose-single-mongo.yml up -d ``` @@ -305,7 +305,7 @@ name: Cleanup MongoDB containers --> ```bash -docker-compose -f ./src/main/java/io/dapr/examples/querystate/docker-compose-single-mongo.yml down +docker compose -f ./src/main/java/io/dapr/examples/querystate/docker-compose-single-mongo.yml down ``` diff --git a/examples/src/main/java/io/dapr/examples/querystate/docker-compose-single-mongo.yml b/examples/src/main/java/io/dapr/examples/querystate/docker-compose-single-mongo.yml index bb17176df..a75004c36 100644 --- a/examples/src/main/java/io/dapr/examples/querystate/docker-compose-single-mongo.yml +++ b/examples/src/main/java/io/dapr/examples/querystate/docker-compose-single-mongo.yml @@ -1,4 +1,3 @@ -version: '3' services: mongo: image: mongo diff --git a/examples/src/main/java/io/dapr/examples/state/README.md b/examples/src/main/java/io/dapr/examples/state/README.md index 89c41d952..6038db8fb 100644 --- a/examples/src/main/java/io/dapr/examples/state/README.md +++ b/examples/src/main/java/io/dapr/examples/state/README.md @@ -44,7 +44,7 @@ sleep: 5 --> ```bash -docker-compose -f ./src/main/java/io/dapr/examples/state/docker-compose-single-mongo.yml up -d +docker compose -f ./src/main/java/io/dapr/examples/state/docker-compose-single-mongo.yml up -d ``` @@ -227,7 +227,7 @@ name: Cleanup MongoDB container --> ```bash -docker-compose -f ./src/main/java/io/dapr/examples/state/docker-compose-single-mongo.yml down +docker compose -f ./src/main/java/io/dapr/examples/state/docker-compose-single-mongo.yml down ``` diff --git a/examples/src/main/java/io/dapr/examples/state/docker-compose-single-mongo.yml b/examples/src/main/java/io/dapr/examples/state/docker-compose-single-mongo.yml index bb17176df..a75004c36 100644 --- a/examples/src/main/java/io/dapr/examples/state/docker-compose-single-mongo.yml +++ b/examples/src/main/java/io/dapr/examples/state/docker-compose-single-mongo.yml @@ -1,4 +1,3 @@ -version: '3' services: mongo: image: mongo diff --git a/pom.xml b/pom.xml index 64d9772df..7dc17a866 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ 1.59.0 3.17.3 https://raw.githubusercontent.com/dapr/dapr/v1.13.0-rc.5/dapr/proto - 0.12.0-SNAPSHOT + 0.12.0-SNAPSHOT 1.6.2 3.1.1 1.8 @@ -38,6 +38,8 @@ 3.2.2 3.2.2 5.8.2 + 2.0 + 1.20.0 @@ -330,6 +332,8 @@ sdk-workflows sdk-springboot examples + + testcontainers-dapr