Skip to content

Commit

Permalink
757 - Integration test for Hot Reload of nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Chandler committed Nov 6, 2024
1 parent 956757a commit b1d222f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.nio.file.Paths;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.StartContainerCmd;
import com.github.dockerjava.api.command.StopContainerCmd;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.DockerComposeContainer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -33,8 +40,6 @@ public class AbstractCassandraCluster
protected static String containerIP;
protected static CqlSession mySession;

protected static Boolean startCluster = true;

@BeforeClass
public static void setup() throws InterruptedException
{
Expand All @@ -43,14 +48,7 @@ public static void setup() throws InterruptedException
.getParent()
.resolve("cassandra-test-image/src/main/docker/docker-compose.yml");
composeContainer = new DockerComposeContainer<>(dockerComposePath.toFile());
if (startCluster)
{
composeContainer.start();
LOG.info("Waiting for the Cassandra cluster to finish starting up.");
Thread.sleep(50000);
}

/*
composeContainer.start();
LOG.info("Waiting for the Cassandra cluster to finish starting up.");
Thread.sleep(50000);

Expand All @@ -63,7 +61,7 @@ public static void setup() throws InterruptedException
.withAuthCredentials("cassandra", "cassandra");
mySession = builder.build();

*/

}

@AfterClass
Expand All @@ -76,9 +74,32 @@ public static void tearDownCluster()
composeContainer.stop();
}

public void decommissionNode ( String node)
protected void decommissionNode ( String node) throws IOException, InterruptedException {
String stdout = composeContainer.getContainerByServiceName(node).get()
.execInContainer("nodetool", "-u", "cassandra", "-pw", "cassandra", "decommission").getStdout();
}
protected void startContainer ( String node)
{
DockerClient dockerClient = DockerClientFactory.instance().client();
String container = composeContainer
.getContainerByServiceName(node).get().getContainerId();

try (StartContainerCmd startCmd3 = dockerClient.startContainerCmd(container))
{
startCmd3.exec();
}
}
protected void stopContainer ( String node)
{
DockerClient dockerClient = DockerClientFactory.instance().client();
String container = composeContainer
.getContainerByServiceName(node).get().getContainerId();
try (StopContainerCmd stopCmd = dockerClient.stopContainerCmd(container))
{
stopCmd.exec();
}

}

}

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import com.ericsson.bss.cassandra.ecchronos.core.impl.repair.DefaultRepairConfigurationProvider;
import com.github.dockerjava.api.DockerClient;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.DockerClientFactory;
import com.ericsson.bss.cassandra.ecchronos.application.spring.EccNodeStateListener;
import org.testcontainers.containers.DockerComposeContainer;

import java.net.InetSocketAddress;
Expand All @@ -22,51 +22,27 @@ public class TestNodeAddition extends AbstractCassandraCluster
private static final Logger LOG = LoggerFactory.getLogger(TestNodeAddition.class);
@BeforeClass
public static void setup() throws InterruptedException {
startCluster = false;

Path dockerComposePath = Paths.get("")
.toAbsolutePath()
.getParent()
.resolve("cassandra-test-image/src/main/docker/docker-compose.yml");
composeContainer = new DockerComposeContainer<>(dockerComposePath.toFile());
if (startCluster)
{
composeContainer.start();
LOG.info("Waiting for the Cassandra cluster to finish starting up.");
Thread.sleep(60000);
}
}
@Test
public void testCassandraCluster() throws InterruptedException {
DockerClient dockerClient = DockerClientFactory.instance().client();

composeContainer.withScaledService("cassandra-node-dc1-rack1-node2", 0 );
composeContainer.withScaledService("cassandra-node-dc2-rack1-node2", 0 );
composeContainer.withScaledService("cassandra-seed-dc1-rack1-node1", 1 );
composeContainer.withScaledService("cassandra-seed-dc2-rack1-node1", 0 );
composeContainer.start();
LOG.info("Waiting for the Cassandra cluster to finish starting up.");
Thread.sleep(50000);
/*
String seed1 = composeContainer
.getContainerByServiceName("cassandra-seed-dc1-rack1-node1").get().getContainerId();
String seed2 = composeContainer
.getContainerByServiceName("cassandra-seed-dc2-rack1-node1").get().getContainerId();
String node1 = composeContainer
.getContainerByServiceName("cassandra-node-dc1-rack1-node2").get().getContainerId();
}
@Test
public void testCassandraCluster() throws InterruptedException {

try (StartContainerCmd startCmd1 = dockerClient.startContainerCmd(seed1))
{
startCmd1.exec();
}
try (StartContainerCmd startCmd2 = dockerClient.startContainerCmd(seed2))
{
startCmd2.exec();
}
*/
EccNodeStateListener listener = mock(EccNodeStateListener.class);
DefaultRepairConfigurationProvider listener = mock(DefaultRepairConfigurationProvider.class);
containerIP = composeContainer.getContainerByServiceName("cassandra-seed-dc1-rack1-node1").get()
.getContainerInfo()
.getNetworkSettings().getNetworks().values().stream().findFirst().get().getIpAddress();
// EccNodeStateListener listener = new EccNodeStateListener();
CqlSessionBuilder builder = CqlSession.builder()
.addContactPoint(new InetSocketAddress(containerIP, 9042))
.withLocalDatacenter("datacenter1")
Expand All @@ -78,28 +54,9 @@ public void testCassandraCluster() throws InterruptedException {
composeContainer.withScaledService("cassandra-node-dc2-rack1-node2", 1 );
composeContainer.withScaledService("cassandra-seed-dc2-rack1-node1", 1 );
composeContainer.start();
LOG.info("Waiting for the new nodes to finish starting up.");
Thread.sleep(50000);

/*
String node1 = composeContainer
.getContainerByServiceName("cassandra-node-dc1-rack1-node2").get().getContainerId();
try (StartContainerCmd startCmd3 = dockerClient.startContainerCmd(node1))
{
startCmd3.exec();
}
// To stop the container
try (StopContainerCmd stopCmd = dockerClient.stopContainerCmd(container))
{
stopCmd.exec();
}
// To start it again
*/



verify(listener, times(3)).onAdd(any());
verify(listener, times(0)).onRemove(any());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import com.ericsson.bss.cassandra.ecchronos.application.spring.EccNodeStateListener;
import com.ericsson.bss.cassandra.ecchronos.core.impl.repair.DefaultRepairConfigurationProvider;
import com.github.dockerjava.api.DockerClient;
import org.junit.Test;
import org.testcontainers.DockerClientFactory;
Expand All @@ -19,14 +19,12 @@ public class TestNodeRemoval extends AbstractCassandraCluster

@Test
public void testCassandraCluster() throws InterruptedException {
DockerClient dockerClient = DockerClientFactory.instance().client();


EccNodeStateListener listener = mock(EccNodeStateListener.class);
DefaultRepairConfigurationProvider listener = mock(DefaultRepairConfigurationProvider.class);
containerIP = composeContainer.getContainerByServiceName("cassandra-seed-dc1-rack1-node1").get()
.getContainerInfo()
.getNetworkSettings().getNetworks().values().stream().findFirst().get().getIpAddress();
// EccNodeStateListener listener = new EccNodeStateListener();

CqlSessionBuilder builder = CqlSession.builder()
.addContactPoint(new InetSocketAddress(containerIP, 9042))
.withLocalDatacenter("datacenter1")
Expand All @@ -35,14 +33,14 @@ public void testCassandraCluster() throws InterruptedException {
mySession = builder.build();

try {
composeContainer
.getContainerByServiceName("cassandra-seed-dc1-rack1-node1").get().execInContainer("nodetool", "-u", "cassandra", "-pw", "cassandra", "decommission");
decommissionNode("cassandra-seed-dc1-rack1-node1");
} catch (IOException e) {
throw new RuntimeException(e);

}
Thread.sleep(50000);


verify(listener, times(1)).onRemove(any());

}
Expand Down

0 comments on commit b1d222f

Please sign in to comment.