This is an automated email from the ASF dual-hosted git repository.
pascalschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 134df12 camel-xmpp: Do not reuse a static EmbeddedXmppTestServer
instance, but create a new one for each test. I hope this improves the test
stability on build.apache.org.
134df12 is described below
commit 134df1228ab9c3f2444ce2ab03e3ac277a6edd77
Author: Pascal Schumacher <[email protected]>
AuthorDate: Thu Feb 15 20:17:37 2018 +0100
camel-xmpp: Do not reuse a static EmbeddedXmppTestServer instance, but
create a new one for each test. I hope this improves the test stability on
build.apache.org.
---
.../component/xmpp/EmbeddedXmppTestServer.java | 73 ++++++++++------------
.../component/xmpp/XmppDeferredConnectionTest.java | 20 ++++--
.../component/xmpp/XmppMultiUserChatTest.java | 17 ++++-
.../component/xmpp/XmppProducerConcurrentTest.java | 18 +++++-
.../component/xmpp/XmppRobustConnectionTest.java | 24 +++++--
.../camel/component/xmpp/XmppRouteChatTest.java | 18 +++++-
...ppRouteMultipleProducersSingleConsumerTest.java | 19 ++++--
.../apache/camel/component/xmpp/XmppRouteTest.java | 7 ++-
8 files changed, 129 insertions(+), 67 deletions(-)
diff --git
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/EmbeddedXmppTestServer.java
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/EmbeddedXmppTestServer.java
index 20b14de..1d8dcb9 100644
---
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/EmbeddedXmppTestServer.java
+++
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/EmbeddedXmppTestServer.java
@@ -46,64 +46,51 @@ import org.jxmpp.jid.impl.JidCreate;
public final class EmbeddedXmppTestServer {
- private static EmbeddedXmppTestServer instance;
-
private XMPPServer xmppServer;
private TCPEndpoint endpoint;
private int port;
-
- // restricted to singleton
- private EmbeddedXmppTestServer() { }
-
- public static EmbeddedXmppTestServer instance() {
- if (instance == null) {
- instance = new EmbeddedXmppTestServer();
- instance.initializeXmppServer();
- }
- return instance;
+
+ public EmbeddedXmppTestServer() {
+ initializeXmppServer();
}
private void initializeXmppServer() {
try {
- if (xmppServer == null) {
- xmppServer = new XMPPServer("apache.camel");
+ xmppServer = new XMPPServer("apache.camel");
- StorageProviderRegistry providerRegistry = new
MemoryStorageProviderRegistry();
- AccountManagement accountManagement = (AccountManagement)
providerRegistry.retrieve(AccountManagement.class);
+ StorageProviderRegistry providerRegistry = new
MemoryStorageProviderRegistry();
+ AccountManagement accountManagement = (AccountManagement)
providerRegistry.retrieve(AccountManagement.class);
- Entity user =
EntityImpl.parseUnchecked("[email protected]");
- accountManagement.addUser(user, "secret");
+ Entity user =
EntityImpl.parseUnchecked("[email protected]");
+ accountManagement.addUser(user, "secret");
- Entity user2 =
EntityImpl.parseUnchecked("[email protected]");
- accountManagement.addUser(user2, "secret");
-
- Entity user3 =
EntityImpl.parseUnchecked("[email protected]");
- accountManagement.addUser(user3, "secret");
+ Entity user2 =
EntityImpl.parseUnchecked("[email protected]");
+ accountManagement.addUser(user2, "secret");
+
+ Entity user3 =
EntityImpl.parseUnchecked("[email protected]");
+ accountManagement.addUser(user3, "secret");
- xmppServer.setStorageProviderRegistry(providerRegistry);
+ xmppServer.setStorageProviderRegistry(providerRegistry);
- if (endpoint == null) {
- endpoint = new TCPEndpoint();
- this.port = AvailablePortFinder.getNextAvailable(5222);
- endpoint.setPort(port);
- }
+ endpoint = new TCPEndpoint();
+ this.port = AvailablePortFinder.getNextAvailable(5222);
+ endpoint.setPort(port);
- xmppServer.addEndpoint(endpoint);
+ xmppServer.addEndpoint(endpoint);
- InputStream stream =
ObjectHelper.loadResourceAsStream("xmppServer.jks");
- xmppServer.setTLSCertificateInfo(stream, "secret");
+ InputStream stream =
ObjectHelper.loadResourceAsStream("xmppServer.jks");
+ xmppServer.setTLSCertificateInfo(stream, "secret");
- // allow anonymous logins
- xmppServer.setSASLMechanisms(Arrays.asList(new
SASLMechanism[]{new Anonymous()}));
+ // allow anonymous logins
+ xmppServer.setSASLMechanisms(Arrays.asList(new SASLMechanism[]{new
Anonymous()}));
- xmppServer.start();
+ xmppServer.start();
- // add the multi-user chat module and create a few test rooms
- Conference conference = new Conference("test conference");
-
conference.createRoom(EntityImpl.parseUnchecked("[email protected]"),
"camel-anon", RoomType.FullyAnonymous);
-
conference.createRoom(EntityImpl.parseUnchecked("[email protected]"),
"camel-test", RoomType.Public);
- xmppServer.addModule(new MUCModule("conference", conference));
- }
+ // add the multi-user chat module and create a few test rooms
+ Conference conference = new Conference("test conference");
+
conference.createRoom(EntityImpl.parseUnchecked("[email protected]"),
"camel-anon", RoomType.FullyAnonymous);
+
conference.createRoom(EntityImpl.parseUnchecked("[email protected]"),
"camel-test", RoomType.Public);
+ xmppServer.addModule(new MUCModule("conference", conference));
} catch (Exception e) {
throw new RuntimeException("An error occurred when initializing
the XMPP Test Server.", e);
}
@@ -141,4 +128,8 @@ public final class EmbeddedXmppTestServer {
registry.bind("customConnectionConfig", connectionConfig);
}
+
+ public void stop() {
+ xmppServer.stop();
+ }
}
diff --git
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppDeferredConnectionTest.java
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppDeferredConnectionTest.java
index f84bf88..88c31f8 100644
---
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppDeferredConnectionTest.java
+++
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppDeferredConnectionTest.java
@@ -29,20 +29,23 @@ import org.junit.Test;
*/
public class XmppDeferredConnectionTest extends CamelTestSupport {
+ private EmbeddedXmppTestServer embeddedXmppTestServer;
+
/**
* Ensures that the XMPP server instance is created and 'stopped' before
the camel
* routes are initialized
*/
@Override
public void doPreSetup() throws Exception {
- EmbeddedXmppTestServer.instance().stopXmppEndpoint();
+ embeddedXmppTestServer = new EmbeddedXmppTestServer();
+ embeddedXmppTestServer.stopXmppEndpoint();
}
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
- EmbeddedXmppTestServer.instance().bindSSLContextTo(registry);
+ embeddedXmppTestServer.bindSSLContextTo(registry);
return registry;
}
@@ -70,7 +73,7 @@ public class XmppDeferredConnectionTest extends
CamelTestSupport {
template.sendBody("direct:simple", "Hello simple!");
simpleEndpoint.assertIsSatisfied();
- EmbeddedXmppTestServer.instance().startXmppEndpoint();
+ embeddedXmppTestServer.startXmppEndpoint();
// wait for the connection to be established
Thread.sleep(2000);
@@ -100,15 +103,20 @@ public class XmppDeferredConnectionTest extends
CamelTestSupport {
}
protected String getProducerUri() {
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/[email protected]?connectionConfig=#customConnectionConfig&[email protected]&user=camel_producer&password=secret&serviceName=apache.camel"
+ "&testConnectionOnStartup=false";
}
protected String getConsumerUri() {
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/[email protected]?connectionConfig=#customConnectionConfig&[email protected]&user=camel_consumer&password=secret&serviceName=apache.camel"
+ "&testConnectionOnStartup=false&connectionPollDelay=1";
}
-}
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ embeddedXmppTestServer.stop();
+ }
+}
diff --git
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java
index 7f21d0c..09cbe1c 100644
---
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java
+++
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppMultiUserChatTest.java
@@ -28,6 +28,7 @@ import org.junit.Test;
*/
public class XmppMultiUserChatTest extends CamelTestSupport {
+ private EmbeddedXmppTestServer embeddedXmppTestServer;
protected MockEndpoint consumerEndpoint;
protected String body1 = "the first message";
protected String body2 = "the second message";
@@ -36,7 +37,7 @@ public class XmppMultiUserChatTest extends CamelTestSupport {
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
- EmbeddedXmppTestServer.instance().bindSSLContextTo(registry);
+ embeddedXmppTestServer.bindSSLContextTo(registry);
return registry;
}
@@ -73,15 +74,25 @@ public class XmppMultiUserChatTest extends CamelTestSupport
{
// here on purpose we provide the room query parameter without the
domain name as 'camel-test', and Camel
// will resolve it properly to '[email protected]'
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/?connectionConfig=#customConnectionConfig&room=camel-test&[email protected]&password=secret&nickname=camel_producer";
}
protected String getConsumerUri() {
// however here we provide the room query parameter as fully
qualified, including the domain name as
// '[email protected]'
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/?connectionConfig=#customConnectionConfig&[email protected]&[email protected]&password=secret&nickname=camel_consumer";
}
+ @Override
+ public void doPreSetup() throws Exception {
+ embeddedXmppTestServer = new EmbeddedXmppTestServer();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ embeddedXmppTestServer.stop();
+ }
}
diff --git
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java
index 5f67a82..5b91096 100644
---
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java
+++
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppProducerConcurrentTest.java
@@ -30,11 +30,13 @@ import org.junit.Test;
*/
public class XmppProducerConcurrentTest extends CamelTestSupport {
+ private EmbeddedXmppTestServer embeddedXmppTestServer;
+
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
- EmbeddedXmppTestServer.instance().bindSSLContextTo(registry);
+ embeddedXmppTestServer.bindSSLContextTo(registry);
return registry;
}
@@ -49,7 +51,6 @@ public class XmppProducerConcurrentTest extends
CamelTestSupport {
doSendMessages(10, 5);
}
-
private void doSendMessages(int files, int poolSize) throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(files);
getMockEndpoint("mock:result").assertNoDuplicates(body());
@@ -75,10 +76,21 @@ public class XmppProducerConcurrentTest extends
CamelTestSupport {
@Override
public void configure() throws Exception {
from("direct:start")
- .to("xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ .to("xmpp://localhost:" +
embeddedXmppTestServer.getXmppPort()
+
"?connectionConfig=#customConnectionConfig&user=camel_consumer&password=secret&serviceName=apache.camel")
.to("mock:result");
}
};
}
+
+ @Override
+ public void doPreSetup() throws Exception {
+ embeddedXmppTestServer = new EmbeddedXmppTestServer();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ embeddedXmppTestServer.stop();
+ }
}
diff --git
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRobustConnectionTest.java
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRobustConnectionTest.java
index 27a40a5..2d66bb5 100644
---
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRobustConnectionTest.java
+++
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRobustConnectionTest.java
@@ -30,11 +30,13 @@ import org.junit.Test;
*/
public class XmppRobustConnectionTest extends CamelTestSupport {
+ private EmbeddedXmppTestServer embeddedXmppTestServer;
+
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
- EmbeddedXmppTestServer.instance().bindSSLContextTo(registry);
+ embeddedXmppTestServer.bindSSLContextTo(registry);
return registry;
}
@@ -61,7 +63,7 @@ public class XmppRobustConnectionTest extends
CamelTestSupport {
consumerEndpoint.assertIsNotSatisfied();
errorEndpoint.assertIsNotSatisfied();
- EmbeddedXmppTestServer.instance().stopXmppEndpoint();
+ embeddedXmppTestServer.stopXmppEndpoint();
Thread.sleep(2000);
for (int i = 0; i < 5; i++) {
@@ -71,7 +73,7 @@ public class XmppRobustConnectionTest extends
CamelTestSupport {
errorEndpoint.assertIsSatisfied();
consumerEndpoint.assertIsNotSatisfied();
- EmbeddedXmppTestServer.instance().startXmppEndpoint();
+ embeddedXmppTestServer.startXmppEndpoint();
Thread.sleep(2000);
for (int i = 0; i < 5; i++) {
@@ -97,13 +99,25 @@ public class XmppRobustConnectionTest extends
CamelTestSupport {
}
protected String getProducerUri() {
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/[email protected]?connectionConfig=#customConnectionConfig&[email protected]&user=camel_producer&password=secret&serviceName=apache.camel";
}
protected String getConsumerUri() {
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/[email protected]?connectionConfig=#customConnectionConfig&[email protected]&user=camel_consumer&password=secret&serviceName=apache.camel"
+ "&connectionPollDelay=1";
}
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ embeddedXmppTestServer = new EmbeddedXmppTestServer();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ embeddedXmppTestServer.stop();
+ }
}
diff --git
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java
index 815d880..61dc10f 100644
---
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java
+++
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java
@@ -27,6 +27,7 @@ import org.junit.Test;
*/
public class XmppRouteChatTest extends CamelTestSupport {
+ private EmbeddedXmppTestServer embeddedXmppTestServer;
protected MockEndpoint consumerEndpoint;
protected MockEndpoint producerEndpoint;
protected String body1 = "the first message";
@@ -36,7 +37,7 @@ public class XmppRouteChatTest extends CamelTestSupport {
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
- EmbeddedXmppTestServer.instance().bindSSLContextTo(registry);
+ embeddedXmppTestServer.bindSSLContextTo(registry);
return registry;
}
@@ -83,12 +84,23 @@ public class XmppRouteChatTest extends CamelTestSupport {
}
protected String getProducerUri() {
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/[email protected]?connectionConfig=#customConnectionConfig&[email protected]&user=camel_producer&password=secret&serviceName=apache.camel";
}
protected String getConsumerUri() {
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/[email protected]?connectionConfig=#customConnectionConfig&[email protected]&user=camel_consumer&password=secret&serviceName=apache.camel";
}
+
+ @Override
+ public void doPreSetup() throws Exception {
+ embeddedXmppTestServer = new EmbeddedXmppTestServer();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ embeddedXmppTestServer.stop();
+ }
}
diff --git
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java
index 5f57123..3c5e3bc 100644
---
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java
+++
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteMultipleProducersSingleConsumerTest.java
@@ -26,6 +26,7 @@ import org.junit.Test;
* @version
*/
public class XmppRouteMultipleProducersSingleConsumerTest extends
CamelTestSupport {
+ private EmbeddedXmppTestServer embeddedXmppTestServer;
protected MockEndpoint goodEndpoint;
protected MockEndpoint badEndpoint;
@@ -33,7 +34,7 @@ public class XmppRouteMultipleProducersSingleConsumerTest
extends CamelTestSuppo
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
- EmbeddedXmppTestServer.instance().bindSSLContextTo(registry);
+ embeddedXmppTestServer.bindSSLContextTo(registry);
return registry;
}
@@ -81,18 +82,28 @@ public class XmppRouteMultipleProducersSingleConsumerTest
extends CamelTestSuppo
}
protected String getProducer1Uri() {
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/[email protected]?connectionConfig=#customConnectionConfig&[email protected]&user=camel_producer&password=secret&serviceName=apache.camel";
}
protected String getProducer2Uri() {
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/[email protected]?connectionConfig=#customConnectionConfig&user=camel_producer1&password=secret&serviceName=apache.camel";
}
protected String getConsumerUri() {
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort()
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort()
+
"/[email protected]?connectionConfig=#customConnectionConfig&[email protected]&user=camel_consumer&password=secret&serviceName=apache.camel";
}
+ @Override
+ public void doPreSetup() throws Exception {
+ embeddedXmppTestServer = new EmbeddedXmppTestServer();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ embeddedXmppTestServer.stop();
+ }
}
diff --git
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
index bb85b53..0d962af 100644
---
a/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
+++
b/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
@@ -44,6 +44,7 @@ public class XmppRouteTest extends TestCase {
protected CountDownLatch latch = new CountDownLatch(1);
protected Endpoint endpoint;
protected ProducerCache client;
+ private EmbeddedXmppTestServer embeddedXmppTestServer;
public static void main(String[] args) {
enabled = true;
@@ -117,15 +118,17 @@ public class XmppRouteTest extends TestCase {
});
container.start();
+ embeddedXmppTestServer = new EmbeddedXmppTestServer();
}
protected String getUriPrefix() {
- return "xmpp://localhost:" +
EmbeddedXmppTestServer.instance().getXmppPort() +
"/camel?login=false&room=camel-anon";
+ return "xmpp://localhost:" + embeddedXmppTestServer.getXmppPort() +
"/camel?login=false&room=camel-anon";
}
-
+
@Override
protected void tearDown() throws Exception {
client.stop();
container.stop();
+ embeddedXmppTestServer.stop();
}
}
--
To stop receiving notification emails like this one, please contact
[email protected].