Always Remove Test Exchanges in ERIT

- in case of dross left behind by a failed test run
This commit is contained in:
Gary Russell
2020-07-14 13:35:05 -04:00
parent e0ca772304
commit 7367bd7457
2 changed files with 40 additions and 0 deletions

View File

@@ -442,6 +442,33 @@ public final class BrokerRunningSupport {
}
}
/**
* Remove exchanges from the broker.
* @param exchanges the exchanges.
* @since 2.3
*/
public void removeExchanges(String... exchanges) {
LOGGER.debug("deleting test exchanges: " + Arrays.toString(exchanges));
Connection connection = null; // NOSONAR (closeResources())
Channel channel = null;
try {
connection = getConnection(getConnectionFactory());
connection.setId(generateId() + ".exchangeDelete");
channel = connection.createChannel();
for (String exchange : exchanges) {
channel.exchangeDelete(exchange);
}
}
catch (Exception e) {
LOGGER.warn("Failed to delete exchanges", e);
}
finally {
closeResources(connection, channel);
}
}
/**
* Delete and re-declare all the configured queues. Can be used between tests when
* a test might leave stale data and multiple tests use the same queue.

View File

@@ -225,6 +225,19 @@ public class EnableRabbitIntegrationTests {
public static void setUp() {
System.setProperty(RabbitListenerAnnotationBeanPostProcessor.RABBIT_EMPTY_STRING_ARGUMENTS_PROPERTY,
"test-empty");
RabbitAvailableCondition.getBrokerRunning().removeExchanges("auto.exch.tx",
"auto.exch",
"auto.exch.fanout",
"auto.exch",
"auto.exch",
"auto.start",
"auto.headers",
"auto.headers",
"auto.internal",
"multi.exch",
"multi.json.exch",
"multi.exch.tx",
"test.metaFanout");
}
@AfterAll