Add BROKER_INTEGRATION_TEST system property for broker tests
This commit is contained in:
@@ -12,8 +12,9 @@ import junit.framework.Assert;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.amqp.rabbit.test.EnvironmentAvailable;
|
||||
import org.springframework.erlang.connection.SingleConnectionFactory;
|
||||
import org.springframework.erlang.core.ErlangTemplate;
|
||||
import org.springframework.util.exec.Os;
|
||||
@@ -25,7 +26,6 @@ import com.ericsson.otp.erlang.OtpErlangObject;
|
||||
import com.ericsson.otp.erlang.OtpPeer;
|
||||
import com.ericsson.otp.erlang.OtpSelf;
|
||||
|
||||
@Ignore("Manual integration test only.")
|
||||
public class JInterfaceIntegrationTests {
|
||||
|
||||
private static Log logger = LogFactory.getLog(JInterfaceIntegrationTests.class);
|
||||
@@ -34,6 +34,9 @@ public class JInterfaceIntegrationTests {
|
||||
|
||||
private OtpConnection connection = null;
|
||||
|
||||
@Rule
|
||||
public static EnvironmentAvailable environment = new EnvironmentAvailable("BROKER_INTEGRATION_TEST");
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (connection != null) {
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.test.BrokerPanic;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.EnvironmentAvailable;
|
||||
import org.springframework.amqp.rabbit.test.Log4jLevelAdjuster;
|
||||
|
||||
/**
|
||||
@@ -42,6 +43,9 @@ public class RabbitBrokerAdminIntegrationTests {
|
||||
@Rule
|
||||
public Log4jLevelAdjuster logLevel = new Log4jLevelAdjuster(Level.INFO, RabbitBrokerAdmin.class);
|
||||
|
||||
@Rule
|
||||
public static EnvironmentAvailable environment = new EnvironmentAvailable("BROKER_INTEGRATION_TEST");
|
||||
|
||||
/*
|
||||
* Ensure broker dies if a test fails (otherwise the erl process might have to be killed manually)
|
||||
*/
|
||||
@@ -52,15 +56,19 @@ public class RabbitBrokerAdminIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void start() throws Exception {
|
||||
// Set up broker admin for non-root user
|
||||
brokerAdmin = BrokerTestUtils.getRabbitBrokerAdmin();
|
||||
brokerAdmin.startNode();
|
||||
panic.setBrokerAdmin(brokerAdmin);
|
||||
if (environment.isActive()) {
|
||||
// Set up broker admin for non-root user
|
||||
brokerAdmin = BrokerTestUtils.getRabbitBrokerAdmin();
|
||||
brokerAdmin.startNode();
|
||||
panic.setBrokerAdmin(brokerAdmin);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void stop() throws Exception {
|
||||
brokerAdmin.stopNode();
|
||||
if (environment.isActive()) {
|
||||
brokerAdmin.stopNode();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.EnvironmentAvailable;
|
||||
import org.springframework.amqp.rabbit.test.Log4jLevelAdjuster;
|
||||
import org.springframework.erlang.OtpException;
|
||||
|
||||
@@ -43,6 +44,9 @@ public class RabbitBrokerAdminLifecycleIntegrationTests {
|
||||
@Rule
|
||||
public Log4jLevelAdjuster logLevel = new Log4jLevelAdjuster(Level.INFO, RabbitBrokerAdmin.class);
|
||||
|
||||
@Rule
|
||||
public static EnvironmentAvailable environment = new EnvironmentAvailable("BROKER_INTEGRATION_TEST");
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
FileUtils.deleteDirectory(new File("target/rabbitmq"));
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.amqp.rabbit.test.BrokerPanic;
|
||||
import org.springframework.amqp.rabbit.test.BrokerRunning;
|
||||
import org.springframework.amqp.rabbit.test.BrokerTestUtils;
|
||||
import org.springframework.amqp.rabbit.test.EnvironmentAvailable;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
|
||||
@@ -51,6 +52,9 @@ public class MessageListenerBrokerInterruptionIntegrationTests {
|
||||
|
||||
private SimpleMessageListenerContainer container;
|
||||
|
||||
@Rule
|
||||
public static EnvironmentAvailable environment = new EnvironmentAvailable("BROKER_INTEGRATION_TEST");
|
||||
|
||||
/*
|
||||
* Ensure broker dies if a test fails (otherwise the erl process might have to be killed manually)
|
||||
*/
|
||||
@@ -72,28 +76,34 @@ public class MessageListenerBrokerInterruptionIntegrationTests {
|
||||
logger.debug("Setting up broker");
|
||||
brokerAdmin = BrokerTestUtils.getRabbitBrokerAdmin();
|
||||
panic.setBrokerAdmin(brokerAdmin);
|
||||
brokerAdmin.startNode();
|
||||
if (environment.isActive()) {
|
||||
brokerAdmin.startNode();
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void createConnectionFactory() {
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
||||
connectionFactory.setChannelCacheSize(concurrentConsumers);
|
||||
connectionFactory.setPort(BrokerTestUtils.getAdminPort());
|
||||
this.connectionFactory = connectionFactory;
|
||||
if (environment.isActive()) {
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
||||
connectionFactory.setChannelCacheSize(concurrentConsumers);
|
||||
connectionFactory.setPort(BrokerTestUtils.getAdminPort());
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void clear() throws Exception {
|
||||
// Wait for broker communication to finish before trying to stop container
|
||||
Thread.sleep(300L);
|
||||
logger.debug("Shutting down at end of test");
|
||||
if (container != null) {
|
||||
container.shutdown();
|
||||
if (environment.isActive()) {
|
||||
// Wait for broker communication to finish before trying to stop container
|
||||
Thread.sleep(300L);
|
||||
logger.debug("Shutting down at end of test");
|
||||
if (container != null) {
|
||||
container.shutdown();
|
||||
}
|
||||
brokerAdmin.stopNode();
|
||||
// Remove all trace of the durable queue...
|
||||
FileUtils.deleteDirectory(new File("target/rabbitmq"));
|
||||
}
|
||||
brokerAdmin.stopNode();
|
||||
// Remove all trace of the durable queue...
|
||||
FileUtils.deleteDirectory(new File("target/rabbitmq"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,9 +123,9 @@ public class MessageListenerBrokerInterruptionIntegrationTests {
|
||||
template.convertAndSend(queue.getName(), i + "foo");
|
||||
}
|
||||
|
||||
assertTrue("No more messages to receive before broker stopped", latch.getCount()>0);
|
||||
assertTrue("No more messages to receive before broker stopped", latch.getCount() > 0);
|
||||
brokerAdmin.stopBrokerApplication();
|
||||
assertTrue("No more messages to receive after broker stopped", latch.getCount()>0);
|
||||
assertTrue("No more messages to receive after broker stopped", latch.getCount() > 0);
|
||||
boolean waited = latch.await(500, TimeUnit.MILLISECONDS);
|
||||
assertFalse("Did not time out waiting for message", waited);
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.amqp.rabbit.test;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Assume;
|
||||
import org.junit.rules.MethodRule;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
public class EnvironmentAvailable implements MethodRule {
|
||||
|
||||
private static Log logger = LogFactory.getLog(EnvironmentAvailable.class);
|
||||
|
||||
private static final String DEFAULT_ENVIRONMENT_KEY = "ENVIRONMENT";
|
||||
|
||||
private final String key;
|
||||
|
||||
public EnvironmentAvailable(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public EnvironmentAvailable() {
|
||||
this(DEFAULT_ENVIRONMENT_KEY);
|
||||
}
|
||||
|
||||
public Statement apply(final Statement base, final FrameworkMethod method, Object target) {
|
||||
return new Statement() {
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
logger.info("Evironment: " + key + " active=" + isActive());
|
||||
Assume.assumeTrue(isActive());
|
||||
base.evaluate();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return System.getProperty(key) != null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user