Giter VIP home page Giter VIP logo

testing-with-containers's Introduction

Testing with Containers

Workshop exercises -> here

This is a sample project for the Testing with Containers workshop. It contains two sample applications, one is a reference implementation using Testcontainers' generic containers to orchestrate the todo-list-gateway setup and the docker compose containers to start a more complex environment for the tests.

Software requirements to run the samples are maven, openjdk-1.8 (or any other 1.8 JDK) and docker. When running the Maven lifecycleit will create the war package and use the liberty-maven-plugin to create a runnable jar (fatjar) which contains thetodo-service and the Open Liberty application server. The fatjar will be copied into a Docker image using Spotify's dockerfile-maven-plugin during the package phase.

How to run

Before running the application it needs to be compiled and packaged using Maven. It creates the required war, jar and Docker image and can be run todo-list-service together with its required database via docker-compose:

$ cd todo-list/todo-list-service
$ mvn clean package
$ docker-compose up

When changing code you must re-run the package process and start docker-compose with the additional build parameter to ensure that both the application and the Docker image is up-to-date:

$ mvn clean package
$ docker-compose up --build

Wait for a message log similar to this:

service_1 | [3/5/20 16:36:02:145 UTC] 0000001b id= com.ibm.ws.kernel.feature.internal.FeatureManager A CWWKF0011I: The defaultServer server is ready to run a smarter planet. The defaultServer server started in 13.006 seconds.

If everything worked you can access the Swagger ui via http://localhost:9080/openapi/ui.

To run the todo-list-gateway you need to start it manually via Docker after building it:

$ cd todo-list/todo-list-gateway
$ mvn clean package
$ docker run --rm -p 19080:19080 testing-with-containers/todo-list-gateway:0

Both examples may require sudo on Linux machines.

Resolving issues

Sometimes it may happen that the containers did not stop as expected when trying to stop the pipeline early. This may result in running containers although they should have been stopped and removed. To detect them you need to check Docker:

$ docker ps -a | grep testing-with-containers

If there are containers remaining although the application has been stopped you can remove them:

$ docker rm <ids of the containers>

Remarks on the code

There are two samples, hello-world which is a minimal project intended for the exercises. The second project todo-list contains two services: todo-list-gateway and todo-list-service. The gateway is a service which relays incoming requests to the todo-list-service. It represents a backend for frontend. Its target url for the service is configured in the src/main/resources/META-INF/microprofile-config.properties. The todo-list-service contains a MicroProfile-based project that provides a REST interface to interact with. It can list, create, update and delete to-dos which are saved in an external PostgreSQL database.

testing-with-containers's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

cwansart

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.