Re-organise broker admin integration tests
This commit is contained in:
@@ -14,24 +14,19 @@
|
||||
package org.springframework.amqp.rabbit.admin;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.log4j.Level;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
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.Log4jLevelAdjuster;
|
||||
import org.springframework.util.exec.Os;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -41,7 +36,9 @@ import org.springframework.util.exec.Os;
|
||||
*/
|
||||
public class RabbitBrokerAdminIntegrationTests {
|
||||
|
||||
private static Log logger = LogFactory.getLog(RabbitBrokerAdminIntegrationTests.class);
|
||||
private static final int PORT = 15672;
|
||||
|
||||
private static final String NODE_NAME = "spring@localhost";
|
||||
|
||||
@Rule
|
||||
public Log4jLevelAdjuster logLevel = new Log4jLevelAdjuster(Level.INFO, RabbitBrokerAdmin.class);
|
||||
@@ -54,12 +51,10 @@ public class RabbitBrokerAdminIntegrationTests {
|
||||
|
||||
private static RabbitBrokerAdmin brokerAdmin;
|
||||
|
||||
private static final String NODE_NAME = "spring@localhost";
|
||||
|
||||
@BeforeClass
|
||||
public static void start() throws Exception {
|
||||
// Set up broker admin for non-root user
|
||||
brokerAdmin = new RabbitBrokerAdmin("spring@localhost", 15672);
|
||||
brokerAdmin = new RabbitBrokerAdmin(NODE_NAME, PORT);
|
||||
brokerAdmin.setRabbitLogBaseDirectory("target/rabbitmq/log");
|
||||
brokerAdmin.setRabbitMnesiaBaseDirectory("target/rabbitmq/mnesia");
|
||||
brokerAdmin.setStartupTimeout(10000L);
|
||||
@@ -69,9 +64,7 @@ public class RabbitBrokerAdminIntegrationTests {
|
||||
|
||||
@AfterClass
|
||||
public static void stop() throws Exception {
|
||||
if (Os.isFamily("windows") || Os.isFamily("dos")) {
|
||||
brokerAdmin.stopNode();
|
||||
}
|
||||
brokerAdmin.stopNode();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,47 +85,14 @@ public class RabbitBrokerAdminIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatusAndBrokerLifecycle() throws Exception {
|
||||
|
||||
brokerAdmin.stopBrokerApplication();
|
||||
RabbitStatus status = brokerAdmin.getStatus();
|
||||
assertEquals(0, status.getRunningNodes().size());
|
||||
|
||||
brokerAdmin.startBrokerApplication();
|
||||
status = brokerAdmin.getStatus();
|
||||
assertBrokerAppRunning(status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeatLifecycle() throws Exception {
|
||||
for (int i = 1; i <= 20; i++) {
|
||||
testStatusAndBrokerLifecycle();
|
||||
Thread.sleep(200);
|
||||
if (i % 5 == 0) {
|
||||
logger.debug("i = " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetQueues() throws Exception {
|
||||
ConnectionFactory connectionFactory = new SingleConnectionFactory();
|
||||
Queue queue = new RabbitAdmin(connectionFactory).declareQueue();
|
||||
SingleConnectionFactory connectionFactory = new SingleConnectionFactory();
|
||||
connectionFactory.setPort(PORT);
|
||||
Queue queue = new RabbitAdmin(connectionFactory).declareQueue();
|
||||
assertEquals("/", connectionFactory.getVirtualHost());
|
||||
List<QueueInfo> queues = brokerAdmin.getQueues();
|
||||
assertEquals(queue.getName(), queues.get(0).getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the named-node is running.
|
||||
* @param status
|
||||
*/
|
||||
private void assertBrokerAppRunning(RabbitStatus status) {
|
||||
assertEquals(1, status.getRunningNodes().size());
|
||||
assertTrue(status.getRunningNodes().get(0).getName().contains(NODE_NAME));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,12 +13,15 @@
|
||||
|
||||
package org.springframework.amqp.rabbit.admin;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.log4j.Level;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -30,7 +33,11 @@ import org.springframework.erlang.OtpException;
|
||||
* @author Mark Pollack
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class RabbitBrokerAdminStopIntegrationTests {
|
||||
public class RabbitBrokerAdminLifecycleIntegrationTests {
|
||||
|
||||
private static Log logger = LogFactory.getLog(RabbitBrokerAdminLifecycleIntegrationTests.class);
|
||||
|
||||
private static final String NODE_NAME = "spring@localhost";
|
||||
|
||||
@Rule
|
||||
public Log4jLevelAdjuster logLevel = new Log4jLevelAdjuster(Level.INFO, RabbitBrokerAdmin.class);
|
||||
@@ -44,7 +51,7 @@ public class RabbitBrokerAdminStopIntegrationTests {
|
||||
public void testStartNode() throws Exception {
|
||||
|
||||
// Set up broker admin for non-root user
|
||||
final RabbitBrokerAdmin brokerAdmin = new RabbitBrokerAdmin("spring@localhost", 15672);
|
||||
final RabbitBrokerAdmin brokerAdmin = new RabbitBrokerAdmin(NODE_NAME, 15672);
|
||||
brokerAdmin.setRabbitLogBaseDirectory("target/rabbitmq/log");
|
||||
brokerAdmin.setRabbitMnesiaBaseDirectory("target/rabbitmq/mnesia");
|
||||
|
||||
@@ -82,4 +89,51 @@ public class RabbitBrokerAdminStopIntegrationTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopAndStartBroker() throws Exception {
|
||||
|
||||
// Set up broker admin for non-root user
|
||||
final RabbitBrokerAdmin brokerAdmin = new RabbitBrokerAdmin(NODE_NAME, 15672);
|
||||
brokerAdmin.setRabbitLogBaseDirectory("target/rabbitmq/log");
|
||||
brokerAdmin.setRabbitMnesiaBaseDirectory("target/rabbitmq/mnesia");
|
||||
|
||||
brokerAdmin.setStartupTimeout(10000L);
|
||||
RabbitStatus status = brokerAdmin.getStatus();
|
||||
|
||||
status = brokerAdmin.getStatus();
|
||||
if (!status.isRunning()) {
|
||||
brokerAdmin.startBrokerApplication();
|
||||
}
|
||||
|
||||
brokerAdmin.stopBrokerApplication();
|
||||
|
||||
status = brokerAdmin.getStatus();
|
||||
assertEquals(0, status.getRunningNodes().size());
|
||||
|
||||
brokerAdmin.startBrokerApplication();
|
||||
status = brokerAdmin.getStatus();
|
||||
assertBrokerAppRunning(status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeatLifecycle() throws Exception {
|
||||
for (int i = 1; i <= 20; i++) {
|
||||
testStopAndStartBroker();
|
||||
Thread.sleep(200);
|
||||
if (i % 5 == 0) {
|
||||
logger.debug("i = " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the named-node is running.
|
||||
* @param status
|
||||
*/
|
||||
private void assertBrokerAppRunning(RabbitStatus status) {
|
||||
assertEquals(1, status.getRunningNodes().size());
|
||||
assertTrue(status.getRunningNodes().get(0).getName().contains(NODE_NAME));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user