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
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
/** Smoke test for rolling upgrade with persistence. */
public class IgniteRebalanceOnUpgradeTest extends GridCommonAbstractTest {
/** Consistent ID's. */
private static final List<String> CONSISTENT_IDS = List.of(
protected static final List<String> CONSISTENT_IDS = List.of(
"ad26bff6-5ff5-49f1-9a61-425a827953ed",
"c1099d16-e7d7-49f4-925c-53329286c444",
"7b880b69-8a9e-4b84-b555-250d365e2e67"
);

/** Source image name, overridable via {@code -Dru.source.image.name}. */
private static final String SOURCE_IMAGE_NAME = System.getProperty("ru.source.image.name");
protected static final String SOURCE_IMAGE_NAME = System.getProperty("ru.source.image.name");

/** Upgrade mode. */
private static final UpgradeMode UPGRADE_MODE = UpgradeMode.valueOf(System.getProperty("ru.upgrade.mode",
Expand Down Expand Up @@ -114,7 +114,7 @@ public static void afterClass() {
/** Basic RU test. */
@Test
public void testRollingUpgrade() throws Exception {
try (IgniteClusterContainer cluster = new IgniteClusterContainer(SOURCE_IMAGE_NAME, CONSISTENT_IDS)) {
try (IgniteClusterContainer cluster = cluster()) {
cluster.start();

ClientCacheConfiguration cfg = new ClientCacheConfiguration()
Expand Down Expand Up @@ -144,8 +144,13 @@ public void testRollingUpgrade() throws Exception {
}
}

/** @return Source cluster container. */
protected IgniteClusterContainer cluster() throws Exception {
return new IgniteClusterContainer(SOURCE_IMAGE_NAME, CONSISTENT_IDS);
}

/** Verify data via local host-JVM nodes. */
private void verifyViaLocalNodes() {
protected void verifyViaLocalNodes() {
IgniteCache<Integer, Integer> targetCache = nodes.get(0).cache(CACHE_NAME);

for (int i = 0; i < 1000; i++)
Expand All @@ -157,7 +162,7 @@ private void verifyViaLocalNodes() {
}

/** Verify data via thin client connected to upgraded Docker nodes. */
private void verifyViaDockerNodes(IgniteClusterContainer cluster) {
protected void verifyViaDockerNodes(IgniteClusterContainer cluster) {
IgniteContainer con = cluster.containers().get(0);

con.checkNodeCount(cluster.containers().size());
Expand All @@ -173,7 +178,7 @@ private void verifyViaDockerNodes(IgniteClusterContainer cluster) {
}

/** */
private void upgradeCluster(IgniteClusterContainer srcCluster) throws Exception {
protected void upgradeCluster(IgniteClusterContainer srcCluster) throws Exception {
List<IgniteContainer> srcContainers = srcCluster.containers();

if (UPGRADE_MODE == UpgradeMode.LOCAL) {
Expand All @@ -194,7 +199,7 @@ private void upgradeCluster(IgniteClusterContainer srcCluster) throws Exception
}

/** Stop container, start a local host-JVM node with the same consistent ID. */
private void upgradeLocally(IgniteContainer con, int idx) throws Exception {
protected void upgradeLocally(IgniteContainer con, int idx) throws Exception {
// Address containers use to reach this (host JVM) node:
// - Linux: Docker bridge gateway IP (e.g. 172.24.0.1) — always reachable from containers,
// and the host can bind to it. The host's LAN IP is unreliable (on Debian/Ubuntu
Expand Down Expand Up @@ -235,7 +240,7 @@ private void upgradeLocally(IgniteContainer con, int idx) throws Exception {
}

/** */
private IgniteConfiguration configuration(String nodeId, String workDir, Collection<String> addrs0, String ip, int idx) {
protected IgniteConfiguration configuration(String nodeId, String workDir, Collection<String> addrs0, String ip, int idx) {
DataRegionConfiguration dataRegionCfg = new DataRegionConfiguration()
.setName("testRegion")
.setInitialSize(1024L * 1024 * 1024)
Expand Down Expand Up @@ -295,15 +300,23 @@ private IgniteConfiguration configuration(String nodeId, String workDir, Collect
}

/** */
private IgniteClient client(String addr) {
protected IgniteClient client(String addr) {
if (client == null)
client = Ignition.startClient(new ClientConfiguration().setAddresses(addr));
client = Ignition.startClient(clientConfiguration(addr));

return client;
}

/**
* @param addr Server address.
* @return Thin client configuration.
*/
protected ClientConfiguration clientConfiguration(String addr) {
return new ClientConfiguration().setAddresses(addr);
}

/** */
private void closeClient() {
protected void closeClient() {
if (client != null) {
client.close();

Expand All @@ -312,7 +325,7 @@ private void closeClient() {
}

/** */
private void stopLocalNodes() {
protected void stopLocalNodes() {
for (IgniteEx node : nodes) {
if (node != null)
Ignition.stop(node.name(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.ignite.IgniteException;
import org.testcontainers.containers.Network;
import org.testcontainers.lifecycle.Startable;
import org.testcontainers.lifecycle.Startables;
Expand All @@ -30,21 +31,52 @@ public class IgniteClusterContainer implements Startable {
private final List<IgniteContainer> containers;

/** Network. */
private final Network net = Network.newNetwork();
private final Network net;

/** Image name. */
private final String imageName;

/** Consistent ID's. */
private final List<String> consistentIds;

/**
* @param imageName Image name.
* @param consistentIds Consistent ID's.
*/
public IgniteClusterContainer(String imageName, List<String> consistentIds) throws Exception {
public IgniteClusterContainer(String imageName, List<String> consistentIds) {
this.imageName = imageName;
this.consistentIds = consistentIds;

net = Network.newNetwork();
containers = new ArrayList<>(consistentIds.size());
}

/**
* @param imageName Image name.
* @param net Shared test network the container must be attached to.
* @param consistentIds Consistent ID's.
* @param idx Node index.
* @return The node container.
*/
protected IgniteContainer container(String imageName, Network net, List<String> consistentIds, int idx) throws Exception {
return new IgniteContainer(imageName, net, "node" + (1 + idx), consistentIds.get(idx), idx);
}

/** Builds the node containers. */
protected void initContainers() throws Exception {
for (int i = 0; i < consistentIds.size(); i++)
containers.add(new IgniteContainer(imageName, net, "node" + (1 + i), consistentIds.get(i), i));
containers.add(container(imageName, net, consistentIds, i));
}

/** {@inheritDoc} */
@Override public void start() {
try {
initContainers();
}
catch (Exception e) {
throw new IgniteException(e);
}

Startables.deepStart(containers).join();

containers.get(0).activateCluster(containers.size());
Expand Down
Loading
Loading