Skip to content

Commit

Permalink
add integration test for testcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
jetoile committed Feb 11, 2019
1 parent 304f8d7 commit 32f32bc
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 13 deletions.
1 change: 0 additions & 1 deletion hadoop-unit-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

<properties>
<mavenVersion>3.3.9</mavenVersion>
<!--<aetherVersion>1.0.0.v20140518</aetherVersion>-->
<aetherVersion>1.1.0</aetherVersion>
</properties>

Expand Down
5 changes: 5 additions & 0 deletions hadoop-unit-testcontainer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@
<version>${junit.version}</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.FixedHostPortGenericContainer;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.OutputFrame;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.output.ToStringConsumer;

import java.net.URL;
import java.util.Arrays;
Expand Down Expand Up @@ -176,6 +178,7 @@ private void build() {
container.withClasspathResourceMapping(local, remote, BindMode.valueOf(bindMode));
});
}

}

@Override
Expand All @@ -187,7 +190,7 @@ public Bootstrap start() {
build();
container.start();
container.followOutput(new Slf4jLogConsumer(LOGGER));
} catch (Exception e) {
} catch (Throwable e) {
LOGGER.error("unable to add testcontainer", e);
}
state = State.STARTED;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
#testcontainer.imagename=couchbase:4.5.0
#testcontainer.exposedports=8091,8092,8093,8094,11207,11210,11211,18091,18092,18093
testcontainer.imagename=alpine:3.2
testcontainer.exposedports=80
testcontainer.envs=MAGIC_NUMBER:42
testcontainer.labels=MAGIC_NUMBER:42
testcontainer.command=/bin/sh, -c, while true; do echo \"$MAGIC_NUMBER\" | nc -l -p 80; done
testcontainer.fixed.exposedports=21300:80
testcontainer.classpath.resources.mapping=hadoop-unit-default.properties:/hadoop-unit-default.properties:READ_ONLY
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.jetoile.hadoopunit.component;

import fr.jetoile.hadoopunit.HadoopBootstrap;
Expand Down Expand Up @@ -43,7 +56,7 @@ public static void setup() throws BootstrapException {


@AfterClass
public static void tearDown() throws BootstrapException {
public static void tearDown() {
HadoopBootstrap.INSTANCE.stopAll();
}

Expand Down
1 change: 1 addition & 0 deletions sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<module>knox-hbase-webhdfs</module>
<module>redis</module>
<module>confluent-integrationtest</module>
<module>testcontainer-integrationtest</module>
</modules>

<artifactId>sample</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion sample/solr-parquet-spark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
<artifactId>hadoop-unit-solrcloud</artifactId>
<groupId>fr.jetoile.hadoop</groupId>
<version>${hadoop-unit.version}</version>
<mainClass>fr.jetoile.hadoopunit.component.SolrCloudBootstrap</mainClass><properties>
<mainClass>fr.jetoile.hadoopunit.component.SolrCloudBootstrap</mainClass>
<properties>
<solr.dir>file://${project.basedir}/src/test/resources/solr</solr.dir>
</properties>
</componentArtifact>
Expand Down
108 changes: 108 additions & 0 deletions sample/testcontainer-integrationtest/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sample</artifactId>
<groupId>fr.jetoile.hadoop</groupId>
<version>3.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>testcontainer-integrationtest</artifactId>

<properties>
<jedis.version>2.9.0</jedis.version>
</properties>

<dependencies>
<dependency>
<groupId>fr.jetoile.hadoop</groupId>
<artifactId>hadoop-unit-commons</artifactId>
</dependency>

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>!travis</name>
</property>
</activation>

<build>
<plugins>
<plugin>
<artifactId>hadoop-unit-maven-plugin</artifactId>
<groupId>fr.jetoile.hadoop</groupId>
<version>${hadoop-unit.version}</version>
<executions>
<execution>
<id>start</id>
<goals>
<goal>embedded-start</goal>
</goals>
<phase>pre-integration-test</phase>
</execution>
<execution>
<id>embedded-stop</id>
<goals>
<goal>embedded-stop</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
<configuration>
<components>
<componentArtifact implementation="fr.jetoile.hadoopunit.ComponentArtifact">
<componentName>TESTCONTAINER</componentName>
<artifactId>hadoop-unit-testcontainer</artifactId>
<groupId>fr.jetoile.hadoop</groupId>
<version>${hadoop-unit.version}</version>
<mainClass>fr.jetoile.hadoopunit.component.TestContainerBootstrap</mainClass>
<properties>
<testcontainer.imagename>redis:5.0.3</testcontainer.imagename>
<testcontainer.exposedports>6379</testcontainer.exposedports>
<testcontainer.fixed.exposedports>21300:6379</testcontainer.fixed.exposedports>
</properties>
</componentArtifact>
</components>

</configuration>

</plugin>
</plugins>
</build>

</profile>
<profile>
<id>travis</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>travis</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.jetoile.hadoopunit.testcontainer;

import org.junit.Test;
import redis.clients.jedis.Jedis;

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


public class TestContainerBootstrapIntegrationTest {

@Test
public void testStartAndStopRedis() {
Jedis jedis = new Jedis("127.0.0.1", 21300);

jedis.hset("test", "foo", "FOO");
String foundObject = jedis.hget("test", "foo");

assertThat(foundObject).isEqualTo("FOO");

jedis.close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg %n

</pattern>
</encoder>
</appender>

<appender name="STDOUT_COLOR" class="ch.qos.logback.core.ConsoleAppender">
<withJansi>true</withJansi>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %green(%msg) %n

</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>

<!--<logger name="org.testcontainers" level="INFO"/>-->
<!--<logger name="com.github.dockerjava" level="WARN"/>-->

<logger name="fr.jetoile.hadoopunit" level="INFO">
<appender-ref ref="STDOUT_COLOR" />
</logger>
</configuration>

0 comments on commit 32f32bc

Please sign in to comment.