testcontainers-infinispan/README.md

78 lines
3.1 KiB
Markdown
Raw Normal View History

2017-12-07 18:32:36 +01:00
# Testcontainers Infinispan
The [Testcontainers](https://www.testcontainers.org/) library provides container implementations
for a few different docker containers that you might want to use during integration tests. You can always
use a generic container to launch other images. This repository contains an implementation of a container
for the Infinispan cache server. It provides an API that is aimed to help you configure the container.
2017-12-17 17:37:31 +01:00
At the moment this is a rudimentary implementation and by no means complete. It only supports the [Hotrod protocol](http://infinispan.org/docs/stable/user_guide/user_guide.html#hot_rod_protocol)
to connect to the Infinispan server, for example.
2018-01-21 18:46:54 +01:00
Further information can be found in these blog posts:
- [12-19-2017: Running an Infinispan Server using Testcontainers](https://blog.codecentric.de/en/2017/12/running-infinispan-server-using-testcontainers)
- [01-21-2018: Running a clustered Infinispan Server using Testcontainers](https://reinhard.codes/2018/01/21/running-an-infinispan-node-in-clustered-mode-using-testcontainers/)
2017-12-17 17:37:31 +01:00
Feel free to suggest changes!
2017-12-07 18:34:49 +01:00
# Usage
2018-01-21 18:46:54 +01:00
It's possible to run Infinispan in standalone or in clustered mode. See the integration tests contained in this repository
for detailed examples.
## Instantiation of the Infinispan containers
Here's a simple example how you can use the `StandaloneInfinispanContainer`.
```
@ClassRule
public static InfinispanContainer infinispan = new StandaloneInfinispanContainer();
```
2017-12-22 15:48:42 +01:00
2018-01-21 18:46:54 +01:00
If you want to run Infinispan as a one-node clustered instance, you can do it like this:
2017-12-07 18:34:49 +01:00
```
@ClassRule
2018-01-21 18:46:54 +01:00
public static InfinispanContainer infinispan = new ClusteredInfinispanContainer();
2017-12-22 15:48:42 +01:00
```
2018-01-21 18:46:54 +01:00
2017-12-22 15:48:42 +01:00
## Cache creation
You can create simple local caches that need to be available for your tests. If you run an up-to-date Infinispan container (>9.1.0) then caches can be created
using the API of the `RemoteCacheManager` provided by the Infinispan client library. Simple configure some caches that the `InfinispanContainer` should create for you.
They will automatically be created once the container has started.
```
2018-01-27 18:26:31 +01:00
new StandaloneInfinispanContainer()
2018-01-21 18:46:54 +01:00
.withCaches("testCache")
.withProtocolVersion(ProtocolVersion.PROTOCOL_VERSION_26);
2017-12-22 15:48:42 +01:00
```
2018-01-21 18:46:54 +01:00
The `ClusteredInfinispanContainer` supports the same method.
2017-12-22 15:48:42 +01:00
If you run an Infinispan server version prior to `9.1.0`, you can link a configuration file that contains the necessary caches into the container:
```
2018-01-21 18:46:54 +01:00
new StandaloneInfinispanContainer("jboss/infinispan-server:9.0.3.Final")
.withStandaloneConfiguration("infinispan-standalone.xml")
.withProtocolVersion(ProtocolVersion.PROTOCOL_VERSION_26)
```
There's an equivalent for the `ClusteredInfinispanContainer`:
```
new ClusteredInfinispanContainer("jboss/infinispan-server:9.0.3.Final")
.withClusteredConfiguration("infinispan-standalone.xml")
.withProtocolVersion(ProtocolVersion.PROTOCOL_VERSION_26)
2017-12-14 16:56:53 +01:00
```
2017-12-22 15:48:42 +01:00
## CacheManager retrieval
2017-12-14 16:56:53 +01:00
If you want, you can retrieve a `RemoteCacheManager` from the container:
2018-01-21 18:46:54 +01:00
2017-12-14 16:56:53 +01:00
```
infinispan.getCacheManager()
```
For general usage info on Testcontainers please look at the examples of the project.