Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@
<version>0.23.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.apache.ignite.testcontainers;

import java.time.Duration;
import java.time.ZoneId;
import java.util.Collection;
import org.apache.ignite.Ignition;
import org.apache.ignite.client.ClientCache;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.configuration.ClientConfiguration;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

/** Ignite container. */
public class IgniteContainer extends GenericContainer<IgniteContainer> {
/** Docker image name. */
private static final DockerImageName DOCKER_IMAGE_NAME = DockerImageName.parse("apacheignite/ignite:2.18.0");

/** Default thin client port. */
private static final int THIN_CLIENT_PORT = 10800;

/** Constructor. */
public IgniteContainer() {
super(DOCKER_IMAGE_NAME);

withExposedPorts(THIN_CLIENT_PORT);
//withEnv("CONFIG_URI", "file:///opt/ignite/config/default-config.xml");
withEnv("IGNITE_QUIET", "false");
//withEnv("IGNITE_NODE_NAME", "");
//withEnv("JVM_OPTS", String.format("-Xmx%s", heapSize));
withEnv("TZ", ZoneId.systemDefault().toString());

waitingFor(Wait.forLogMessage(".*Node started.*", 1)
.withStartupTimeout(Duration.ofSeconds(60)));
}

/** @return The port on which the thin client connector is listening. */
public Integer getThinClientPort() {
return getMappedPort(THIN_CLIENT_PORT);
}

/**
* Creates a cache with the given name using the thin client.
*
* @param cacheName Name of the cache to create.
*/
public void createCache(String cacheName) {
try (IgniteClient client = Ignition.startClient(clientConfig())) {
ClientCache<Object, Object> cache = client.createCache(cacheName);

cache.put("key", "val");
cache.put("key1", "val1");
cache.put("key2", "val2");
}
}

/** */
public Collection<String> caches() {
try (IgniteClient client = Ignition.startClient(clientConfig())) {
return client.cacheNames();
}
}

/** */
private ClientConfiguration clientConfig() {
return new ClientConfiguration()
.setAddresses("127.0.0.1:" + getThinClientPort())
.setRequestTimeout(30_000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.apache.ignite.testcontainers;

import org.junit.Test;

/** */
public class SimpleTest {
/** */
@Test
public void testStartStop() {
try (IgniteContainer ignite = new IgniteContainer()) {
ignite.start();

System.out.println(">>> Started container with ID=" + ignite.getContainerId());

ignite.createCache("test-cache");

System.out.println("All caches=" + ignite.caches());
}
}
}
1 change: 1 addition & 0 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<spring.version>5.3.39</spring.version>
<surefire.version>3.5.4</surefire.version>
<tomcat.version>10.0.27</tomcat.version>
<testcontainers.version>2.0.5</testcontainers.version>
<yardstick.version>0.8.3</yardstick.version>
<zookeeper.version>3.9.5</zookeeper.version>
<zstd.version>1.5.7-8</zstd.version>
Expand Down