Skip to content

Commit cf206ee

Browse files
committed
Support non-http urls, specifically tcp and add integration tests
1 parent 1ce4c60 commit cf206ee

8 files changed

Lines changed: 271 additions & 42 deletions

File tree

pom.xml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.honton.chas</groupId>
66
<artifactId>process-exec-maven-plugin</artifactId>
7-
<version>0.9</version>
7+
<version>0.9.1</version>
88
<packaging>maven-plugin</packaging>
99

1010
<name>Process execution maven plugin</name>
@@ -122,6 +122,12 @@
122122
<scope>test</scope>
123123
</dependency>
124124

125+
<dependency>
126+
<groupId>org.honton.chas.url</groupId>
127+
<artifactId>url-extension</artifactId>
128+
<version>0.0.1</version>
129+
</dependency>
130+
125131
</dependencies>
126132

127133
<build>
@@ -157,6 +163,23 @@
157163
<version>2.18.1</version>
158164
</plugin>
159165

166+
167+
<plugin>
168+
<artifactId>maven-invoker-plugin</artifactId>
169+
<version>2.0.0</version>
170+
<configuration>
171+
</configuration>
172+
<executions>
173+
<execution>
174+
<id>integration-test</id>
175+
<goals>
176+
<goal>verify</goal>
177+
<goal>run</goal>
178+
</goals>
179+
</execution>
180+
</executions>
181+
</plugin>
182+
160183
</plugins>
161184
</build>
162185

src/it/url/invoker.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = clean verify
2+
invoker.failureBehavior = fail-never

src/it/url/pom.xml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.honton.chas</groupId>
6+
<artifactId>process-exec-maven-plugin-url-test</artifactId>
7+
<version>0.9.1</version>
8+
9+
<description>Test URL integration with Process execution maven plugin</description>
10+
11+
<properties>
12+
<maven.compiler.source>1.7</maven.compiler.source>
13+
<maven.compiler.target>1.7</maven.compiler.target>
14+
15+
<!-- don't deploy -->
16+
<maven.deploy.skip>true</maven.deploy.skip>
17+
<maven.site.deploy.skip>true</maven.site.deploy.skip>
18+
<!-- don't install -->
19+
<maven.install.skip>true</maven.install.skip>
20+
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23+
</properties>
24+
25+
<dependencies>
26+
27+
<dependency>
28+
<groupId>org.honton.chas.zookeeper</groupId>
29+
<artifactId>zookeeper-url</artifactId>
30+
<version>0.0.1</version>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.honton.chas.url</groupId>
35+
<artifactId>url-extension</artifactId>
36+
<version>0.0.1</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>junit</groupId>
41+
<artifactId>junit</artifactId>
42+
<version>4.12</version>
43+
</dependency>
44+
45+
</dependencies>
46+
47+
<build>
48+
<plugins>
49+
50+
<plugin>
51+
<groupId>org.apache.maven.plugins</groupId>
52+
<artifactId>maven-failsafe-plugin</artifactId>
53+
<version>2.19.1</version>
54+
<executions>
55+
<execution>
56+
<goals>
57+
<goal>integration-test</goal>
58+
<goal>verify</goal>
59+
</goals>
60+
</execution>
61+
</executions>
62+
<configuration>
63+
<systemPropertyVariables>
64+
<port>${server.port}</port>
65+
</systemPropertyVariables>
66+
</configuration>
67+
</plugin>
68+
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-jar-plugin</artifactId>
72+
<version>3.0.2</version>
73+
<configuration>
74+
<archive>
75+
<manifest>
76+
<mainClass>org.honton.chas.process.example.Server</mainClass>
77+
</manifest>
78+
</archive>
79+
</configuration>
80+
</plugin>
81+
82+
<plugin>
83+
<groupId>org.codehaus.mojo</groupId>
84+
<artifactId>build-helper-maven-plugin</artifactId>
85+
<version>3.0.0</version>
86+
<executions>
87+
<execution>
88+
<goals>
89+
<goal>reserve-network-port</goal>
90+
</goals>
91+
<configuration>
92+
<portNames>
93+
<portName>server.port</portName>
94+
</portNames>
95+
</configuration>
96+
</execution>
97+
</executions>
98+
</plugin>
99+
100+
<plugin>
101+
<groupId>org.honton.chas</groupId>
102+
<artifactId>process-exec-maven-plugin</artifactId>
103+
<version>0.9.1</version>
104+
<executions>
105+
<execution>
106+
<phase>pre-integration-test</phase>
107+
<goals>
108+
<goal>start</goal>
109+
</goals>
110+
<configuration>
111+
<name>server</name>
112+
<healthCheckUrl>tcp://localhost:${server.port}</healthCheckUrl>
113+
<arguments>
114+
<argument>${java.home}/bin/java</argument>
115+
<argument>-jar</argument>
116+
<argument>${project.build.directory}/${project.build.finalName}.${project.packaging}</argument>
117+
<argument>${server.port}</argument>
118+
</arguments>
119+
</configuration>
120+
</execution>
121+
122+
<execution>
123+
<id>stop-all</id>
124+
<phase>post-integration-test</phase>
125+
<goals>
126+
<goal>stop-all</goal>
127+
</goals>
128+
</execution>
129+
</executions>
130+
</plugin>
131+
</plugins>
132+
133+
</build>
134+
135+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.honton.chas.process.example;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.io.InputStreamReader;
7+
import java.io.OutputStreamWriter;
8+
import java.io.Writer;
9+
import java.net.ServerSocket;
10+
import java.net.Socket;
11+
import java.nio.charset.StandardCharsets;
12+
13+
/**
14+
* Example server
15+
*/
16+
public class Server {
17+
18+
private final ServerSocket serverSocket;
19+
20+
Server(int port) throws IOException {
21+
serverSocket = new ServerSocket(port);
22+
}
23+
24+
private void serve() throws IOException {
25+
while (true) {
26+
acceptAndRespond();
27+
}
28+
}
29+
30+
private void acceptAndRespond() throws IOException {
31+
try(Socket connectionSocket = serverSocket.accept()) {
32+
InputStream is = connectionSocket.getInputStream();
33+
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
34+
Writer writer = new OutputStreamWriter(connectionSocket.getOutputStream(), StandardCharsets.UTF_8);
35+
writer.append(reader.readLine()).close();
36+
}
37+
}
38+
39+
public static void main(String argv[]) throws Exception {
40+
new Server(Integer.parseInt(argv[0])).serve();
41+
}
42+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.honton.chas.process.example;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.io.OutputStreamWriter;
7+
import java.io.Writer;
8+
import java.net.URL;
9+
import java.net.URLConnection;
10+
import java.nio.charset.StandardCharsets;
11+
import org.honton.chas.url.extension.urlhandler.UrlStreamHandlerRegistry;
12+
import org.junit.Assert;
13+
import org.junit.Test;
14+
15+
public class ClientIT {
16+
17+
@Test
18+
public void testTcpClient() throws IOException {
19+
UrlStreamHandlerRegistry.register();
20+
21+
URLConnection connection = new URL("tcp://127.0.0.1:" + System.getProperty("port")).openConnection();
22+
Writer writer = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8);
23+
writer.append("line\n").flush();
24+
25+
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
26+
Assert.assertEquals("line", reader.readLine());
27+
}
28+
}
29+

src/main/java/org/honton/chas/process/exec/maven/plugin/AbstractProcessMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public abstract class AbstractProcessMojo extends AbstractMojo {
3232

3333
public void setHealthCheckUrl(String url) throws MalformedURLException {
3434
this.healthCheckUrl = new HealthCheckUrl();
35-
this.healthCheckUrl.setUrl(new URL(url));
35+
this.healthCheckUrl.setUrl(url);
3636
}
3737

3838
@Parameter(property = "exec.healthCheckValidateSsl", defaultValue = "true")

src/main/java/org/honton/chas/process/exec/maven/plugin/HealthCheckUrl.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.honton.chas.process.exec.maven.plugin;
22

3+
import java.net.MalformedURLException;
34
import java.net.URL;
45
import java.util.Properties;
6+
import org.honton.chas.url.extension.urlhandler.UrlStreamHandlerRegistry;
57

68
public class HealthCheckUrl {
79
private URL url;
@@ -15,8 +17,14 @@ public Properties getHeaders() {
1517
return headers;
1618
}
1719

18-
public void setUrl(URL url) {
19-
this.url = url;
20+
public void setUrl(String url) throws MalformedURLException {
21+
try {
22+
this.url = new URL(url);
23+
}
24+
catch (MalformedURLException e) {
25+
UrlStreamHandlerRegistry.register();
26+
this.url = new URL(url);
27+
}
2028
}
2129

2230
@Override

0 commit comments

Comments
 (0)