use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubscriptionOffline4Test method testCleanupDeletedSubAfterRestart.
@Test(timeout = 60 * 1000)
public // https://issues.apache.org/jira/browse/AMQ-3206
void testCleanupDeletedSubAfterRestart() throws Exception {
Connection con = createConnection("cli1");
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createDurableSubscriber(topic, "SubsId", null, true);
session.close();
con.close();
con = createConnection("cli2");
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createDurableSubscriber(topic, "SubsId", null, true);
session.close();
con.close();
con = createConnection();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(null);
final int toSend = 500;
final String payload = Arrays.toString(new byte[40 * 1024]);
int sent = 0;
for (int i = sent; i < toSend; i++) {
Message message = session.createTextMessage(payload);
message.setStringProperty("filter", "false");
message.setIntProperty("ID", i);
producer.send(topic, message);
sent++;
}
con.close();
LOG.info("sent: " + sent);
// kill off cli1
con = createConnection("cli1");
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.unsubscribe("SubsId");
destroyBroker();
createBroker(false);
con = createConnection("cli2");
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createDurableSubscriber(topic, "SubsId", null, true);
final DurableSubscriptionOfflineTestListener listener = new DurableSubscriptionOfflineTestListener();
consumer.setMessageListener(listener);
assertTrue("got all sent", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("Want: " + toSend + ", current: " + listener.count);
return listener.count == toSend;
}
}));
session.close();
con.close();
destroyBroker();
createBroker(false);
final KahaDBPersistenceAdapter pa = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
assertTrue("Should have less than three journal files left but was: " + pa.getStore().getJournal().getFileMap().size(), Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return pa.getStore().getJournal().getFileMap().size() <= 3;
}
}));
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubscriptionOfflineTestListener method createBroker.
protected void createBroker(boolean deleteAllMessages) throws Exception {
String currentTestName = getName(true);
broker = BrokerFactory.createBroker("broker:(vm://" + currentTestName + ")");
broker.setBrokerName(currentTestName);
broker.setDeleteAllMessagesOnStartup(deleteAllMessages);
broker.getManagementContext().setCreateConnector(false);
broker.setAdvisorySupport(false);
broker.setKeepDurableSubsActive(keepDurableSubsActive);
broker.addConnector("tcp://0.0.0.0:0");
if (usePrioritySupport) {
PolicyEntry policy = new PolicyEntry();
policy.setPrioritizedMessages(true);
PolicyMap policyMap = new PolicyMap();
policyMap.setDefaultEntry(policy);
broker.setDestinationPolicy(policyMap);
}
setDefaultPersistenceAdapter(broker);
if (broker.getPersistenceAdapter() instanceof JDBCPersistenceAdapter) {
// ensure it kicks in during tests
((JDBCPersistenceAdapter) broker.getPersistenceAdapter()).setCleanupPeriod(2 * 1000);
} else if (broker.getPersistenceAdapter() instanceof KahaDBPersistenceAdapter) {
// have lots of journal files
((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).setJournalMaxFileLength(journalMaxFileLength);
}
broker.start();
broker.waitUntilStarted();
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubscriptionOfflineTestListener method setPersistenceAdapter.
public PersistenceAdapter setPersistenceAdapter(BrokerService broker, PersistenceAdapterChoice choice) throws IOException {
PersistenceAdapter adapter = null;
switch(choice) {
case JDBC:
LOG.debug(">>>> setPersistenceAdapter to JDBC ");
adapter = new JDBCPersistenceAdapter();
break;
case KahaDB:
LOG.debug(">>>> setPersistenceAdapter to KahaDB ");
adapter = new KahaDBPersistenceAdapter();
break;
case LevelDB:
LOG.debug(">>>> setPersistenceAdapter to LevelDB ");
adapter = new LevelDBPersistenceAdapter();
break;
case MEM:
LOG.debug(">>>> setPersistenceAdapter to MEM ");
adapter = new MemoryPersistenceAdapter();
break;
}
broker.setPersistenceAdapter(adapter);
return adapter;
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubSelectorDelayWithRestartTest 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);
File kahadbData = new File("activemq-data/" + getName() + "-kahadb");
if (deleteAllMessages)
delete(kahadbData);
broker.setPersistent(true);
KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
kahadb.setDirectory(kahadbData);
kahadb.setJournalMaxFileLength(10 * 1024);
kahadb.setCleanupInterval(5000);
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);
LOG.info(toString() + "Starting Broker...");
broker.start();
broker.waitUntilStarted();
LOG.info(toString() + " Broker started!!");
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubscriptionActivationTest method createBroker.
private void createBroker(boolean delete) throws Exception {
broker = BrokerFactory.createBroker("broker:(vm://localhost)");
broker.setKeepDurableSubsActive(true);
broker.setPersistent(true);
broker.setDeleteAllMessagesOnStartup(delete);
KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
kahadb.setDirectory(new File("activemq-data/" + getName() + "-kahadb"));
kahadb.setJournalMaxFileLength(500 * 1024);
broker.setPersistenceAdapter(kahadb);
broker.setBrokerName(getName());
// only if we pre-create the destinations
broker.setDestinations(new ActiveMQDestination[] { topic });
broker.start();
broker.waitUntilStarted();
connection = createConnection();
}
Aggregations