Test cleanup
This commit is contained in:
Timothy Bish 2015-03-04 18:40:31 -05:00
parent 6380bf3762
commit 00e4b25357
1 changed files with 52 additions and 25 deletions

View File

@ -16,7 +16,8 @@
*/
package org.apache.activemq.broker.region;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import javax.jms.Connection;
import javax.jms.Message;
@ -25,7 +26,6 @@ import javax.jms.MessageListener;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.EmbeddedBrokerTestSupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
@ -33,29 +33,53 @@ import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.Wait;
import org.apache.activemq.util.Wait.Condition;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class DestinationGCTest extends EmbeddedBrokerTestSupport {
public class DestinationGCTest {
ActiveMQQueue queue = new ActiveMQQueue("TEST");
ActiveMQQueue otherQueue = new ActiveMQQueue("TEST-OTHER");
private final ActiveMQQueue queue = new ActiveMQQueue("TEST");
private final ActiveMQQueue otherQueue = new ActiveMQQueue("TEST-OTHER");
private BrokerService brokerService;
@Before
public void setUp() throws Exception {
brokerService = createBroker();
brokerService.start();
brokerService.waitUntilStarted();
}
@After
public void tearDown() throws Exception {
if (brokerService != null) {
brokerService.stop();
brokerService.waitUntilStopped();
}
}
@Override
protected BrokerService createBroker() throws Exception {
BrokerService broker = super.createBroker();
PolicyEntry entry = new PolicyEntry();
entry.setGcInactiveDestinations(true);
entry.setInactiveTimeoutBeforeGC(3000);
PolicyMap map = new PolicyMap();
map.setDefaultEntry(entry);
BrokerService broker = new BrokerService();
broker.setPersistent(false);
broker.setUseJmx(true);
broker.setDestinations(new ActiveMQDestination[] {queue});
broker.setSchedulePeriodForDestinationPurge(1000);
broker.setMaxPurgedDestinationsPerSweep(1);
PolicyEntry entry = new PolicyEntry();
entry.setGcInactiveDestinations(true);
entry.setInactiveTimoutBeforeGC(3000);
PolicyMap map = new PolicyMap();
map.setDefaultEntry(entry);
broker.setDestinationPolicy(map);
return broker;
}
@Test(timeout = 60000)
public void testDestinationGCWithActiveConsumers() throws Exception {
assertEquals(1, broker.getAdminView().getQueues().length);
assertEquals(1, brokerService.getAdminView().getQueues().length);
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?create=false");
Connection connection = factory.createConnection();
@ -68,45 +92,48 @@ public class DestinationGCTest extends EmbeddedBrokerTestSupport {
public void onMessage(Message message) {
}
});
connection.start();
TimeUnit.SECONDS.sleep(5);
connection.start();
assertTrue("After GC runs there should be one Queue.", Wait.waitFor(new Condition() {
@Override
public boolean isSatisified() throws Exception {
return broker.getAdminView().getQueues().length == 1;
return brokerService.getAdminView().getQueues().length == 1;
}
}));
connection.close();
}
@Test(timeout = 60000)
public void testDestinationGc() throws Exception {
assertEquals(1, broker.getAdminView().getQueues().length);
assertEquals(1, brokerService.getAdminView().getQueues().length);
assertTrue("After GC runs the Queue should be empty.", Wait.waitFor(new Condition() {
@Override
public boolean isSatisified() throws Exception {
return broker.getAdminView().getQueues().length == 0;
return brokerService.getAdminView().getQueues().length == 0;
}
}));
}
@Test(timeout = 60000)
public void testDestinationGcLimit() throws Exception {
broker.getAdminView().addQueue("TEST1");
broker.getAdminView().addQueue("TEST2");
broker.getAdminView().addQueue("TEST3");
broker.getAdminView().addQueue("TEST4");
brokerService.getAdminView().addQueue("TEST1");
brokerService.getAdminView().addQueue("TEST2");
brokerService.getAdminView().addQueue("TEST3");
brokerService.getAdminView().addQueue("TEST4");
assertEquals(5, broker.getAdminView().getQueues().length);
assertEquals(5, brokerService.getAdminView().getQueues().length);
Thread.sleep(7000);
int queues = broker.getAdminView().getQueues().length;
int queues = brokerService.getAdminView().getQueues().length;
assertTrue(queues > 0 && queues < 5);
assertTrue("After GC runs the Queue should be empty.", Wait.waitFor(new Condition() {
@Override
public boolean isSatisified() throws Exception {
return broker.getAdminView().getQueues().length == 0;
return brokerService.getAdminView().getQueues().length == 0;
}
}));
}