use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubProcessMultiRestartTest method testProcess.
/**
* The test creates a durable subscriber and producer with a broker that is
* continually restarted.
*
* Producer creates a message every .5 seconds -creates a new connection for
* each message
*
* durable subscriber - comes online for 10 seconds, - then goes offline for
* a "moment" - repeats the cycle
*
* approx every 10 seconds the broker restarts. Subscriber and Producer
* connections will be closed BEFORE the restart.
*
* The Durable subscriber is "unsubscribed" before the the end of the test.
*
* checks for number of kahaDB files left on filesystem.
*
* @throws Exception
*/
@Test
public void testProcess() throws Exception {
DurableSubscriber durableSubscriber = new DurableSubscriber(SUBSCRIPTION_ID);
MsgProducer msgProducer = new MsgProducer();
try {
// register the subscription & start messages
durableSubscriber.start();
msgProducer.start();
long endTime = System.currentTimeMillis() + RUNTIME;
while (endTime > System.currentTimeMillis()) {
Thread.sleep(10000);
restartBroker();
}
} catch (Throwable e) {
exit("ProcessTest.testProcess failed.", e);
}
// wait for threads to finish
try {
msgProducer.join();
durableSubscriber.join();
} catch (InterruptedException e) {
e.printStackTrace(System.out);
}
// restart broker one last time
restartBroker();
assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
final KahaDBPersistenceAdapter pa = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
assertTrue("only less than two journal files should be left: " + pa.getStore().getJournal().getFileMap().size(), Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return pa.getStore().getJournal().getFileMap().size() <= 2;
}
}, TimeUnit.MINUTES.toMillis(3)));
LOG.info("DONE.");
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubProcessMultiRestartTest method startBroker.
private void startBroker(boolean deleteAllMessages) throws Exception {
if (broker != null)
return;
broker = BrokerFactory.createBroker("broker:(vm://" + getName() + ")");
broker.setBrokerName(getName());
broker.setAdvisorySupport(false);
broker.setDeleteAllMessagesOnStartup(deleteAllMessages);
broker.setKeepDurableSubsActive(true);
File kahadbData = new File("activemq-data/" + getName() + "-kahadb");
if (deleteAllMessages)
delete(kahadbData);
broker.setPersistent(true);
KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
kahadb.setDirectory(kahadbData);
kahadb.setJournalMaxFileLength(20 * 1024);
broker.setPersistenceAdapter(kahadb);
broker.addConnector("tcp://localhost:61656");
broker.getSystemUsage().getMemoryUsage().setLimit(256 * 1024 * 1024);
broker.getSystemUsage().getTempUsage().setLimit(256 * 1024 * 1024);
broker.getSystemUsage().getStoreUsage().setLimit(256 * 1024 * 1024);
broker.start();
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubProcessWithRestartTest method startBroker.
private void startBroker(boolean deleteAllMessages) throws Exception {
if (broker != null)
return;
broker = BrokerFactory.createBroker("broker:(vm://" + getName() + ")");
broker.setBrokerName(getName());
broker.setAdvisorySupport(false);
broker.setDeleteAllMessagesOnStartup(deleteAllMessages);
switch(PERSISTENT_ADAPTER) {
case MEMORY:
broker.setPersistent(false);
break;
case LEVELDB:
File datadir = new File("activemq-data/" + getName() + "-leveldb");
if (deleteAllMessages)
delete(datadir);
broker.setPersistent(true);
LevelDBStore amq = new LevelDBStore();
amq.setDirectory(datadir);
broker.setPersistenceAdapter(amq);
break;
case KAHADB:
File kahadbData = new File("activemq-data/" + getName() + "-kahadb");
if (deleteAllMessages)
delete(kahadbData);
broker.setPersistent(true);
KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
kahadb.setDirectory(kahadbData);
kahadb.setJournalMaxFileLength(5 * 1024 * 1024);
broker.setPersistenceAdapter(kahadb);
break;
}
broker.addConnector("tcp://localhost:61656");
broker.getSystemUsage().getMemoryUsage().setLimit(256 * 1024 * 1024);
broker.getSystemUsage().getTempUsage().setLimit(256 * 1024 * 1024);
broker.getSystemUsage().getStoreUsage().setLimit(256 * 1024 * 1024);
broker.start();
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class QueuePurgeTest method setUp.
@Override
protected void setUp() throws Exception {
// 10 mins
setMaxTestTime(10 * 60 * 1000);
setAutoFail(true);
super.setUp();
broker = new BrokerService();
File testDataDir = new File("target/activemq-data/QueuePurgeTest");
broker.setDataDirectoryFile(testDataDir);
broker.setUseJmx(true);
broker.setDeleteAllMessagesOnStartup(true);
broker.getSystemUsage().getMemoryUsage().setLimit(1024L * 1024 * 64);
KahaDBPersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
persistenceAdapter.setDirectory(new File(testDataDir, "kahadb"));
broker.setPersistenceAdapter(persistenceAdapter);
broker.addConnector("tcp://localhost:0");
broker.start();
factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri().toString());
connection = factory.createConnection();
connection.start();
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project fabric8 by jboss-fuse.
the class ServiceFactoryTest method testStartRetryOnIOException.
/**
* Test for ENTMQ-2146.
* Broker does not get restarted after it shuts down due to IOException
* from KahaDB.
*
* @throws Exception
*/
@Test
public void testStartRetryOnIOException() throws Exception {
final String brokerName = "amq-kahadb";
underTest = new ActiveMQServiceFactory();
underTest.curator = curator;
Properties props = new Properties();
props.put("config", "amq-kahadb.xml");
props.put("broker-name", brokerName);
props.put("connectors", "openwire");
underTest.updated("b", props);
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return underTest.getBrokerService(brokerName) != null;
}
});
underTest.getBrokerService(brokerName).waitUntilStarted(2000);
final BrokerService brokerService = underTest.getBrokerService(brokerName);
KahaDBPersistenceAdapter kahaDBPersistenceAdapter = (KahaDBPersistenceAdapter) brokerService.getPersistenceAdapter();
// have the broker stop with an IOException on next checkpoint so it
// has a pending local transaction to recover
kahaDBPersistenceAdapter.getStore().getJournal().close();
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return brokerService.isStopped();
}
});
assertTrue("Broker running again", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
// check if broker is running
BrokerService broker = underTest.getBrokerService(brokerName);
return broker != null && broker.isStarted();
}
}));
}
Aggregations