Skip to content

Commit f86d3a6

Browse files
authored
Merge pull request #1 from CDLUC3/pom
pom modifications to enable pom automation of tests
2 parents 3a5337f + 40d90c9 commit f86d3a6

File tree

3 files changed

+186
-63
lines changed

3 files changed

+186
-63
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,34 @@ ZooKeeper API for Merritt Microservices.
2626
- [Admin Function Mapping](design/queue-admin.md)
2727
- [Use Cases](design/use-cases.md)
2828

29-
## Start a local ZK instance (for integration tests)
29+
## Run integration tests with maven
3030

31+
Maven will start/stop an integration test instance of ZooKeeper as tests are executed.
32+
33+
```
34+
maven clean install
35+
```
36+
37+
## Run Integration tests in a debugger.
38+
39+
### To run from the command line or in a debugger
40+
41+
Make sure that the jar is up to date
42+
```
43+
mvn install -Ddocker.skip -DskipITs -Dmaven.test.skip=true
44+
```
45+
46+
Launch Containers
3147
```
3248
docker-compose up -d
3349
```
3450

51+
Run the junit tests in VSCode
52+
53+
```
54+
docker-compose down
55+
```
56+
3557
## Java Code -- Purpose
3658

3759
Ensure that the following enums implement the state transitions defined in [states.yml](states.yml)

pom.xml

Lines changed: 152 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,153 @@
1111
<name>Test</name>
1212
<url>http://maven.apache.org</url>
1313

14+
<dependencyManagement>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.cdlib.mrt</groupId>
18+
<artifactId>mrt-reflectoring-bom</artifactId>
19+
<version>1.0.0</version>
20+
<type>pom</type>
21+
<scope>import</scope>
22+
</dependency>
23+
</dependencies>
24+
</dependencyManagement>
25+
26+
<parent>
27+
<groupId>org.cdlib.mrt</groupId>
28+
<artifactId>mrt-parent-properties</artifactId>
29+
<version>1.0.0</version>
30+
</parent>
31+
32+
<!-- force UTF-8 -->
1433
<properties>
1534
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35+
<docker.skip>${env.SKIP_DOCKER_TEST}</docker.skip>
36+
<skipTests>${env.SKIP_DOCKER_TEST}</skipTests>
1637
</properties>
17-
1838
<dependencies>
19-
<dependency>
20-
<groupId>org.json</groupId>
21-
<artifactId>json</artifactId>
22-
<version>20240303</version>
23-
</dependency>
24-
<dependency>
25-
<groupId>org.yaml</groupId>
26-
<artifactId>snakeyaml</artifactId>
27-
<version>2.2</version>
28-
</dependency>
29-
<dependency>
30-
<groupId>com.google.code.gson</groupId>
31-
<artifactId>gson</artifactId>
32-
<version>2.10.1</version>
33-
</dependency>
34-
<dependency>
35-
<groupId>junit</groupId>
36-
<artifactId>junit</artifactId>
37-
<version>4.13.2</version>
38-
<scope>test</scope>
39-
</dependency>
40-
<dependency>
41-
<groupId>org.apache.zookeeper</groupId>
42-
<artifactId>zookeeper</artifactId>
43-
<version>3.8.3</version>
44-
</dependency>
45-
</dependencies>
39+
<dependency>
40+
<groupId>org.json</groupId>
41+
<artifactId>json</artifactId>
42+
<!--TODO: move this to the BOM-->
43+
<version>20240303</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.yaml</groupId>
47+
<artifactId>snakeyaml</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.google.code.gson</groupId>
51+
<artifactId>gson</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>junit</groupId>
55+
<artifactId>junit</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.apache.zookeeper</groupId>
60+
<artifactId>zookeeper</artifactId>
61+
</dependency>
62+
</dependencies>
4663
<build>
4764
<plugins>
65+
<plugin>
66+
<groupId>io.fabric8</groupId>
67+
<artifactId>docker-maven-plugin</artifactId>
68+
<version>${docker.maven.plugin.version}</version>
69+
<executions>
70+
<execution>
71+
<id>prepare-it-server</id>
72+
<phase>pre-integration-test</phase>
73+
<goals>
74+
<goal>start</goal>
75+
</goals>
76+
<configuration>
77+
<images>
78+
<image>
79+
<name>zookeeper:3.8.3</name>
80+
<alias>zoo</alias>
81+
<run>
82+
<ports>
83+
<port>zoo.port:2181</port>
84+
</ports>
85+
<wait>
86+
<time>2000</time>
87+
</wait>
88+
</run>
89+
</image>
90+
</images>
91+
</configuration>
92+
</execution>
93+
<execution>
94+
<id>remove-it-server</id>
95+
<phase>post-integration-test</phase>
96+
<goals>
97+
<goal>stop</goal>
98+
</goals>
99+
</execution>
100+
</executions>
101+
</plugin>
48102
<plugin>
49103
<groupId>org.apache.maven.plugins</groupId>
50-
<artifactId>maven-compiler-plugin</artifactId>
51-
<version>2.3.2</version>
104+
<artifactId>maven-failsafe-plugin</artifactId>
105+
<version>${maven.failsafe.plugin.version}</version>
106+
<executions>
107+
<execution>
108+
<goals>
109+
<goal>integration-test</goal>
110+
<goal>verify</goal>
111+
</goals>
112+
</execution>
113+
</executions>
114+
<configuration>
115+
<includes>
116+
<include>**/*IT</include>
117+
</includes>
118+
<environmentVariables>
119+
<zoo.port>${zoo.port}</zoo.port>
120+
</environmentVariables>
121+
</configuration>
122+
</plugin>
123+
<plugin>
124+
<groupId>org.apache.maven.plugins</groupId>
125+
<artifactId>maven-surefire-plugin</artifactId>
126+
<version>${maven.surefire.plugin.version}</version>
52127
<configuration>
53-
<source>1.8</source>
54-
<target>1.8</target>
128+
<!-- Includes Test* and *Test by default -->
129+
<!-- skips surefire tests without skipping failsafe tests.
130+
Property
131+
value seems to magically default to false -->
132+
<skipTests>${skip.surefire.tests}</skipTests>
55133
</configuration>
56134
</plugin>
135+
<plugin>
136+
<groupId>org.jacoco</groupId>
137+
<artifactId>jacoco-maven-plugin</artifactId>
138+
<version>${jacoco.maven.plugin.version}</version>
139+
<executions>
140+
<execution>
141+
<id>default-prepare-agent</id>
142+
<goals>
143+
<goal>prepare-agent</goal>
144+
</goals>
145+
</execution>
146+
<execution>
147+
<id>default-report</id>
148+
<phase>verify</phase>
149+
<goals>
150+
<goal>report</goal>
151+
</goals>
152+
</execution>
153+
</executions>
154+
</plugin>
57155
<plugin>
58156
<groupId>org.apache.maven.plugins</groupId>
59-
<artifactId>maven-jar-plugin</artifactId>
60-
<version>2.4</version>
157+
<artifactId>maven-compiler-plugin</artifactId>
158+
<version>${maven.compiler.plugin.version}</version>
61159
<configuration>
62-
<archive>
63-
<manifest>
64-
<addClasspath>true</addClasspath>
65-
<mainClass>org.cdlib.mrt.zk.Batch</mainClass>
66-
</manifest>
67-
</archive>
160+
<compilerArgument>${compilerArgument}</compilerArgument>
68161
</configuration>
69162
</plugin>
70163
<plugin>
@@ -81,27 +174,27 @@
81174
</execution>
82175
</executions>
83176
</plugin>
84-
<plugin>
85-
<groupId>org.apache.maven.plugins</groupId>
86-
<artifactId>maven-surefire-plugin</artifactId>
87-
<version>2.22.2</version>
88-
<configuration>
89-
<!-- Includes Test* and *Test by default -->
90-
<!-- skips surefire tests without skipping failsafe tests.
177+
<plugin>
178+
<groupId>org.apache.maven.plugins</groupId>
179+
<artifactId>maven-surefire-plugin</artifactId>
180+
<version>${maven.surefire.plugin.version}</version>
181+
<configuration>
182+
<!-- Includes Test* and *Test by default -->
183+
<!-- skips surefire tests without skipping failsafe tests.
91184
Property
92185
value seems to magically default to false -->
93-
<skipTests>${skip.surefire.tests}</skipTests>
94-
</configuration>
95-
</plugin>
96-
<plugin>
97-
<groupId>org.apache.maven.plugins</groupId>
98-
<artifactId>maven-javadoc-plugin</artifactId>
99-
<version>3.6.3</version>
100-
<configuration>
101-
<notimestamp>true</notimestamp>
102-
</configuration>
103-
</plugin>
104-
</plugins>
186+
<skipTests>${skip.surefire.tests}</skipTests>
187+
</configuration>
188+
</plugin>
189+
<plugin>
190+
<groupId>org.apache.maven.plugins</groupId>
191+
<artifactId>maven-javadoc-plugin</artifactId>
192+
<version>3.6.3</version>
193+
<configuration>
194+
<notimestamp>true</notimestamp>
195+
</configuration>
196+
</plugin>
197+
</plugins>
105198
<directory>target</directory>
106199
<outputDirectory>target/classes</outputDirectory>
107200
<finalName>${project.artifactId}-${project.version}</finalName>

src/test/java/org/cdlib/mrt/zk/ZKTest.java renamed to src/test/java/org/cdlib/mrt/zk/ZKTestIT.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.json.JSONException;
2828
import org.json.JSONObject;
2929

30-
public class ZKTest {
30+
public class ZKTestIT {
3131
enum Tests {
3232
test_read_write_from_zk,
3333
test_sequential_node_mapping,
@@ -58,8 +58,10 @@ enum Tests {
5858
private JSONObject testCasesJson;
5959
private Tests currentTest;
6060
private Map<String, String> remap = new HashMap<>();
61+
private static int port = 8084;
62+
private static String host = "localhost";
6163

62-
public ZKTest() throws IOException {
64+
public ZKTestIT() throws IOException {
6365
Yaml yaml = new Yaml();
6466
final Object testCasesYaml = yaml.load(new FileReader(new File("test-cases.yml")));
6567
//Note that jackson yaml parsing does not support anchors and references, so Gson is used instead.
@@ -68,11 +70,17 @@ public ZKTest() throws IOException {
6870
String json = gson.toJson(testCasesYaml,LinkedHashMap.class);
6971
testCasesJson = new JSONObject(json);
7072

73+
try {
74+
port = Integer.parseInt(System.getenv("zoo.port"));
75+
} catch (NumberFormatException e) {
76+
System.err.println("zoo.port not set... using default value");
77+
}
78+
7179
zk = createZk();
7280
}
7381

7482
public static ZooKeeper createZk() throws IOException {
75-
return new ZooKeeper("localhost:8084", 100, null);
83+
return new ZooKeeper(String.format("%s:%d", host, port), 100, null);
7684
}
7785

7886
public String makePath(String path, String cp) {

0 commit comments

Comments
 (0)