Skip to content

Commit

Permalink
109 integration tests using docker fail with mac m1 arm (#114)
Browse files Browse the repository at this point in the history
- Fix testcontainers for integration tests
- startDockerContainer takes http endpoint for up check
- Exclude jna from spring-shell as more recent version is required by testcontainers
- Bump rocksdbjni to 7.1.2
- Use testcontainers 9baede using jitpack to solve testcontainers/testcontainers-java#5121
- Fix Mule integration tests by excluding WMQ when running on Mac M1
- Move dependency to RocksDB into openrewrite module
  • Loading branch information
fabapp2 committed May 5, 2022
1 parent 5b21820 commit 35ff928
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 44 deletions.
12 changes: 9 additions & 3 deletions applications/spring-shell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-starter</artifactId>
<exclusions>
<exclusion>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -79,9 +85,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.16.3</version>
<groupId>com.github.testcontainers.testcontainers-java</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void happyPath() {

executeMavenGoals(getTestDir(), "package", "spring-boot:build-image");

int port = startDockerContainer("jboss-sample:1.0.0", 8080);
Integer port = startDockerContainer("jboss-sample:1.0.0", "/HelloWorld", 8080);

TestRestTemplate testRestTemplate = new TestRestTemplate();
String response = testRestTemplate.getForObject("http://localhost:" + port + "/HelloWorld", String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void migrateSimpleJeeApp() {
assertThat(ejbJarXml).doesNotExist();

executeMavenGoals(getTestDir(), "clean", "package", "spring-boot:build-image");
int port = startDockerContainer("jee-app:8.0.5-SNAPSHOT", 8080);
Integer port = startDockerContainer("jee-app:8.0.5-SNAPSHOT", "/HelloWorld", 8080);

TestRestTemplate testRestTemplate = new TestRestTemplate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
package org.springframework.sbm;

import com.rabbitmq.client.Channel;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.jruby.RubyProcess;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.sbm.mule.amqp.RabbitMqChannelBuilder;
import org.springframework.sbm.mule.amqp.RabbitMqListener;
import org.springframework.sbm.mule.wmq.WmqListener;
import org.springframework.sbm.mule.wmq.WmqSender;
import org.springframework.sbm.mule.wmq.JmsListener;
import org.springframework.sbm.mule.wmq.JmsSender;
import org.springframework.web.client.RestTemplate;
import org.testcontainers.containers.Network;

Expand All @@ -37,12 +39,14 @@

import static org.assertj.core.api.Assertions.assertThat;

@TestMethodOrder(MethodOrderer.MethodName.class)
public class BootifySimpleMuleAppIntegrationTest extends IntegrationTestBaseClass {

private static final String FIRST_QUEUE_NAME = "sbm-integration-queue-one";
private static final String SECOND_QUEUE_NAME = "sbm-integration-queue-two";
private String messageContent;
private final RestTemplate restTemplate = new RestTemplate();
private static RunningNetworkedContainer rabbitMqContainer;

@Override
protected String getTestSubDir() {
Expand All @@ -56,23 +60,47 @@ public void setUp() {
messageContent = "Integration test message " + UUID.randomUUID();
}

@BeforeAll
public static void beforeAll() {
IntegrationTestBaseClass.beforeAll();
// start RabbitMQ
rabbitMqContainer = startDockerContainer(
new NetworkedContainer(
"rabbitmq:3-management",
List.of(5672, 15672),
"amqphost"),
null,
Collections.emptyMap());
if(!rabbitMqContainer.getContainer().isRunning()) {
throw new RuntimeException("RabbitMQ container could not be started");
}
}

@AfterAll
public static void afterAll() {
if(rabbitMqContainer != null && rabbitMqContainer.getContainer() != null) {
rabbitMqContainer.getContainer().stop();
}
}

@Test
@Tag("integration")
@DisabledIfSystemProperty(named= "os.arch", matches = "aarch64", disabledReason = "imbcom/mq image not supported with Apple Silicon")
void t1_testWebsphereMqMigration() throws JMSException, InterruptedException {
checkWmqIntegration(rabbitMqContainer.getNetwork());
}

@Test
@Tag("integration")
public void springIntegrationWorks() throws IOException, TimeoutException, InterruptedException, JMSException {
public void t0_springIntegrationWorks() throws IOException, TimeoutException, InterruptedException {
intializeTestProject();
scanProject();
applyRecipe("initialize-spring-boot-migration");
applyRecipe("migrate-mule-to-boot");

executeMavenGoals(getTestDir(), "clean", "package", "spring-boot:build-image");

RunningNetworkedContainer rabbitMqContainer = startDockerContainer(
new NetworkedContainer(
"rabbitmq:3-management",
List.of(5672, 15672),
"amqphost"),
null,
Collections.emptyMap());

int amqpPort = rabbitMqContainer.getContainer().getMappedPort(5672);
Channel ampqChannel = new RabbitMqChannelBuilder().initializeChannelAndQueues(amqpPort);

Expand All @@ -84,9 +112,11 @@ public void springIntegrationWorks() throws IOException, TimeoutException, Inter
checkSendHttpMessage(container.getContainer().getMappedPort(9081));
checkInboundGatewayHttpMessage(container.getContainer().getMappedPort(9081));
checkRabbitMqIntegration(ampqChannel);
checkWmqIntegration(rabbitMqContainer.getNetwork());
}




private void checkRabbitMqIntegration(Channel amqpChannel)
throws IOException, InterruptedException {

Expand All @@ -101,7 +131,7 @@ private void checkRabbitMqIntegration(Channel amqpChannel)
assertThat(latch).isTrue();
}

private RunningNetworkedContainer startWmqContainer(Network rabbitContainerNetwork) {
private RunningNetworkedContainer startJmsContainer(Network rabbitContainerNetwork) {
Map<String, String> wmqMap = new HashMap<>();
wmqMap.put("LICENSE", "accept");
wmqMap.put("MQ_QMGR_NAME", "QM1");
Expand All @@ -116,16 +146,16 @@ private RunningNetworkedContainer startWmqContainer(Network rabbitContainerNetwo
}

private void checkWmqIntegration(Network rabbitMqNetwork) throws InterruptedException, JMSException {
RunningNetworkedContainer wmqContainer = startWmqContainer(rabbitMqNetwork);
WmqSender wmqSender = new WmqSender();
RunningNetworkedContainer jmsContainer = startJmsContainer(rabbitMqNetwork);
JmsSender jmsSender = new JmsSender();
CountDownLatch latch = new CountDownLatch(1);
WmqListener wmqListener = new WmqListener();
int mappedPort = wmqContainer.getContainer().getMappedPort(1414);
JmsListener wmqListener = new JmsListener();
int mappedPort = jmsContainer.getContainer().getMappedPort(1414);
wmqListener.listenForMessage(mappedPort, "DEV.QUEUE.2", message -> {
System.out.println(" [x] Received wmq message: '" + message + "'");
latch.countDown();
});
wmqSender.sendMessage(mappedPort, "DEV.QUEUE.1", "Test WMQ message");
jmsSender.sendMessage(mappedPort, "DEV.QUEUE.1", "Test WMQ message");
boolean latchResult = latch.await(1000000, TimeUnit.MILLISECONDS);
assertThat(latchResult).isTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.springframework.util.SocketUtils;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

import java.io.File;
Expand Down Expand Up @@ -78,14 +79,14 @@ public abstract class IntegrationTestBaseClass {
/**
* Points to the source root directory where example projects are expected.
*
* @see {@link #getTestSubDir()}.
* See {@link #getTestSubDir()}.
*/
public static final String TESTCODE_DIR = "src/test/resources/testcode/";

/**
* Points to the target root directory where example projects will be copied to.
*
* @see {@link #getTestSubDir()}.
* See {@link #getTestSubDir()}.
*/
public static final String INTEGRATION_TEST_DIR = "./target/sbm-integration-test/";
@Autowired
Expand All @@ -105,7 +106,8 @@ public abstract class IntegrationTestBaseClass {
@BeforeAll
public static void beforeAll() {
if (System.getenv("MAVEN_HOME") == null) {
throw new RuntimeException("You must set $MAVEN_HOME on your system for the integration test to run.");
System.err.println("You must set $MAVEN_HOME on your system for the integration test to run.");
throw new RuntimeException();
}
System.setProperty("maven.home", System.getenv("MAVEN_HOME"));
}
Expand Down Expand Up @@ -233,9 +235,6 @@ protected void executeMavenGoals(Path executionDir, String... goals) {
}
}

/**
*
*/
protected Path writeFile(String content, String fileName) {
try {
return Files.writeString(getTestDir().resolve(fileName), content);
Expand Down Expand Up @@ -315,14 +314,19 @@ protected String loadJavaFile(String packageName, String className) {
}
}

protected int startDockerContainer(String image, Integer... ports) {
GenericContainer genericContainer = new GenericContainer(DockerImageName.parse(image)).withExposedPorts(ports);
/**
* Starts {@code image} as Docker container exposing {@code ports} and waiting for {@code httpEndpoint} to be available.
*/
protected Integer startDockerContainer(String image, String httpEndpoint, Integer... ports) {
GenericContainer genericContainer = new GenericContainer(DockerImageName.parse(image))
.withExposedPorts(ports)
.waitingFor(Wait.forHttp(httpEndpoint));
genericContainer.start();
return genericContainer.getFirstMappedPort();
}

protected RunningNetworkedContainer startDockerContainer(NetworkedContainer networkedContainer,
Network attachNetwork, Map<String, String> envMap) {
protected static RunningNetworkedContainer startDockerContainer(NetworkedContainer networkedContainer,
Network attachNetwork, Map<String, String> envMap) {

Network network = attachNetwork == null ? Network.newNetwork() : attachNetwork;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import javax.jms.*;
import java.util.function.Consumer;

public class WmqListener {
public class JmsListener {

public void listenForMessage(int port, String queueName, final Consumer<String> messageConsumer) throws JMSException {
WmqFactory wmqFactory = new WmqFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import javax.jms.*;

public class WmqSender {
public class JmsSender {

public void sendMessage(int port, String queueName, String messageContent) throws JMSException {
WmqFactory wmqFactory = new WmqFactory();
Expand Down
6 changes: 0 additions & 6 deletions components/sbm-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@
<version>0.10.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.rocksdb</groupId>
<artifactId>rocksdbjni</artifactId>
<version>7.1.1</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions components/sbm-openrewrite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java-11</artifactId>
</dependency>
<dependency>
<groupId>org.rocksdb</groupId>
<artifactId>rocksdbjni</artifactId>
<version>7.1.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<openrewrite.spring.version>4.14.1</openrewrite.spring.version>
<spring-boot.version>2.5.12</spring-boot.version>
<progressbar.version>0.9.0</progressbar.version>
<testcontainers.version>1.16.3</testcontainers.version>
<testcontainers.version>9baedef17589ff70f7a585c809e0b1beb27eff62</testcontainers.version>
<maven-invoker.version>3.0.1</maven-invoker.version>
<spring-shell-starter.version>2.0.1.RELEASE</spring-shell-starter.version>
<shrinkwrap.resolvers.version>3.1.4</shrinkwrap.resolvers.version>
Expand Down Expand Up @@ -77,6 +77,11 @@
<name>mavencentral</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
<!-- TODO: remove after b umping testcontainers to > 1.17.1 -->
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencyManagement>
Expand Down

0 comments on commit 35ff928

Please sign in to comment.