Skip to content

Commit

Permalink
Add oci image definition, use it in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Nov 22, 2024
1 parent f4df4b1 commit f201fdb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
25 changes: 24 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ oci {
}
}
}
imageMapping {
mapModule("com.hivemq", "hivemq-enterprise") {
toImage("hivemq/hivemq4")
}
}
imageDefinitions.register("main") {
allPlatforms {
dependencies {
runtime("com.hivemq:hivemq-enterprise:latest") { isChanging = true }
}
layers {
layer("hivemqExtension") {
contents {
permissions("opt/hivemq/", 0b111_111_000)
permissions("opt/hivemq/extensions/", 0b111_111_000)
into("opt/hivemq/extensions") {
from(zipTree(tasks.hivemqExtensionZip.flatMap { it.archiveFile }))
}
}
}
}
}
}
}

@Suppress("UnstableApiUsage")
Expand Down Expand Up @@ -66,7 +89,7 @@ testing {
}
oci.of(this) {
imageDependencies {
runtime("hivemq:hivemq4:latest") { isChanging = true }
runtime(project).tag("latest")
runtime("azure-storage:azurite:3.33.0").tag("latest")
runtime("shopify:toxiproxy:2.1.0").tag("latest")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
import org.testcontainers.utility.MountableFile;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -74,7 +71,7 @@ void tearDown() {
}

@Test
void threeNodesFormCluster() throws IOException, TimeoutException {
void threeNodesFormCluster() throws TimeoutException {
final WaitingConsumer consumer1 = new WaitingConsumer();
final WaitingConsumer consumer2 = new WaitingConsumer();
final WaitingConsumer consumer3 = new WaitingConsumer();
Expand All @@ -95,7 +92,7 @@ void threeNodesFormCluster() throws IOException, TimeoutException {
}

@Test
void twoNodesInCluster_oneNodeStarted_threeNodesInCluster() throws IOException, TimeoutException {
void twoNodesInCluster_oneNodeStarted_threeNodesInCluster() throws TimeoutException {
final WaitingConsumer consumer1 = new WaitingConsumer();
final WaitingConsumer consumer2 = new WaitingConsumer();
final WaitingConsumer consumer3 = new WaitingConsumer();
Expand All @@ -118,7 +115,7 @@ void twoNodesInCluster_oneNodeStarted_threeNodesInCluster() throws IOException,
}

@Test
void twoNodesInCluster_oneNodeCannotReachAzure_nodeFileDeleted() throws IOException, TimeoutException {
void twoNodesInCluster_oneNodeCannotReachAzure_nodeFileDeleted() throws TimeoutException {
final ToxiproxyContainer toxiproxy = new ToxiproxyContainer(OciImages.getImageName("shopify/toxiproxy")) //
.withNetwork(network).withNetworkAliases(TOXIPROXY_NETWORK_ALIAS);
try (toxiproxy) {
Expand Down Expand Up @@ -153,7 +150,7 @@ void twoNodesInCluster_oneNodeCannotReachAzure_nodeFileDeleted() throws IOExcept
}

@Test
void threeNodesInCluster_oneNodeStopped_twoNodesInCluster() throws IOException, TimeoutException {
void threeNodesInCluster_oneNodeStopped_twoNodesInCluster() throws TimeoutException {
final WaitingConsumer consumer1 = new WaitingConsumer();
final WaitingConsumer consumer2 = new WaitingConsumer();
final WaitingConsumer consumer3 = new WaitingConsumer();
Expand Down Expand Up @@ -187,7 +184,7 @@ void threeNodesInCluster_oneNodeStopped_twoNodesInCluster() throws IOException,
}

@Test
void wrongConnectionString_reloadRightConnectionString_clusterCreated() throws IOException, TimeoutException {
void wrongConnectionString_reloadRightConnectionString_clusterCreated() throws TimeoutException {
final String wrongConnectionString = "DefaultEndpointsProtocol=http;" + //
"AccountName=devstoreaccount1;" +
"AccountKey=XXX8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;" +
Expand All @@ -211,7 +208,7 @@ void wrongConnectionString_reloadRightConnectionString_clusterCreated() throws I
}

@Test
void containerNotExisting_nodeStarted_containerCreated() throws IOException {
void containerNotExisting_nodeStarted_containerCreated() {
final BlobContainerClient blobContainerClient = new BlobContainerClientBuilder().connectionString(createHostAzuriteConnectionString())
.containerName(BLOB_CONTAINER_NAME)
.buildClient();
Expand All @@ -228,7 +225,7 @@ void containerNotExisting_nodeStarted_containerCreated() throws IOException {
}

@Test
void containerExisting_nodeStarted_containerUsed() throws IOException {
void containerExisting_nodeStarted_containerUsed() {
final BlobContainerClient blobContainerClient = new BlobContainerClientBuilder().connectionString(createHostAzuriteConnectionString())
.containerName(BLOB_CONTAINER_NAME)
.buildClient();
Expand Down Expand Up @@ -271,20 +268,16 @@ void containerExisting_nodeStarted_containerUsed() throws IOException {
return createAzuriteConnectionString("127.0.0.1", azureriteContainer.getMappedPort(AZURITE_PORT));
}

private @NotNull HiveMQContainer createHiveMQNode(final @NotNull String connectionString) throws IOException {

final Path configFile = Files.createTempDirectory("az-extension-test").resolve("azDiscovery.properties");
Files.writeString(configFile, createConfig(connectionString));

return new HiveMQContainer(OciImages.getImageName("hivemq/hivemq4")) //
private @NotNull HiveMQContainer createHiveMQNode(final @NotNull String connectionString) {
return new HiveMQContainer(OciImages.getImageName("hivemq/extensions/hivemq-azure-cluster-discovery-extension")
.asCompatibleSubstituteFor("hivemq/hivemq4")) //
.withHiveMQConfig(MountableFile.forClasspathResource("config.xml"))
.withExtension(MountableFile.forClasspathResource("hivemq-azure-cluster-discovery-extension"))
.withFileInExtensionHomeFolder(MountableFile.forHostPath(configFile),
"hivemq-azure-cluster-discovery-extension")
.withCopyToContainer(Transferable.of(createConfig(connectionString)),
"/opt/hivemq/extensions/hivemq-azure-cluster-discovery-extension/azDiscovery.properties")
.withNetwork(network);
}

private @NotNull HiveMQContainer createHiveMQNode() throws IOException {
private @NotNull HiveMQContainer createHiveMQNode() {
return createHiveMQNode(createDockerAzuriteConnectionString());
}
}

0 comments on commit f201fdb

Please sign in to comment.