How does one go about doing end-to-end testing of a distributed in-memory database such as Pivotal GemFire?
Presented at JVM Meetup Sydney
https://www.meetup.com/Sydney-JVM-Community/events/233465115/
Demo code available at:
https://github.com/d-lorenc/junit-docker-demo
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
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)
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));
}