Skip to content

Commit

Permalink
cleanup storage container before run
Browse files Browse the repository at this point in the history
  • Loading branch information
dlg99 committed Jun 27, 2024
1 parent 36526a6 commit cf851f6
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,33 @@
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testng.annotations.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;
import static java.util.stream.Collectors.joining;
import static org.testng.Assert.assertEquals;

/**
* Test upgrading/downgrading Pulsar cluster.
* Test upgrading/downgrading Pulsar cluster from major releases.
*/
@Slf4j
public class PulsarUpgradeDowngradeTest extends PulsarClusterTestBase {

@Test(timeOut=600_000)
public void test_210() throws Exception {
Path tempDir = Files.createTempDirectory("pulsar2.10");
tempDir.toFile().deleteOnExit();
testUpgradeDowngrade(tempDir.toAbsolutePath().toString(), "apachepulsar/pulsar:2.10.6", PulsarContainer.DEFAULT_IMAGE_NAME);
public void upgradeFrom_2_10_6() throws Exception {
testUpgradeDowngrade("apachepulsar/pulsar:2.10.6", PulsarContainer.DEFAULT_IMAGE_NAME);
}

@Test(timeOut=600_000)
public void test_300() throws Exception {
Path tempDir = Files.createTempDirectory("pulsar3.0");
tempDir.toFile().deleteOnExit();
testUpgradeDowngrade(tempDir.toAbsolutePath().toString(), "apachepulsar/pulsar:3.0.5", PulsarContainer.DEFAULT_IMAGE_NAME);
public void upgradeFrom_3_0_5() throws Exception {
testUpgradeDowngrade("apachepulsar/pulsar:3.0.5", PulsarContainer.DEFAULT_IMAGE_NAME);
}

private void testUpgradeDowngrade(String path, String imageOld, String imageNew) throws Exception {
private void testUpgradeDowngrade(String imageOld, String imageNew) throws Exception {
final String clusterName = Stream.of(this.getClass().getSimpleName(), randomName(5))
.filter(s -> !s.isEmpty())
.collect(joining("-"));
String topicName = generateTopicName("testupdown", true);

@Cleanup
Network network = Network.newNetwork();
@Cleanup
GenericContainer<?> alpine = new GenericContainer<>("alpine:3.20.1")
Expand All @@ -76,9 +71,13 @@ private void testUpgradeDowngrade(String path, String imageOld, String imageNew)
.withEnv("MAGIC_NUMBER", "42")
.withCreateContainerCmdModifier(createContainerCmd -> createContainerCmd
.getHostConfig()
.withBinds(Bind.parse("/pulsar/data:/pulsar/data:rw")))
.withBinds(Bind.parse("/pulsar/data:/pulsar/data")))
.withCommand("/bin/sh", "-c",
"mkdir -p /pulsar/data && chmod -R ug+rwx /pulsar/data && chown -R 10000:0 /pulsar/data && while true; do echo \"$MAGIC_NUMBER\" | nc -l -p 80; done");
"mkdir -p /pulsar/data && "
+ "chmod -R ug+rwx /pulsar/data && "
+ "chown -R 10000:0 /pulsar/data && "
+ "rm -rf /pulsar/data/* && "
+ "while true; do echo \"$MAGIC_NUMBER\" | nc -l -p 80; done");
alpine.start();

PulsarClusterSpec specOld = PulsarClusterSpec.builder()
Expand Down

0 comments on commit cf851f6

Please sign in to comment.