You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to reuse containers so that when I am developing tests, I don't have to wait about a minute for mysql to start up.
The following program works, but the containers are always created, rather than being reused.
After debugging testcontainers, I saw that the hash used to add a label always changes, because the network name is in there, and by default it is based on a random uuid.
It is not currently possible to name the network.
setting network to null in the code below would work, but then redpanda console cannot find redpanda and it seems as though you can only use network aliases if a network is added to the testcontainer?
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.lifecycle.Startables;
import org.testcontainers.redpanda.RedpandaContainer;
import org.testcontainers.utility.DockerImageName;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
public class AbstractContainerBaseTest {
static Network network = Network.newNetwork();
static MySQLContainer<?> mysql = new MySQLContainer<>("mysql:8.0.33")
.withDatabaseName("test")
.withUsername("cdc")
.withPassword("cdcpwd")
.withReuse(true)
.withNetwork(network)
.withNetworkAliases("mysql")
;
static RedpandaContainer redpanda = new RedpandaContainer("docker.redpanda.com/redpandadata/redpanda:v23.1.12")
.withNetwork(network)
.withNetworkAliases("redpanda")
.withReuse(true);
static GenericContainer redpandaconsole = new GenericContainer(DockerImageName.parse("redpandadata/console:v2.2.4"))
.dependsOn(redpanda)
.withNetwork(network)
.withExposedPorts(8080)
.withNetworkAliases("redpandaconsole")
.withEnv("KAFKA_BROKERS", "redpanda:29092") // check impl of RedpandaContainer, and the port used internallyis 29092
.withReuse(true);
static {
Startables.deepStart(mysql, redpanda, redpandaconsole).join();
logAndOpenRedpandaConsoleInBrowser();
}
private static void logAndOpenRedpandaConsoleInBrowser() {
String url = ("http://localhost:" + redpandaconsole.getMappedPort(8080));
try {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(URI.create(url));
}
}
} catch (IOException | InternalError e) {
e.printStackTrace();
}
System.out.println("Redpanda Console running on " + url);
}
}
That you can have two containers with one being able to refer to the other, AND that they can have "reuse" set so that when developing tests, it is not necessary to keep bouncing the containers.
Alternatives
cant think of any
Would you like to help contributing this feature?
Yes
The text was updated successfully, but these errors were encountered:
I see two different issues that has been reported in the past, reusable networks issue and reuse redpanda. As you can see in one of my comments I have offered a workaround and an PR improving adding kafka listeners.
Module
Core
Problem
I am trying to reuse containers so that when I am developing tests, I don't have to wait about a minute for mysql to start up.
The following program works, but the containers are always created, rather than being reused.
After debugging testcontainers, I saw that the hash used to add a label always changes, because the network name is in there, and by default it is based on a random uuid.
It is not currently possible to name the network.
setting network to null in the code below would work, but then redpanda console cannot find redpanda and it seems as though you can only use network aliases if a network is added to the testcontainer?
Solution
Allow networks to be named.
this might work:
Benefit
That you can have two containers with one being able to refer to the other, AND that they can have "reuse" set so that when developing tests, it is not necessary to keep bouncing the containers.
Alternatives
cant think of any
Would you like to help contributing this feature?
Yes
The text was updated successfully, but these errors were encountered: