use per-test separate exchange name and delete test exchange during tearDown

Change-Id: Ib2660fe79a2fae060d0c6d4c6c613fe1056e9428
This commit is contained in:
Axel Uhl
2017-03-07 21:18:13 +01:00
parent 735b9a8042
commit a0bdce9eed
4 changed files with 15 additions and 6 deletions
@@ -19,6 +19,7 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -131,7 +132,7 @@ public abstract class AbstractServerReplicationTestSetUp<ReplicableInterface ext
ReplicableImpl master, ReplicableImpl replica) throws Exception {
logger.info("basicSetUp for test class "+getClass().getName());
persistenceSetUp(dropDB);
String exchangeName = "test-sapsailinganalytics-exchange";
String exchangeName = "test-sapsailinganalytics-exchange-"+new Random().nextInt();
String exchangeHost = "localhost";
if (System.getenv(Activator.ENV_VAR_NAME_REPLICATION_HOST) != null) {
exchangeHost = System.getenv(Activator.ENV_VAR_NAME_REPLICATION_HOST);
@@ -188,7 +189,7 @@ public abstract class AbstractServerReplicationTestSetUp<ReplicableInterface ext
}
if (masterDescriptor != null) {
logger.info("before stopConnection...");
masterDescriptor.stopConnection();
masterDescriptor.stopConnection(/* deleteExchange */ true);
}
try {
if (initialLoadTestServerThread != null) {
@@ -59,7 +59,12 @@ public interface ReplicationMasterDescriptor {
String getExchangeName();
void stopConnection();
/**
* @param deleteExchange
* Only to be used by the master itself when no longer delivering messages to the exchange, or to tear
* down after a test
*/
void stopConnection(boolean deleteExchange);
String getMessagingHostname();
@@ -225,12 +225,15 @@ public class ReplicationMasterDescriptorImpl implements ReplicationMasterDescrip
}
@Override
public synchronized void stopConnection() {
public synchronized void stopConnection(boolean deleteExchange) {
try {
if (consumer != null) {
// make sure to remove queue in order to avoid any exchanges filling it with messages
consumer.getChannel().queueUnbind(queueName, exchangeName, "");
consumer.getChannel().queueDelete(queueName);
if (deleteExchange) {
consumer.getChannel().exchangeDelete(exchangeName);
}
consumer.getChannel().getConnection().close(/* timeout in millis */ 1000);
}
} catch (Exception ex) {
@@ -239,7 +242,7 @@ public class ReplicationMasterDescriptorImpl implements ReplicationMasterDescrip
logger.log(Level.SEVERE, "Exception while closing replication channel consumer", ex);
}
}
/**
* @return 0 means use default port
*/
@@ -400,7 +400,7 @@ public class ReplicationReceiver implements Runnable {
}
logger.info("Signaled Replicator thread to stop asap.");
stopped = true;
master.stopConnection();
master.stopConnection(/* deleteExchange */ false);
notifyAll(); // notify those waiting for stopped
}