Skip to content

Commit 0e84540

Browse files
committed
Fix system properties handling to work with both Maven and Ant
1 parent f11d2dd commit 0e84540

File tree

9 files changed

+100
-62
lines changed

9 files changed

+100
-62
lines changed

build.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@
340340
<jvmarg value="-Dmake.bin=${make.bin}"/>
341341
<jvmarg value="-Drabbitmqctl.bin=${rabbitmqctl.bin}"/>
342342
<jvmarg value="-Dsibling.rabbitmq_test.dir=${sibling.rabbitmq_test.dir}"/>
343+
<jvmarg value="-Dbroker.hostname=${broker.hostname}"/>
344+
<jvmarg value="-Dbroker.port=${broker.port}"/>
345+
<jvmarg value="-Dbroker.sslport=${broker.sslport}"/>
343346

344347
<jvmarg value="-Dkeystore.path=${CLIENT_KEYSTORE}"/>
345348
<jvmarg value="-Dkeystore.empty.path=${CLIENT_KEYSTORE_EMPTY}"/>
@@ -364,6 +367,9 @@
364367
<jvmarg value="-Dmake.bin=${make.bin}"/>
365368
<jvmarg value="-Drabbitmqctl.bin=${rabbitmqctl.bin}"/>
366369
<jvmarg value="-Dsibling.rabbitmq_test.dir=${sibling.rabbitmq_test.dir}"/>
370+
<jvmarg value="-Dbroker.hostname=${broker.hostname}"/>
371+
<jvmarg value="-Dbroker.port=${broker.port}"/>
372+
<jvmarg value="-Dbroker.sslport=${broker.sslport}"/>
367373

368374
<formatter type="plain"/>
369375
<formatter type="xml"/>
@@ -380,6 +386,9 @@
380386
<jvmarg value="-Dmake.bin=${make.bin}"/>
381387
<jvmarg value="-Drabbitmqctl.bin=${rabbitmqctl.bin}"/>
382388
<jvmarg value="-Dsibling.rabbitmq_test.dir=${sibling.rabbitmq_test.dir}"/>
389+
<jvmarg value="-Dbroker.hostname=${broker.hostname}"/>
390+
<jvmarg value="-Dbroker.port=${broker.port}"/>
391+
<jvmarg value="-Dbroker.sslport=${broker.sslport}"/>
383392

384393
<formatter type="plain"/>
385394
<formatter type="xml"/>
@@ -398,6 +407,9 @@
398407
<jvmarg value="-Dmake.bin=${make.bin}"/>
399408
<jvmarg value="-Drabbitmqctl.bin=${rabbitmqctl.bin}"/>
400409
<jvmarg value="-Dsibling.rabbitmq_test.dir=${sibling.rabbitmq_test.dir}"/>
410+
<jvmarg value="-Dbroker.hostname=${broker.hostname}"/>
411+
<jvmarg value="-Dbroker.port=${broker.port}"/>
412+
<jvmarg value="-Dbroker.sslport=${broker.sslport}"/>
401413

402414
<formatter type="plain"/>
403415
<formatter type="xml"/>

pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
33
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
44
<modelVersion>4.0.0</modelVersion>
5-
5+
66
<groupId>com.rabbitmq</groupId>
77
<artifactId>amqp-client</artifactId>
88
<version>3.6.1-SNAPSHOT</version>
99
<packaging>jar</packaging>
10-
10+
1111
<name>RabbitMQ Java Client</name>
1212
<description>RabbitMQ Java client</description>
1313
<url>http://www.rabbitmq.com</url>
14-
14+
1515
<licenses>
1616
<license>
1717
<name>ASL 2.0</name>
@@ -29,12 +29,12 @@
2929
<distribution>repo</distribution>
3030
</license>
3131
</licenses>
32-
32+
3333
<scm>
3434
<url>https://github.com/rabbitmq/rabbitmq-java-client.git</url>
3535
<connection>scm:git:https://github.com/rabbitmq/rabbitmq-java-client.git</connection>
3636
</scm>
37-
37+
3838
<developers>
3939
<developer>
4040
<id>rabbitmq.team</id>
@@ -44,11 +44,11 @@
4444
</roles>
4545
</developer>
4646
</developers>
47-
47+
4848
<properties>
4949
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5050
</properties>
51-
51+
5252
<dependencies>
5353
<dependency>
5454
<groupId>commons-cli</groupId>
@@ -69,7 +69,7 @@
6969
<scope>test</scope>
7070
</dependency>
7171
</dependencies>
72-
72+
7373
<build>
7474
<plugins>
7575
<!-- Clean generated sources at clean phase -->
@@ -266,12 +266,12 @@
266266
</plugin>
267267
</plugins>
268268
</build>
269-
269+
270270
<distributionManagement>
271271
<repository>
272272
<id>sonatype-nexus-staging</id>
273273
<name>Nexus Release Repository</name>
274274
<url>http://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
275275
</repository>
276276
</distributionManagement>
277-
</project>
277+
</project>
Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.rabbitmq.client.test;
22

33
import java.io.File;
4+
import java.io.IOException;
45
import java.net.Socket;
56
import java.nio.file.FileSystems;
67
import java.util.Properties;
@@ -9,48 +10,87 @@
910
import junit.framework.TestResult;
1011
import junit.framework.TestSuite;
1112

12-
import org.junit.Assume;
13+
import com.rabbitmq.tools.Host;
1314

1415
public abstract class AbstractRMQTestSuite extends TestSuite {
1516
private static final String DEFAULT_SSL_HOSTNAME = "localhost";
1617
private static final int DEFAULT_SSL_PORT = 5671;
1718

18-
private static boolean buildPropertiesFound = false;
19+
private static boolean buildSSLPropertiesFound = false;
1920

20-
private static final Properties TESTS_PROPS = new Properties(System.getProperties());
2121
static {
22-
TESTS_PROPS.setProperty("make.bin", System.getenv("MAKE") == null ? "make" : System.getenv("MAKE"));
22+
Properties TESTS_PROPS = new Properties(System.getProperties());
23+
TESTS_PROPS.setProperty("make.bin",
24+
System.getenv("MAKE") == null ? "make" : System.getenv("MAKE"));
2325
try {
24-
TESTS_PROPS.load(AbstractRMQTestSuite.class.getClassLoader().getResourceAsStream("build.properties"));
25-
TESTS_PROPS.load(AbstractRMQTestSuite.class.getClassLoader().getResourceAsStream("config.properties"));
26-
buildPropertiesFound = true;
26+
TESTS_PROPS.load(Host.class.getClassLoader().getResourceAsStream("build.properties"));
27+
TESTS_PROPS.load(Host.class.getClassLoader().getResourceAsStream("config.properties"));
2728
} catch (Exception e) {
28-
System.out
29-
.println("build.properties or config.properties not found in classpath,copy build.properties and config.properties into src/test/resources, ignore this message if running with ant");
29+
System.out.println(
30+
"\"build.properties\" or \"config.properties\" not found" +
31+
" in classpath. Please copy \"build.properties\" and" +
32+
" \"config.properties\" into src/test/resources. Ignore" +
33+
" this message if running with ant.");
34+
} finally {
35+
System.setProperties(TESTS_PROPS);
3036
}
3137
}
3238

33-
public AbstractRMQTestSuite() {
34-
System.setProperties(TESTS_PROPS);
39+
public static boolean requiredProperties() {
40+
/* GNU Make. */
41+
String make = Host.makeCommand();
42+
boolean isGNUMake = false;
43+
if (make != null) {
44+
try {
45+
Process makeProc = Host.executeCommandIgnoringErrors(make + " --version");
46+
String makeVersion = Host.capture(makeProc.getInputStream());
47+
isGNUMake = makeVersion.startsWith("GNU Make");
48+
} catch (IOException e) {}
49+
}
50+
if (!isGNUMake) {
51+
System.err.println(
52+
"GNU Make required; please set \"make.bin\" system property" +
53+
" or \"$MAKE\" environment variable");
54+
return false;
55+
}
56+
57+
/* Path to rabbitmq_test. */
58+
String rabbitmq_test = Host.rabbitmqTestDir();
59+
if (rabbitmq_test == null || !new File(rabbitmq_test).isDirectory()) {
60+
System.err.println(
61+
"rabbitmq_test required; please set \"sibling.rabbitmq_test.dir\" system" +
62+
" property");
63+
return false;
64+
}
65+
66+
/* Path to rabbitmqctl. */
67+
String rabbitmqctl = Host.rabbitmqctlCommand();
68+
if (rabbitmqctl == null || !new File(rabbitmqctl).isFile()) {
69+
System.err.println(
70+
"rabbitmqctl required; please set \"rabbitmqctl.bin\" system" +
71+
" property");
72+
return false;
73+
}
74+
75+
return true;
3576
}
3677

3778
public static boolean isUnderUmbrella() {
3879
return new File("../../UMBRELLA.md").isFile();
3980
}
4081

4182
public static boolean isSSLAvailable() {
42-
/*
43-
* FIXME: This method tries to reproduce what was done in Ant's
44-
* build.xml. It's probably not enough to have a working SSL
45-
* testsuite with Maven.
46-
*/
47-
System.setProperty("SSL_CERTS_DIR", System.getenv("SSL_CERTS_DIR"));
48-
String sslClientCertsDir = System.getProperty("SSL_CERTS_DIR") +
83+
String SSL_CERTS_DIR = System.getenv("SSL_CERTS_DIR");
84+
String hostname = System.getProperty("broker.hostname");
85+
String port = System.getProperty("broker.sslport");
86+
if (SSL_CERTS_DIR == null || hostname == null || port == null)
87+
return false;
88+
89+
String sslClientCertsDir = SSL_CERTS_DIR +
4990
FileSystems.getDefault().getSeparator() + "client";
5091
// If certificate is present and some server is listening on port 5671
5192
if (new File(sslClientCertsDir).exists() &&
52-
checkServerListening(DEFAULT_SSL_HOSTNAME, DEFAULT_SSL_PORT)) {
53-
System.setProperty("SSL_AVAILABLE", sslClientCertsDir);
93+
checkServerListening(hostname, Integer.parseInt(port))) {
5494
return true;
5595
} else
5696
return false;
@@ -71,11 +111,4 @@ private static boolean checkServerListening(String host, int port) {
71111
}
72112
}
73113
}
74-
75-
public void runTest(Test test, TestResult result) {
76-
// Run the tests only if build.properties was found
77-
Assume.assumeTrue(buildPropertiesFound);
78-
test.run(result);
79-
}
80-
81114
}

src/test/java/com/rabbitmq/client/test/functional/FunctionalTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
public class FunctionalTests extends AbstractRMQTestSuite {
2828
public static TestSuite suite() {
2929
TestSuite suite = new TestSuite("functional");
30+
if (!requiredProperties()) return suite;
31+
if (!isUnderUmbrella()) return suite;
3032
add(suite);
3133
return suite;
3234
}

src/test/java/com/rabbitmq/client/test/server/HATests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
public class HATests extends AbstractRMQTestSuite {
2727
// this is horrific
2828
public static boolean HA_TESTS_RUNNING = false;
29-
29+
3030
public static TestSuite suite() {
3131
TestSuite suite = new TestSuite("server-tests");
32-
if(!isUnderUmbrella()) return suite;
32+
if (!requiredProperties()) return suite;
33+
if (!isUnderUmbrella()) return suite;
3334
suite.addTestSuite(SetUp.class);
3435
FunctionalTests.add(suite);
3536
ServerTests.add(suite);

src/test/java/com/rabbitmq/client/test/server/ServerTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
package com.rabbitmq.client.test.server;
1818

1919
import junit.framework.TestSuite;
20+
import org.junit.runner.RunWith;
21+
import org.junit.runners.Suite;
2022

2123
import com.rabbitmq.client.test.AbstractRMQTestSuite;
2224

2325
public class ServerTests extends AbstractRMQTestSuite {
26+
2427
public static TestSuite suite() {
2528
TestSuite suite = new TestSuite("server-tests");
26-
if(!isUnderUmbrella()) return suite;
29+
if (!requiredProperties()) return suite;
30+
if (!isUnderUmbrella()) return suite;
2731
add(suite);
2832
return suite;
2933
}

src/test/java/com/rabbitmq/client/test/ssl/SSLTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class SSLTests extends AbstractRMQTestSuite {
2525
public static TestSuite suite() {
2626
TestSuite suite = new TestSuite("ssl");
2727
//Skip the tests if not under umbrella and not SSL available
28-
if(!(isUnderUmbrella() && isSSLAvailable())) return suite;
28+
if (!requiredProperties()) return suite;
29+
if (!(isUnderUmbrella() && isSSLAvailable())) return suite;
2930
suite.addTestSuite(UnverifiedConnection.class);
3031
suite.addTestSuite(VerifiedConnection.class);
3132
suite.addTestSuite(BadVerifiedConnection.class);

src/test/java/com/rabbitmq/tools/Host.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,12 @@
2424
import java.io.InputStreamReader;
2525
import java.util.ArrayList;
2626
import java.util.List;
27-
import java.util.Properties;
2827

2928
import com.rabbitmq.client.impl.NetworkConnection;
3029

3130
public class Host {
32-
33-
static {
34-
Properties TESTS_PROPS = new Properties(System.getProperties());
35-
TESTS_PROPS.setProperty("make.bin", System.getenv("MAKE") == null ? "make" : System.getenv("MAKE"));
36-
try {
37-
TESTS_PROPS.load(Host.class.getClassLoader().getResourceAsStream("build.properties"));
38-
TESTS_PROPS.load(Host.class.getClassLoader().getResourceAsStream("config.properties"));
39-
} catch (Exception e) {
40-
System.out
41-
.println("build.properties or config.properties not found in classpath,copy build.properties and config.properties into src/test/resources, ignore this message if running with ant");
42-
}finally {
43-
System.setProperties(TESTS_PROPS);
44-
}
45-
}
46-
47-
48-
private static String capture(InputStream is)
31+
32+
public static String capture(InputStream is)
4933
throws IOException
5034
{
5135
BufferedReader br = new BufferedReader(new InputStreamReader(is));
@@ -124,17 +108,17 @@ public static Process invokeMakeTarget(String command) throws IOException {
124108
" " + command);
125109
}
126110

127-
private static String makeCommand()
111+
public static String makeCommand()
128112
{
129113
return System.getProperty("make.bin");
130114
}
131115

132-
private static String rabbitmqctlCommand()
116+
public static String rabbitmqctlCommand()
133117
{
134118
return System.getProperty("rabbitmqctl.bin");
135119
}
136120

137-
private static String rabbitmqTestDir()
121+
public static String rabbitmqTestDir()
138122
{
139123
return System.getProperty("sibling.rabbitmq_test.dir");
140124
}

src/test/resources/config.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
broker.hostname=localhost
22
broker.port=5672
3+
broker.sslport=5671
34
test.main=com.rabbitmq.examples.TestMain
45
test.producer.rate-limit=100000
56
test.producer.message-count=30000

0 commit comments

Comments
 (0)