Skip to content

Commit

Permalink
Detect M1 mac in test and substitute container image (#75)
Browse files Browse the repository at this point in the history
Fixes #57
  • Loading branch information
Alexander Preuß authored Aug 29, 2022
1 parent 67cb57c commit dfa1e36
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@

package org.springframework.pulsar.autoconfigure;

import java.util.Locale;

import org.testcontainers.containers.PulsarContainer;
import org.testcontainers.utility.DockerImageName;

abstract class AbstractContainerBaseTests {

static final DockerImageName PULSAR_IMAGE = DockerImageName.parse("apachepulsar/pulsar:2.10.1");

static PulsarContainer PULSAR_CONTAINER;
static final PulsarContainer PULSAR_CONTAINER;

static {
final DockerImageName PULSAR_IMAGE = isRunningOnMacM1() ? getMacM1PulsarImage() : getStandardPulsarImage();
PULSAR_CONTAINER = new PulsarContainer(PULSAR_IMAGE);
PULSAR_CONTAINER.start();
}
Expand All @@ -38,4 +39,18 @@ protected static String getHttpServiceUrl() {
return PULSAR_CONTAINER.getHttpServiceUrl();
}

private static boolean isRunningOnMacM1() {
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
String osArchitecture = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
return osName.contains("mac") && osArchitecture.equals("aarch64");
}

private static DockerImageName getStandardPulsarImage() {
return DockerImageName.parse("apachepulsar/pulsar:2.10.1");
}

private static DockerImageName getMacM1PulsarImage() {
return DockerImageName.parse("kezhenxu94/pulsar").asCompatibleSubstituteFor("apachepulsar/pulsar");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@

package org.springframework.pulsar.core;

import java.util.Locale;

import org.testcontainers.containers.PulsarContainer;
import org.testcontainers.utility.DockerImageName;

public abstract class AbstractContainerBaseTests {

static final DockerImageName PULSAR_IMAGE = DockerImageName.parse("apachepulsar/pulsar:2.10.1");

static PulsarContainer PULSAR_CONTAINER;
static final PulsarContainer PULSAR_CONTAINER;

static {
final DockerImageName PULSAR_IMAGE = isRunningOnMacM1() ? getMacM1PulsarImage() : getStandardPulsarImage();
PULSAR_CONTAINER = new PulsarContainer(PULSAR_IMAGE);
PULSAR_CONTAINER.start();
}
Expand All @@ -38,4 +39,18 @@ protected static String getHttpServiceUrl() {
return PULSAR_CONTAINER.getHttpServiceUrl();
}

private static boolean isRunningOnMacM1() {
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
String osArchitecture = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
return osName.contains("mac") && osArchitecture.equals("aarch64");
}

private static DockerImageName getStandardPulsarImage() {
return DockerImageName.parse("apachepulsar/pulsar:2.10.1");
}

private static DockerImageName getMacM1PulsarImage() {
return DockerImageName.parse("kezhenxu94/pulsar").asCompatibleSubstituteFor("apachepulsar/pulsar");
}

}

0 comments on commit dfa1e36

Please sign in to comment.