SlideShare a Scribd company logo
1 of 30
Download to read offline
Integration testing with Docker Compose and JUnit
Dariusz Lorenc
Boris Kravtsov
Pivotal Labs
Problem
End-2-end test of GemFire in various cluster configurations
and with different failover scenarios
GemFire
GemFire is a distributed, in-memory database with strong data
consistency, built to support transactional applications with low latency
and high concurrency needs
GemFire Server
GemFire
GemFire Server GemFire Server
Partitioned
Data
Partitioned
Data
Partitioned
Data
GemFire ServerGemFire Server GemFire Server
Partitioned
Data
Partitioned
Data
Partitioned
Data
Client
WAN / Multi-Site
Gateway Hub
Gateway Hub
Relational Database
Docker Compose to the rescue
Docker Compose is a tool for defining and running multi-container
Docker applications
Docker Compose JUnit Rule
A JUnit rule to manage docker containers using docker-compose
• Start and stop docker-compose multi-container applications
• Waits for services to become available before running tests
• Extends logging and debugging
https://github.com/palantir/docker-compose-rule
GreetingCounter
Master
Our Sample Distributed System
Test First - Happy Path
@Test

public void shouldReturnData(){

get("/info")

.then().assertThat()

.body("counter", isA(Number.class))

.body("greeting", is("Hello World"));

}
Spring Boot - Application.kt
@SpringBootApplication
open class Application {
companion object {
@JvmStatic fun main(args: Array<String>) {
SpringApplication.run(Application::class.java,
*args)
}
}
}
Greeting Service
@RestController

class Controller {



@RequestMapping("/greeting")

fun greet(): Greeting {

return Greeting("Hello World")

}

}
data class Greeting(val greeting: String)
Counter Service
@RestController

class Controller {



val counter = AtomicLong()



@RequestMapping("/counter")

fun count(): Counter {

return Counter(counter.incrementAndGet())

}

}
data class Counter(val counter: Long)
Master Service
@RestController

class Controller @Autowired constructor(
val greetingClient: GreetingClient,

val counterClient: CounterClient) {



@RequestMapping("/info")

fun info(): Response {

return Response(counterClient.counter().counter,

greetingClient.greeting().greeting)

}

}
data class Response(val counter: Long, val greeting: String)
Master Service - Greeting Client
@FeignClient(name = "greeting",
url = "http://greeting-service:8080")

interface GreetingClient {


@RequestMapping(value = "/greeting",
method = arrayOf(RequestMethod.GET))

fun greeting(): Greeting

}
Master Service - Counter Client
@FeignClient(name = "counter",
url = "http://counter-service:8080")

interface CounterClient {


@RequestMapping(value = “/counter”,
method = arrayOf(RequestMethod.GET))

fun counter(): Counter

}
GreetingCounter
Master
Next Step: Dockerize Our Services
Dockerfiles
FROM frolvlad/alpine-oraclejdk8:slim
ADD master-service-1.0.0.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
Base image
Add the app’s fat jar
Expose the port
Start the java app
Build Docker Image with Gradle (Transmodo plugin)
buildscript {
dependencies {
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
group = '<your docker group name>'
apply plugin: 'docker'
task buildDocker(type: Docker, dependsOn: build) {
push = true
applicationName = jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
Gradle Docker plugin
Your Docker Hub ID
Build Docker task
GreetingCounter
Master
GreetingCount
“Docker Composed” Services
Docker Compose
docker-compose.yml
Greeting
Counter
Master
greeting-service:
image: lorenc/greeting-service
ports:
- “8081:8080"
counter-service:
image: lorenc/counter-service
ports:
- "8082:8080"
master-service:
image: lorenc/master-service
ports:
- "8083:8080"
links:
- greeting-service
- counter-service
Integration Test Setup
@Rule

public DockerComposeRule docker = DockerComposeRule.builder()

.file("../docker-compose.yml")

.build();
@Before

public void setUp() throws Exception {

docker.dockerCompose().up();

}



@After

public void tearDown() throws Exception {

docker.dockerCompose().down();

}
Health Checks & Logs
@Rule

public DockerComposeRule docker = DockerComposeRule.builder()

.file("../docker-compose.yml")

.waitingForService("greeting-service",
toRespondOverHttp(8080, TO_EXTERNAL_URI))

.waitingForService("counter-service",
toRespondOverHttp(8080, TO_EXTERNAL_URI))

.waitingForService("master-service",
toRespondOverHttp(8080, TO_EXTERNAL_URI))

.saveLogsTo("build/docker-logs")

.build();
What could possibly go wrong?
@Test

public void shouldReturnHolaWhenGreetingServiceDown(){

docker.dockerCompose().container("greeting-service").stop();



get("/info")

.then().assertThat()

.body("greeting", is("Hola!"));

}
What could possibly go wrong?
@Test

public void shouldReturn42WhenCounterServiceDown() {

docker.dockerCompose().container("counter-service").stop();



get("/info")

.then().assertThat()

.body("counter", is(42));

}
@FeignClient(name = "greeting",
url = "http://greeting-service:8080",
fallback = DefaultGreeting::class)

interface GreetingClient {


@RequestMapping(value = "/greeting",
method = arrayOf(RequestMethod.GET))

fun greeting(): Greeting

}
@Component

class DefaultGreeting : GreetingClient {

override fun greeting(): Greeting {

return Greeting("Hola!")

}

}
Master Service - Greeting Client
Master Service - Counter Client
@FeignClient(name = "counter",
url = "http://counter-service:8080",
fallback = DefaultCounter::class)

interface CounterClient {


@RequestMapping(value = “/counter”,
method = arrayOf(RequestMethod.GET))

fun counter(): Counter

}
@Component

class DefaultCounter : CounterClient {

override fun counter(): Counter {

return Counter(42)

}

}
Demo
References
https://github.com/d-lorenc/junit-docker-demo
https://github.com/palantir/docker-compose-rule
Testing Distributed Microservices with Docker Compose and JUnit

More Related Content

What's hot

Sharing is Caring: Toward Creating Self-tuning Multi-tenant Kafka (Anna Povzn...
Sharing is Caring: Toward Creating Self-tuning Multi-tenant Kafka (Anna Povzn...Sharing is Caring: Toward Creating Self-tuning Multi-tenant Kafka (Anna Povzn...
Sharing is Caring: Toward Creating Self-tuning Multi-tenant Kafka (Anna Povzn...HostedbyConfluent
 
Microservices with Node and Docker
Microservices with Node and DockerMicroservices with Node and Docker
Microservices with Node and DockerTony Pujals
 
Application Deployment and Management at Scale at 1&1
Application Deployment and Management at Scale at 1&1Application Deployment and Management at Scale at 1&1
Application Deployment and Management at Scale at 1&1Matt Baldwin
 
GWT Enterprise Edition
GWT Enterprise EditionGWT Enterprise Edition
GWT Enterprise EditionGilad Garon
 
[OpenInfra Days Korea 2018] Day 2 - E4 - 핸즈온 워크샵: 서버리스가 컨테이너를 만났을 때
[OpenInfra Days Korea 2018] Day 2 - E4 - 핸즈온 워크샵: 서버리스가 컨테이너를 만났을 때 [OpenInfra Days Korea 2018] Day 2 - E4 - 핸즈온 워크샵: 서버리스가 컨테이너를 만났을 때
[OpenInfra Days Korea 2018] Day 2 - E4 - 핸즈온 워크샵: 서버리스가 컨테이너를 만났을 때 OpenStack Korea Community
 
Running Projects in Application Containers, System Containers & VMs - Jelasti...
Running Projects in Application Containers, System Containers & VMs - Jelasti...Running Projects in Application Containers, System Containers & VMs - Jelasti...
Running Projects in Application Containers, System Containers & VMs - Jelasti...Jelastic Multi-Cloud PaaS
 
Building WebLogic Domains With WLST
Building WebLogic Domains With WLSTBuilding WebLogic Domains With WLST
Building WebLogic Domains With WLSTC2B2 Consulting
 
Deploying Flink on Kubernetes - David Anderson
 Deploying Flink on Kubernetes - David Anderson Deploying Flink on Kubernetes - David Anderson
Deploying Flink on Kubernetes - David AndersonVerverica
 
Oops! I started a broker | Yinon Kahta, Taboola
Oops! I started a broker | Yinon Kahta, TaboolaOops! I started a broker | Yinon Kahta, Taboola
Oops! I started a broker | Yinon Kahta, TaboolaHostedbyConfluent
 
How Apache Kafka® Works
How Apache Kafka® WorksHow Apache Kafka® Works
How Apache Kafka® Worksconfluent
 
Cloud Foundry for Spring Developers
Cloud Foundry for Spring DevelopersCloud Foundry for Spring Developers
Cloud Foundry for Spring DevelopersGunnar Hillert
 
Optimizing {Java} Application Performance on Kubernetes
Optimizing {Java} Application Performance on KubernetesOptimizing {Java} Application Performance on Kubernetes
Optimizing {Java} Application Performance on KubernetesDinakar Guniguntala
 
JavaEdge 2008: Your next version control system
JavaEdge 2008: Your next version control systemJavaEdge 2008: Your next version control system
JavaEdge 2008: Your next version control systemGilad Garon
 
Migration of an Enterprise UI Microservice System from Cloud Foundry to Kuber...
Migration of an Enterprise UI Microservice System from Cloud Foundry to Kuber...Migration of an Enterprise UI Microservice System from Cloud Foundry to Kuber...
Migration of an Enterprise UI Microservice System from Cloud Foundry to Kuber...Tony Erwin
 
ElasticKube, a Container Management Platform for Kubernetes
ElasticKube, a Container Management Platform for KubernetesElasticKube, a Container Management Platform for Kubernetes
ElasticKube, a Container Management Platform for KubernetesMatt Baldwin
 
Kubernetes deployment strategies - CNCF Webinar
Kubernetes deployment strategies - CNCF WebinarKubernetes deployment strategies - CNCF Webinar
Kubernetes deployment strategies - CNCF WebinarEtienne Tremel
 
Deep Dive into Kubernetes - Part 1
Deep Dive into Kubernetes - Part 1Deep Dive into Kubernetes - Part 1
Deep Dive into Kubernetes - Part 1Imesh Gunaratne
 
Kubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewKubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewBob Killen
 

What's hot (20)

Sharing is Caring: Toward Creating Self-tuning Multi-tenant Kafka (Anna Povzn...
Sharing is Caring: Toward Creating Self-tuning Multi-tenant Kafka (Anna Povzn...Sharing is Caring: Toward Creating Self-tuning Multi-tenant Kafka (Anna Povzn...
Sharing is Caring: Toward Creating Self-tuning Multi-tenant Kafka (Anna Povzn...
 
Microservices with Node and Docker
Microservices with Node and DockerMicroservices with Node and Docker
Microservices with Node and Docker
 
Application Deployment and Management at Scale at 1&1
Application Deployment and Management at Scale at 1&1Application Deployment and Management at Scale at 1&1
Application Deployment and Management at Scale at 1&1
 
GWT Enterprise Edition
GWT Enterprise EditionGWT Enterprise Edition
GWT Enterprise Edition
 
[OpenInfra Days Korea 2018] Day 2 - E4 - 핸즈온 워크샵: 서버리스가 컨테이너를 만났을 때
[OpenInfra Days Korea 2018] Day 2 - E4 - 핸즈온 워크샵: 서버리스가 컨테이너를 만났을 때 [OpenInfra Days Korea 2018] Day 2 - E4 - 핸즈온 워크샵: 서버리스가 컨테이너를 만났을 때
[OpenInfra Days Korea 2018] Day 2 - E4 - 핸즈온 워크샵: 서버리스가 컨테이너를 만났을 때
 
Running Projects in Application Containers, System Containers & VMs - Jelasti...
Running Projects in Application Containers, System Containers & VMs - Jelasti...Running Projects in Application Containers, System Containers & VMs - Jelasti...
Running Projects in Application Containers, System Containers & VMs - Jelasti...
 
Building WebLogic Domains With WLST
Building WebLogic Domains With WLSTBuilding WebLogic Domains With WLST
Building WebLogic Domains With WLST
 
Deploying Flink on Kubernetes - David Anderson
 Deploying Flink on Kubernetes - David Anderson Deploying Flink on Kubernetes - David Anderson
Deploying Flink on Kubernetes - David Anderson
 
Oops! I started a broker | Yinon Kahta, Taboola
Oops! I started a broker | Yinon Kahta, TaboolaOops! I started a broker | Yinon Kahta, Taboola
Oops! I started a broker | Yinon Kahta, Taboola
 
Deploying a secured Flink cluster on Kubernetes
Deploying a secured Flink cluster on KubernetesDeploying a secured Flink cluster on Kubernetes
Deploying a secured Flink cluster on Kubernetes
 
How Apache Kafka® Works
How Apache Kafka® WorksHow Apache Kafka® Works
How Apache Kafka® Works
 
Cloud Foundry for Spring Developers
Cloud Foundry for Spring DevelopersCloud Foundry for Spring Developers
Cloud Foundry for Spring Developers
 
Optimizing {Java} Application Performance on Kubernetes
Optimizing {Java} Application Performance on KubernetesOptimizing {Java} Application Performance on Kubernetes
Optimizing {Java} Application Performance on Kubernetes
 
JavaEdge 2008: Your next version control system
JavaEdge 2008: Your next version control systemJavaEdge 2008: Your next version control system
JavaEdge 2008: Your next version control system
 
Migration of an Enterprise UI Microservice System from Cloud Foundry to Kuber...
Migration of an Enterprise UI Microservice System from Cloud Foundry to Kuber...Migration of an Enterprise UI Microservice System from Cloud Foundry to Kuber...
Migration of an Enterprise UI Microservice System from Cloud Foundry to Kuber...
 
Camunda and Apache Cassandra
Camunda and Apache CassandraCamunda and Apache Cassandra
Camunda and Apache Cassandra
 
ElasticKube, a Container Management Platform for Kubernetes
ElasticKube, a Container Management Platform for KubernetesElasticKube, a Container Management Platform for Kubernetes
ElasticKube, a Container Management Platform for Kubernetes
 
Kubernetes deployment strategies - CNCF Webinar
Kubernetes deployment strategies - CNCF WebinarKubernetes deployment strategies - CNCF Webinar
Kubernetes deployment strategies - CNCF Webinar
 
Deep Dive into Kubernetes - Part 1
Deep Dive into Kubernetes - Part 1Deep Dive into Kubernetes - Part 1
Deep Dive into Kubernetes - Part 1
 
Kubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewKubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive Overview
 

Viewers also liked

Integration Testing with Docker Containers with DockerCompose
Integration Testing with Docker Containers  with DockerComposeIntegration Testing with Docker Containers  with DockerCompose
Integration Testing with Docker Containers with DockerComposeMike Holdsworth
 
Efficient Parallel Testing with Docker
Efficient Parallel Testing with DockerEfficient Parallel Testing with Docker
Efficient Parallel Testing with DockerLaura Frank Tacho
 
Docker for (Java) Developers
Docker for (Java) DevelopersDocker for (Java) Developers
Docker for (Java) DevelopersRafael Benevides
 
信息系统架构设计
信息系统架构设计信息系统架构设计
信息系统架构设计Weijun Zhong
 
不断归零的前端人生 - 2016 中国软件开发者大会
不断归零的前端人生 - 2016 中国软件开发者大会不断归零的前端人生 - 2016 中国软件开发者大会
不断归零的前端人生 - 2016 中国软件开发者大会Joseph Chiang
 
淺談 Geb 網站自動化測試(JCConf 2014)
淺談 Geb 網站自動化測試(JCConf 2014)淺談 Geb 網站自動化測試(JCConf 2014)
淺談 Geb 網站自動化測試(JCConf 2014)Kyle Lin
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entityToni Jara
 
需求分析及相关技术
需求分析及相关技术需求分析及相关技术
需求分析及相关技术Weijun Zhong
 
Docker初识
Docker初识Docker初识
Docker初识hubugui
 
Efficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura FrankEfficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura FrankDocker, Inc.
 
Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016Adrian Cockcroft
 
Agile Transformation and Cultural Change
 Agile Transformation and Cultural Change Agile Transformation and Cultural Change
Agile Transformation and Cultural ChangeJohnny Ordóñez
 
The hardest part of microservices: your data
The hardest part of microservices: your dataThe hardest part of microservices: your data
The hardest part of microservices: your dataChristian Posta
 
Testing web services
Testing web servicesTesting web services
Testing web servicesTaras Lytvyn
 

Viewers also liked (14)

Integration Testing with Docker Containers with DockerCompose
Integration Testing with Docker Containers  with DockerComposeIntegration Testing with Docker Containers  with DockerCompose
Integration Testing with Docker Containers with DockerCompose
 
Efficient Parallel Testing with Docker
Efficient Parallel Testing with DockerEfficient Parallel Testing with Docker
Efficient Parallel Testing with Docker
 
Docker for (Java) Developers
Docker for (Java) DevelopersDocker for (Java) Developers
Docker for (Java) Developers
 
信息系统架构设计
信息系统架构设计信息系统架构设计
信息系统架构设计
 
不断归零的前端人生 - 2016 中国软件开发者大会
不断归零的前端人生 - 2016 中国软件开发者大会不断归零的前端人生 - 2016 中国软件开发者大会
不断归零的前端人生 - 2016 中国软件开发者大会
 
淺談 Geb 網站自動化測試(JCConf 2014)
淺談 Geb 網站自動化測試(JCConf 2014)淺談 Geb 網站自動化測試(JCConf 2014)
淺談 Geb 網站自動化測試(JCConf 2014)
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
 
需求分析及相关技术
需求分析及相关技术需求分析及相关技术
需求分析及相关技术
 
Docker初识
Docker初识Docker初识
Docker初识
 
Efficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura FrankEfficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura Frank
 
Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016Microservices Workshop All Topics Deck 2016
Microservices Workshop All Topics Deck 2016
 
Agile Transformation and Cultural Change
 Agile Transformation and Cultural Change Agile Transformation and Cultural Change
Agile Transformation and Cultural Change
 
The hardest part of microservices: your data
The hardest part of microservices: your dataThe hardest part of microservices: your data
The hardest part of microservices: your data
 
Testing web services
Testing web servicesTesting web services
Testing web services
 

Similar to Testing Distributed Microservices with Docker Compose and JUnit

Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year laterChristian Ortner
 
Deploying configurable frontend web application containers
Deploying configurable frontend web application containersDeploying configurable frontend web application containers
Deploying configurable frontend web application containersJosé Moreira
 
Nats meetup oct 2016 docker 112
Nats meetup oct 2016 docker 112Nats meetup oct 2016 docker 112
Nats meetup oct 2016 docker 112Nirmal Mehta
 
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Patrick Chanezon
 
Clojure and the Web
Clojure and the WebClojure and the Web
Clojure and the Webnickmbailey
 
Configuration Management and Transforming Legacy Applications in the Enterpri...
Configuration Management and Transforming Legacy Applications in the Enterpri...Configuration Management and Transforming Legacy Applications in the Enterpri...
Configuration Management and Transforming Legacy Applications in the Enterpri...Docker, Inc.
 
Container orchestration from theory to practice
Container orchestration from theory to practiceContainer orchestration from theory to practice
Container orchestration from theory to practiceDocker, Inc.
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Roberto Franchini
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleSkills Matter
 
Docker for developers z java
Docker for developers z javaDocker for developers z java
Docker for developers z javaandrzejsydor
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extremeyinonavraham
 
Docker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalDocker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalPatrick Chanezon
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeDanielle Madeley
 
Docker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesDocker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesSreenivas Makam
 
Practical Design Patterns in Docker Networking
Practical Design Patterns in Docker NetworkingPractical Design Patterns in Docker Networking
Practical Design Patterns in Docker NetworkingDocker, Inc.
 
Containerised Testing at Demonware : PyCon Ireland 2016
Containerised Testing at Demonware : PyCon Ireland 2016Containerised Testing at Demonware : PyCon Ireland 2016
Containerised Testing at Demonware : PyCon Ireland 2016Thomas Shaw
 
Building Web Scale Apps with Docker and Mesos by Alex Rukletsov (Mesosphere)
Building Web Scale Apps with Docker and Mesos by Alex Rukletsov (Mesosphere)Building Web Scale Apps with Docker and Mesos by Alex Rukletsov (Mesosphere)
Building Web Scale Apps with Docker and Mesos by Alex Rukletsov (Mesosphere)Docker, Inc.
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationBen Hall
 

Similar to Testing Distributed Microservices with Docker Compose and JUnit (20)

Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year later
 
Deploying configurable frontend web application containers
Deploying configurable frontend web application containersDeploying configurable frontend web application containers
Deploying configurable frontend web application containers
 
Nats meetup oct 2016 docker 112
Nats meetup oct 2016 docker 112Nats meetup oct 2016 docker 112
Nats meetup oct 2016 docker 112
 
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
 
Clojure and the Web
Clojure and the WebClojure and the Web
Clojure and the Web
 
Configuration Management and Transforming Legacy Applications in the Enterpri...
Configuration Management and Transforming Legacy Applications in the Enterpri...Configuration Management and Transforming Legacy Applications in the Enterpri...
Configuration Management and Transforming Legacy Applications in the Enterpri...
 
Container orchestration from theory to practice
Container orchestration from theory to practiceContainer orchestration from theory to practice
Container orchestration from theory to practice
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: Gradle
 
Docker for developers z java
Docker for developers z javaDocker for developers z java
Docker for developers z java
 
Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extreme
 
Docker Enterprise Workshop - Technical
Docker Enterprise Workshop - TechnicalDocker Enterprise Workshop - Technical
Docker Enterprise Workshop - Technical
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and code
 
Docker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesDocker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting Techniques
 
Practical Design Patterns in Docker Networking
Practical Design Patterns in Docker NetworkingPractical Design Patterns in Docker Networking
Practical Design Patterns in Docker Networking
 
Containerised Testing at Demonware : PyCon Ireland 2016
Containerised Testing at Demonware : PyCon Ireland 2016Containerised Testing at Demonware : PyCon Ireland 2016
Containerised Testing at Demonware : PyCon Ireland 2016
 
Building Web Scale Apps with Docker and Mesos by Alex Rukletsov (Mesosphere)
Building Web Scale Apps with Docker and Mesos by Alex Rukletsov (Mesosphere)Building Web Scale Apps with Docker and Mesos by Alex Rukletsov (Mesosphere)
Building Web Scale Apps with Docker and Mesos by Alex Rukletsov (Mesosphere)
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

Testing Distributed Microservices with Docker Compose and JUnit

  • 1. Integration testing with Docker Compose and JUnit Dariusz Lorenc Boris Kravtsov
  • 3. Problem End-2-end test of GemFire in various cluster configurations and with different failover scenarios
  • 4. GemFire GemFire is a distributed, in-memory database with strong data consistency, built to support transactional applications with low latency and high concurrency needs
  • 5. GemFire Server GemFire GemFire Server GemFire Server Partitioned Data Partitioned Data Partitioned Data GemFire ServerGemFire Server GemFire Server Partitioned Data Partitioned Data Partitioned Data Client WAN / Multi-Site Gateway Hub Gateway Hub Relational Database
  • 6. Docker Compose to the rescue Docker Compose is a tool for defining and running multi-container Docker applications
  • 7. Docker Compose JUnit Rule A JUnit rule to manage docker containers using docker-compose • Start and stop docker-compose multi-container applications • Waits for services to become available before running tests • Extends logging and debugging https://github.com/palantir/docker-compose-rule
  • 9. Test First - Happy Path @Test
 public void shouldReturnData(){
 get("/info")
 .then().assertThat()
 .body("counter", isA(Number.class))
 .body("greeting", is("Hello World"));
 }
  • 10. Spring Boot - Application.kt @SpringBootApplication open class Application { companion object { @JvmStatic fun main(args: Array<String>) { SpringApplication.run(Application::class.java, *args) } } }
  • 11. Greeting Service @RestController
 class Controller {
 
 @RequestMapping("/greeting")
 fun greet(): Greeting {
 return Greeting("Hello World")
 }
 } data class Greeting(val greeting: String)
  • 12. Counter Service @RestController
 class Controller {
 
 val counter = AtomicLong()
 
 @RequestMapping("/counter")
 fun count(): Counter {
 return Counter(counter.incrementAndGet())
 }
 } data class Counter(val counter: Long)
  • 13. Master Service @RestController
 class Controller @Autowired constructor( val greetingClient: GreetingClient,
 val counterClient: CounterClient) {
 
 @RequestMapping("/info")
 fun info(): Response {
 return Response(counterClient.counter().counter,
 greetingClient.greeting().greeting)
 }
 } data class Response(val counter: Long, val greeting: String)
  • 14. Master Service - Greeting Client @FeignClient(name = "greeting", url = "http://greeting-service:8080")
 interface GreetingClient { 
 @RequestMapping(value = "/greeting", method = arrayOf(RequestMethod.GET))
 fun greeting(): Greeting
 }
  • 15. Master Service - Counter Client @FeignClient(name = "counter", url = "http://counter-service:8080")
 interface CounterClient { 
 @RequestMapping(value = “/counter”, method = arrayOf(RequestMethod.GET))
 fun counter(): Counter
 }
  • 17. Dockerfiles FROM frolvlad/alpine-oraclejdk8:slim ADD master-service-1.0.0.jar app.jar EXPOSE 8080 ENTRYPOINT ["java","-jar","/app.jar"] Base image Add the app’s fat jar Expose the port Start the java app
  • 18. Build Docker Image with Gradle (Transmodo plugin) buildscript { dependencies { classpath('se.transmode.gradle:gradle-docker:1.2') } } group = '<your docker group name>' apply plugin: 'docker' task buildDocker(type: Docker, dependsOn: build) { push = true applicationName = jar.baseName dockerfile = file('src/main/docker/Dockerfile') doFirst { copy { from jar into stageDir } } } Gradle Docker plugin Your Docker Hub ID Build Docker task
  • 20. docker-compose.yml Greeting Counter Master greeting-service: image: lorenc/greeting-service ports: - “8081:8080" counter-service: image: lorenc/counter-service ports: - "8082:8080" master-service: image: lorenc/master-service ports: - "8083:8080" links: - greeting-service - counter-service
  • 21. Integration Test Setup @Rule
 public DockerComposeRule docker = DockerComposeRule.builder()
 .file("../docker-compose.yml")
 .build(); @Before
 public void setUp() throws Exception {
 docker.dockerCompose().up();
 }
 
 @After
 public void tearDown() throws Exception {
 docker.dockerCompose().down();
 }
  • 22. Health Checks & Logs @Rule
 public DockerComposeRule docker = DockerComposeRule.builder()
 .file("../docker-compose.yml")
 .waitingForService("greeting-service", toRespondOverHttp(8080, TO_EXTERNAL_URI))
 .waitingForService("counter-service", toRespondOverHttp(8080, TO_EXTERNAL_URI))
 .waitingForService("master-service", toRespondOverHttp(8080, TO_EXTERNAL_URI))
 .saveLogsTo("build/docker-logs")
 .build();
  • 23.
  • 24. What could possibly go wrong? @Test
 public void shouldReturnHolaWhenGreetingServiceDown(){
 docker.dockerCompose().container("greeting-service").stop();
 
 get("/info")
 .then().assertThat()
 .body("greeting", is("Hola!"));
 }
  • 25. What could possibly go wrong? @Test
 public void shouldReturn42WhenCounterServiceDown() {
 docker.dockerCompose().container("counter-service").stop();
 
 get("/info")
 .then().assertThat()
 .body("counter", is(42));
 }
  • 26. @FeignClient(name = "greeting", url = "http://greeting-service:8080", fallback = DefaultGreeting::class)
 interface GreetingClient { 
 @RequestMapping(value = "/greeting", method = arrayOf(RequestMethod.GET))
 fun greeting(): Greeting
 } @Component
 class DefaultGreeting : GreetingClient {
 override fun greeting(): Greeting {
 return Greeting("Hola!")
 }
 } Master Service - Greeting Client
  • 27. Master Service - Counter Client @FeignClient(name = "counter", url = "http://counter-service:8080", fallback = DefaultCounter::class)
 interface CounterClient { 
 @RequestMapping(value = “/counter”, method = arrayOf(RequestMethod.GET))
 fun counter(): Counter
 } @Component
 class DefaultCounter : CounterClient {
 override fun counter(): Counter {
 return Counter(42)
 }
 }
  • 28. Demo