-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Include Axon Server #4607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Include Axon Server #4607
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Axon Server Containers | ||
|
|
||
| Testcontainers can be used to automatically instantiate and manage both [Axon Server SE](https://axoniq.io/product-overview/axon-server) and [Axon Server EE](https://axoniq.io/product-overview/axon-server-enterprise) containers. | ||
| It uses the official [docker images](https://hub.docker.com/u/axoniq) provided by AxonIQ. | ||
|
|
||
| ## Benefits | ||
|
|
||
| * Running a single node Axon Server SE/EE with just one line of code | ||
|
|
||
| ## Example | ||
|
|
||
| ### Axon Server Standard Edition (SE) | ||
|
|
||
| Create an `AxonServerSEContainer` to use in your tests. | ||
|
|
||
| ```java | ||
| final AxonServerSEContainer axonServerSEContainer = | ||
| new AxonServerSEContainer(DockerImageName.parse("axoniq/axonserver:4.4.12")); | ||
| ``` | ||
|
|
||
| This version is the simplest one and also included some utils methods to get the Axon Server Address. The only out of the box configuration provided is the `devMode` flag: | ||
| * `withDevMode` where you can specify if you want dev-mode to be enabled or not. Default is `false` | ||
|
|
||
| ### Axon Server Enterprise Edition (EE) | ||
|
|
||
| Create an `AxonServerEEContainer` to use in your tests. | ||
|
|
||
| ```java | ||
| final AxonServerEEContainer axonServerEEContainer = | ||
| new AxonServerEEContainer(DockerImageName.parse("axoniq/axonserver-enterprise:4.5.9-dev")); | ||
| ``` | ||
|
|
||
| This version is more complex and provides additional configuration listed below: | ||
| * `withLicense` where you can provide a path to your license file | ||
| * `withAutoCluster` where you can provide a path to your auto-cluster file | ||
| * `withConfiguration` where you can provide a path to your `axonserver.properties` file | ||
| * `withAxonServerName` where you can provide Axon Server's name | ||
| * `withAxonServerHostname` where you can provide Axon Server's hostname | ||
| * `withAxonServerInternalHostname` where you can provide Axon Server's internal hostname | ||
|
|
||
| It also includes some utils methods to get the Axon Server Address. | ||
|
|
||
| ### Configuration | ||
|
|
||
| For an extensive list of environment variables you can use, please check the [official docs](https://docs.axoniq.io/reference-guide/v/master/axon-server/administration/admin-configuration/configuration#configuration-properties). | ||
|
|
||
| ## Adding this module to your project dependencies | ||
|
|
||
| Add the following dependency to your `pom.xml`/`build.gradle` file: | ||
|
|
||
| ```groovy tab='Gradle' | ||
| testImplementation "org.testcontainers:axonserver:{{latest_version}}" | ||
| ``` | ||
|
|
||
| ```xml tab='Maven' | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>axonserver</artifactId> | ||
| <version>{{latest_version}}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| description = "Testcontainers :: AxonServer" | ||
|
|
||
| dependencies { | ||
| api project(':testcontainers') | ||
| } |
154 changes: 154 additions & 0 deletions
154
modules/axonserver/src/main/java/org/testcontainers/containers/AxonServerEEContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| package org.testcontainers.containers; | ||
|
|
||
| import lombok.NonNull; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.testcontainers.containers.wait.strategy.Wait; | ||
| import org.testcontainers.utility.DockerImageName; | ||
| import org.testcontainers.utility.MountableFile; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * Constructs a single node AxonServer Enterprise Edition (EE) for testing. | ||
| */ | ||
| @Slf4j | ||
| public class AxonServerEEContainer<SELF extends AxonServerEEContainer<SELF>> extends GenericContainer<SELF> { | ||
|
|
||
| private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("axoniq/axonserver-enterprise"); | ||
| private static final int AXON_SERVER_HTTP_PORT = 8024; | ||
| private static final int AXON_SERVER_GRPC_PORT = 8124; | ||
|
|
||
| private static final String WAIT_FOR_LOG_MESSAGE = ".*Started AxonServer.*"; | ||
|
|
||
| private static final String LICENCE_DEFAULT_LOCATION = "/axonserver/config/axoniq.license"; | ||
| private static final String CONFIGURATION_DEFAULT_LOCATION = "/axonserver/config/axonserver.properties"; | ||
| private static final String CLUSTER_TEMPLATE_DEFAULT_LOCATION = "/axonserver/cluster-template.yml"; | ||
|
|
||
| private static final String AXONIQ_LICENSE = "AXONIQ_LICENSE"; | ||
| private static final String AXONIQ_AXONSERVER_NAME = "AXONIQ_AXONSERVER_NAME"; | ||
| private static final String AXONIQ_AXONSERVER_INTERNAL_HOSTNAME = "AXONIQ_AXONSERVER_INTERNAL_HOSTNAME"; | ||
| private static final String AXONIQ_AXONSERVER_HOSTNAME = "AXONIQ_AXONSERVER_HOSTNAME"; | ||
|
|
||
| private static final String AXON_SERVER_ADDRESS_TEMPLATE = "%s:%s"; | ||
|
|
||
| private String licensePath; | ||
| private String configurationPath; | ||
| private String clusterTemplatePath; | ||
| private String axonServerName; | ||
| private String axonServerInternalHostname; | ||
| private String axonServerHostname; | ||
|
|
||
| public AxonServerEEContainer(@NonNull final String dockerImageName) { | ||
| this(DockerImageName.parse(dockerImageName)); | ||
| } | ||
|
|
||
| public AxonServerEEContainer(final DockerImageName dockerImageName) { | ||
| super(dockerImageName); | ||
|
|
||
| dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
|
|
||
| withExposedPorts(AXON_SERVER_HTTP_PORT, AXON_SERVER_GRPC_PORT); | ||
| waitingFor(Wait.forLogMessage(WAIT_FOR_LOG_MESSAGE, 1)); | ||
| withEnv(AXONIQ_LICENSE, LICENCE_DEFAULT_LOCATION); | ||
| } | ||
|
|
||
| @Override | ||
| protected void configure() { | ||
| optionallyMapResourceParameterAsVolume(LICENCE_DEFAULT_LOCATION, licensePath); | ||
| optionallyMapResourceParameterAsVolume(CONFIGURATION_DEFAULT_LOCATION, configurationPath); | ||
| optionallyMapResourceParameterAsVolume(CLUSTER_TEMPLATE_DEFAULT_LOCATION, clusterTemplatePath); | ||
| withOptionalEnv(AXONIQ_AXONSERVER_NAME, axonServerName); | ||
| withOptionalEnv(AXONIQ_AXONSERVER_HOSTNAME, axonServerHostname); | ||
| withOptionalEnv(AXONIQ_AXONSERVER_INTERNAL_HOSTNAME, axonServerInternalHostname); | ||
| } | ||
|
|
||
| /** | ||
| * Map (effectively replace) directory in Docker with the content of resourceLocation if resource location is not | ||
| * null | ||
| * <p> | ||
| * Protected to allow for changing implementation by extending the class | ||
| * | ||
| * @param pathNameInContainer path in docker | ||
| * @param resourceLocation relative classpath to resource | ||
| */ | ||
| protected void optionallyMapResourceParameterAsVolume(String pathNameInContainer, String resourceLocation) { | ||
| Optional.ofNullable(resourceLocation) | ||
| .map(MountableFile::forClasspathResource) | ||
| .ifPresent(mountableFile -> withCopyFileToContainer(mountableFile, pathNameInContainer)); | ||
| } | ||
|
|
||
| /** | ||
| * Set an environment value if the value is present. | ||
| * <p> | ||
| * Protected to allow for changing implementation by extending the class | ||
| * | ||
| * @param key environment key value, usually a constant | ||
| * @param value environment value to be set | ||
| */ | ||
| protected void withOptionalEnv(String key, String value) { | ||
| Optional.ofNullable(value) | ||
| .ifPresent(v -> withEnv(key, value)); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize AxonServer EE with a given license. | ||
| */ | ||
| public SELF withLicense(String licensePath) { | ||
| this.licensePath = licensePath; | ||
| return self(); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize AxonServer EE with a given configuration file. | ||
| */ | ||
| public SELF withConfiguration(String configurationPath) { | ||
| this.configurationPath = configurationPath; | ||
| return self(); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize AxonServer EE with a given cluster template configuration file. | ||
| */ | ||
| public SELF withClusterTemplate(String clusterTemplatePath) { | ||
| this.clusterTemplatePath = clusterTemplatePath; | ||
| return self(); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize AxonServer EE with a given Axon Server Name. | ||
| */ | ||
| public SELF withAxonServerName(String axonServerName) { | ||
| this.axonServerName = axonServerName; | ||
| return self(); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize AxonServer EE with a given Axon Server Internal Hostname. | ||
| */ | ||
| public SELF withAxonServerInternalHostname(String axonServerInternalHostname) { | ||
| this.axonServerInternalHostname = axonServerInternalHostname; | ||
| return self(); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize AxonServer EE with a given Axon Server Hostname. | ||
| */ | ||
| public SELF withAxonServerHostname(String axonServerHostname) { | ||
| this.axonServerHostname = axonServerHostname; | ||
| return self(); | ||
| } | ||
|
|
||
| public Integer getGrpcPort() { | ||
| return this.getMappedPort(AXON_SERVER_GRPC_PORT); | ||
| } | ||
|
|
||
| public String getIPAddress() { | ||
| return this.getContainerIpAddress(); | ||
| } | ||
|
|
||
| public String getAxonServerAddress() { | ||
| return String.format(AXON_SERVER_ADDRESS_TEMPLATE, | ||
| this.getContainerIpAddress(), | ||
| this.getMappedPort(AXON_SERVER_GRPC_PORT)); | ||
| } | ||
| } | ||
65 changes: 65 additions & 0 deletions
65
modules/axonserver/src/main/java/org/testcontainers/containers/AxonServerSEContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package org.testcontainers.containers; | ||
|
|
||
| import lombok.NonNull; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.testcontainers.containers.wait.strategy.Wait; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
| /** | ||
| * Constructs a single node AxonServer Standard Edition (SE) for testing. | ||
| */ | ||
| @Slf4j | ||
| public class AxonServerSEContainer<SELF extends AxonServerSEContainer<SELF>> extends GenericContainer<SELF> { | ||
|
|
||
| private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("axoniq/axonserver"); | ||
| private static final int AXON_SERVER_HTTP_PORT = 8024; | ||
| private static final int AXON_SERVER_GRPC_PORT = 8124; | ||
|
|
||
| private static final String WAIT_FOR_LOG_MESSAGE = ".*Started AxonServer.*"; | ||
|
|
||
| private static final String AXONIQ_AXONSERVER_DEVMODE_ENABLED = "AXONIQ_AXONSERVER_DEVMODE_ENABLED"; | ||
|
|
||
| private static final String AXON_SERVER_ADDRESS_TEMPLATE = "%s:%s"; | ||
|
|
||
| private boolean devMode; | ||
|
|
||
| public AxonServerSEContainer(@NonNull final String dockerImageName) { | ||
| this(DockerImageName.parse(dockerImageName)); | ||
| } | ||
|
|
||
| public AxonServerSEContainer(final DockerImageName dockerImageName) { | ||
| super(dockerImageName); | ||
|
|
||
| dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
|
|
||
| withExposedPorts(AXON_SERVER_HTTP_PORT, AXON_SERVER_GRPC_PORT); | ||
| waitingFor(Wait.forLogMessage(WAIT_FOR_LOG_MESSAGE, 1)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void configure() { | ||
| withEnv(AXONIQ_AXONSERVER_DEVMODE_ENABLED, String.valueOf(devMode)); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize AxonServer EE with a given license. | ||
| */ | ||
| public SELF withDevMode(boolean devMode) { | ||
| this.devMode = devMode; | ||
| return self(); | ||
| } | ||
|
|
||
| public Integer getGrpcPort() { | ||
| return this.getMappedPort(AXON_SERVER_GRPC_PORT); | ||
| } | ||
|
|
||
| public String getIPAddress() { | ||
| return this.getContainerIpAddress(); | ||
| } | ||
|
|
||
| public String getAxonServerAddress() { | ||
| return String.format(AXON_SERVER_ADDRESS_TEMPLATE, | ||
| this.getContainerIpAddress(), | ||
| this.getMappedPort(AXON_SERVER_GRPC_PORT)); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...les/axonserver/src/test/java/org/testcontainers/containers/AxonServerEEContainerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.testcontainers.containers; | ||
|
|
||
| import org.junit.*; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
|
|
||
| public class AxonServerEEContainerTest { | ||
|
|
||
| @Test | ||
| public void supportsAxonServer_4_5_X() { | ||
| try ( | ||
| final AxonServerEEContainer axonServerEEContainer = | ||
| new AxonServerEEContainer(DockerImageName.parse("axoniq/axonserver-enterprise:4.5.9-dev")) | ||
| ) { | ||
| axonServerEEContainer.start(); | ||
| } | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...les/axonserver/src/test/java/org/testcontainers/containers/AxonServerSEContainerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.testcontainers.containers; | ||
|
|
||
| import org.junit.*; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
|
|
||
| public class AxonServerSEContainerTest { | ||
|
|
||
| @Test | ||
| public void supportsAxonServer_4_4_X() { | ||
| try ( | ||
| final AxonServerSEContainer axonServerSEContainer = | ||
| new AxonServerSEContainer(DockerImageName.parse("axoniq/axonserver:4.4.12")) | ||
| ) { | ||
| axonServerSEContainer.start(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void supportsAxonServer_4_5_X() { | ||
| try ( | ||
| final AxonServerSEContainer axonServerSEContainer = | ||
| new AxonServerSEContainer(DockerImageName.parse("axoniq/axonserver:4.5.8")) | ||
| ) { | ||
| axonServerSEContainer.start(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <configuration> | ||
|
|
||
| <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
| <!-- encoders are assigned the type | ||
| ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
| <encoder> | ||
| <pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern> | ||
| </encoder> | ||
| </appender> | ||
|
|
||
| <root level="INFO"> | ||
| <appender-ref ref="STDOUT"/> | ||
| </root> | ||
|
|
||
| <logger name="org.testcontainers" level="DEBUG"/> | ||
| </configuration> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.