tree: a3c871308cc2444ba55e99340fd29ef2be2c926f [path history] [tgz]
  1. dubbo-scenario-builder/
  2. dubbo-test-runner/
  3. scripts/
  4. build-test-image-use-aliyun-mirror.sh
  5. build-test-image.sh
  6. convert-case.md
  7. kill-tests.sh
  8. pom.xml
  9. quick-start_cn.md
  10. README.md
  11. run-tests.sh
test/README.md

Dubbo Integration Test

Test steps

Follow the 3 steps below:

Step 1 - Build test image

Please install docker and docker-compose first, then build the test image.

cd dubbo-samples/test
./build-test-image.sh

Use a debian mirror through env DEBIAN_MIRROR if apt download files slowly, the following example uses aliyun mirror server http://mirrors.aliyun.com/ubuntu/ :

cd dubbo-samples/test
DEBIAN_MIRROR=http://mirrors.aliyun.com ./build-test-image.sh

Rebuild the image after modify any file of the dubbo-test-runner project.

Step 2 - Add case configuration

Add a case-configuration.yml to the tested project, for examples:

from: app-builtin-zookeeper.yml
props:
  project_name: dubbo-samples-annotation
  main_class: org.apache.dubbo.samples.annotation.AnnotationProviderBootstrap
  zookeeper_port: 2181
  dubbo_port: 20880

Some example projects:

Step 3 - Generate and test scenario

Run single test project:

cd dubbo-samples/test
./run-tests.sh <project.basedir>

Run all tests:

cd dubbo-samples/test
./run-tests.sh

Builtin parent configuration

Use from directive can import parent configuration, merge into current configuration.

Builtin parent configurations is in directory: test/dubbo-scenario-builder/src/main/resources/configs.

  • app-builtin-zookeeper.yml

    Applicable scenario: single dubbo provider application with builtin zookeeper and test case.

  • app-external-zookeeper.yml Applicable scenario: single dubbo provider application, external zookeeper and test case.

Examples:

  • dubbo-samples-annotation configuration:
from: app-builtin-zookeeper.yml
props:
  project_name: dubbo-samples-annotation
  main_class: org.apache.dubbo.samples.annotation.AnnotationProviderBootstrap
  zookeeper_port: 2181
  dubbo_port: 20880

project_name : project name of dubbo sample

main_class : main class of dubbo provider application

dubbo_port : dubbo provider service port

zookeeper_port : builtin zookeeper port

  • dubbo-samples-api configuration:
from: app-external-zookeeper.yml

props:
  project_name: dubbo-samples-api
  main_class: org.apache.dubbo.samples.provider.Application
  dubbo_port: 20880
  zookeeper_version: latest

zookeeper_version : external zookeeper version

External zookeeper service is a fixed port 2181, cause cannot change port unless expose it.

Case configuration details

Top level directives:

NameDescription
fromload parent case configuration, cover its props with current configration
propsInternal properties, automatically replace the current configuration or inherited configuration variables when parsing
servicesA set of app/test services or external services

Directives for dubbo service:

NameDescriptionDefaults
typeservice type: app - dubbo provider application; test- dubbo testcase
basedirproject basedir of app/test service. (current dir)
mainClassMain class of provider service, only for app service.
systemPropsset Java app system properties, automatically converted to jvm flags: -Dname=value
jvmFlagsmultiple jvm flags, automatically join as one string
waitPortsBeforeRunWait ports before run app/test
testsMatching test patterns, only for test service.

Service directives compatible with docker-compose:

NameDescriptionDefaults
imagedocker image name of containerapp/test service is implicitly set to dubbo/sample-test.
environment
depends_on
hostnamecontainer hostnameapp/test service is implicitly set to service id
volumescontainer mount pointsapp/test service automatically mounts directory: $basedir/target:/usr/local/dubbo/app
links
exposeexpose ports between containers
portsmapping ports to host os
entrypoint
healthcheck

Configuration example

app-external-zookeeper.yml includes :

  • External zookeeper
  • Dubbo provider application
  • Dubbo testcase

Note:

  • app/test service connect to zookeeper by system property zookeeper.address and zookeeper.port

  • wait zookeeper port before run dubbo provider application

  • wait zookeeper port and dubbo provider service port before run dubbo test

props:
#  project_name: dubbo-samples-xxx
#  main_class: org.apache.dubbo.samples.xxx.XxxProviderBootstrap
  dubbo_port: 20880
  zookeeper_version: latest

services:
  zookeeper:
    image: zookeeper:${zookeeper_version}

  ${project_name}:
    type: app
    basedir: .
    mainClass: ${main_class}
    systemProps:
      - zookeeper.address=zookeeper
      - zookeeper.port=2181
    waitPortsBeforeRun:
      - zookeeper:2181

  ${project_name}-test:
    type: test
    basedir: .
    tests:
      - "**/*IT.class"
    systemProps:
      - zookeeper.address=zookeeper
      - zookeeper.port=2181
    waitPortsBeforeRun:
      - zookeeper:2181
      - ${project_name}:${dubbo_port}
    depends_on:
      - ${project_name}

Some tricks

Scenario

A scenario is a complete test environment, including docker-compose.yml, scenario.sh, app classes, test classes and dependency jars. You can test the scenario separately, just run scenario.sh.

  • Scenario home

${scenario_home} default location is: ${project.basedir/target}.

App / test service automatically mounts directory: ${scenario_home}:/usr/local/dubbo/app

  • Scenario running timeout

Default running timeout is 90s. Some test cases require more time, you can modify it in the following way.

Change timeout in case-configuration.yml:

timeout: 120

Logs

  • Container log Container log location is: ${scenario_home}/logs/${serviceName}.log, include of dubbo app/test service and external service.

  • Scenario log
    Script scenario.sh log location: ${scenario_home}/logs/scenario.log.

  • Scenario builder log Scenario builder log location: $scenario_home/logs/scenario-builder.log

Test reports

The test reports is in directory: ${scenario_home}/test-reports

Fork run

The fork count is 2 by default, you can modify it by setting env FORK_COUNT=n. Increasing the fork count may cause the container to run very slowly, please set it according to the CPU/IO performance of the operating system.

FORK_COUNT=2 bash run-tests.sh

Fail-fast

Run tests in fail-fast mode, abort testing when any case is failed. It's useful when running tests in CI server, such as: Jenkins, Github actions. Default value: FAIL_FAST=0.

FAIL_FAST=1 bash run-tests.sh

Show error detail

Show log detail of failed testcase, including app log and test container log. It's useful when running tests in CI server, such as: Jenkins, Github actions. Default value: SHOW_ERROR_DETAIL=0.

SHOW_ERROR_DETAIL=1 bash run-tests.sh

Develop

dubbo-scenario-builder

Build dubbo test scenario, generating docker/docker-compose script files and start script files.

dubbo-test-runner

A Junit test runner, execute a set of testcases, replacement for maven-safefail-plugin. Also include files for dubbo-test-image.