use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class BMFailoverTest method testFailoverOnCommit.
@Test
@BMRules(rules = { @BMRule(name = "trace clientsessionimpl commit", targetClass = "org.apache.activemq.artemis.core.client.impl.ClientSessionImpl", targetMethod = "commit", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.BMFailoverTest.serverToStop.getServer().stop(true)") })
public void testFailoverOnCommit() throws Exception {
serverToStop = liveServer;
locator = getServerLocator().setFailoverOnInitialConnection(true);
createSessionFactory();
ClientSession session = createSessionAndQueue();
ClientProducer producer = addClientProducer(session.createProducer(FailoverTestBase.ADDRESS));
sendMessages(session, producer, 10);
try {
session.commit();
fail("should have thrown an exception");
} catch (ActiveMQTransactionOutcomeUnknownException e) {
// pass
}
sendMessages(session, producer, 10);
session.commit();
Queue bindable = (Queue) backupServer.getServer().getPostOffice().getBinding(FailoverTestBase.ADDRESS).getBindable();
assertEquals(10, getMessageCount(bindable));
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class BMFailoverTest method testFailoverOnReceiveCommit.
@Test
@BMRules(rules = { @BMRule(name = "trace clientsessionimpl commit", targetClass = "org.apache.activemq.artemis.core.client.impl.ClientSessionImpl", targetMethod = "commit", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.BMFailoverTest.serverToStop.getServer().stop(true)") })
public void testFailoverOnReceiveCommit() throws Exception {
serverToStop = liveServer;
locator = getServerLocator().setFailoverOnInitialConnection(true);
createSessionFactory();
ClientSession session = createSessionAndQueue();
ClientSession sendSession = createSession(sf, true, true);
ClientProducer producer = addClientProducer(sendSession.createProducer(FailoverTestBase.ADDRESS));
sendMessages(sendSession, producer, 10);
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
for (int i = 0; i < 10; i++) {
ClientMessage m = consumer.receive(500);
assertNotNull(m);
m.acknowledge();
}
try {
session.commit();
fail("should have thrown an exception");
} catch (ActiveMQTransactionOutcomeUnknownException e) {
// pass
} catch (ActiveMQTransactionRolledBackException e1) {
// pass
}
Queue bindable = (Queue) backupServer.getServer().getPostOffice().getBinding(FailoverTestBase.ADDRESS).getBindable();
assertEquals(10, getMessageCount(bindable));
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class BindingsImplTest method internalTest.
private void internalTest(final boolean route) throws Exception {
final FakeBinding fake = new FakeBinding(new SimpleString("a"));
final Bindings bind = new BindingsImpl(null, null, null);
bind.addBinding(fake);
bind.addBinding(new FakeBinding(new SimpleString("a")));
bind.addBinding(new FakeBinding(new SimpleString("a")));
Thread t = new Thread() {
@Override
public void run() {
try {
bind.removeBinding(fake);
} catch (Exception e) {
e.printStackTrace();
}
}
};
Queue queue = new FakeQueue(new SimpleString("a"));
t.start();
for (int i = 0; i < 100; i++) {
if (route) {
bind.route(new CoreMessage(i, 100), new RoutingContextImpl(new FakeTransaction()));
} else {
bind.redistribute(new CoreMessage(i, 100), queue, new RoutingContextImpl(new FakeTransaction()));
}
}
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class QueueManagerImpl method doIt.
private void doIt() {
Queue queue = server.locateQueue(queueName);
// the queue may already have been deleted and this is a result of that
if (queue == null) {
if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
ActiveMQServerLogger.LOGGER.debug("pno queue to delete \"" + queueName + ".\"");
}
return;
}
SimpleString address = queue.getAddress();
AddressSettings settings = server.getAddressSettingsRepository().getMatch(address.toString());
long consumerCount = queue.getConsumerCount();
long messageCount = queue.getMessageCount();
if (queue.isAutoCreated() && settings.isAutoDeleteQueues() && queue.getMessageCount() == 0 && queue.getConsumerCount() == 0) {
if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
ActiveMQServerLogger.LOGGER.debug("deleting " + (queue.isAutoCreated() ? "auto-created " : "") + "queue \"" + queueName + ".\" consumerCount = " + consumerCount + "; messageCount = " + messageCount + "; isAutoDeleteQueues = " + settings.isAutoDeleteQueues());
}
try {
server.destroyQueue(queueName, null, true, false);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.errorRemovingAutoCreatedQueue(e, queueName);
}
} else if (queue.isPurgeOnNoConsumers()) {
if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
ActiveMQServerLogger.LOGGER.debug("purging queue \"" + queueName + ".\" consumerCount = " + consumerCount + "; messageCount = " + messageCount);
}
try {
queue.deleteMatchingReferences(QueueImpl.DEFAULT_FLUSH_LIMIT, null, AckReason.KILLED);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToPurgeQueue(e, queueName);
}
}
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class PostOfficeJournalLoader method generateMapsOnPendingCount.
/**
* This generates a map for use on the recalculation and recovery of pending maps after reloading it
*
* @param queues
* @param pendingNonTXPageCounter
* @param txRecoverCounter
* @return
* @throws Exception
*/
private Map<SimpleString, Map<Long, Map<Long, List<PageCountPending>>>> generateMapsOnPendingCount(Map<Long, Queue> queues, List<PageCountPending> pendingNonTXPageCounter, Transaction txRecoverCounter) throws Exception {
Map<SimpleString, Map<Long, Map<Long, List<PageCountPending>>>> perAddressMap = new HashMap<>();
for (PageCountPending pgCount : pendingNonTXPageCounter) {
long queueID = pgCount.getQueueID();
long pageID = pgCount.getPageID();
// We first figure what Queue is based on the queue id
Queue queue = queues.get(queueID);
if (queue == null) {
logger.debug("removing pending page counter id = " + pgCount.getID() + " as queueID=" + pgCount.getID() + " no longer exists");
// this means the queue doesn't exist any longer, we will remove it from the storage
storageManager.deletePendingPageCounter(txRecoverCounter.getID(), pgCount.getID());
txRecoverCounter.setContainsPersistent();
continue;
}
// Level 1 on the structure, per address
SimpleString address = queue.getAddress();
Map<Long, Map<Long, List<PageCountPending>>> perPageMap = perAddressMap.get(address);
if (perPageMap == null) {
perPageMap = new HashMap<>();
perAddressMap.put(address, perPageMap);
}
Map<Long, List<PageCountPending>> perQueueMap = perPageMap.get(pageID);
if (perQueueMap == null) {
perQueueMap = new HashMap<>();
perPageMap.put(pageID, perQueueMap);
}
List<PageCountPending> pendingCounters = perQueueMap.get(queueID);
if (pendingCounters == null) {
pendingCounters = new LinkedList<>();
perQueueMap.put(queueID, pendingCounters);
}
pendingCounters.add(pgCount);
perQueueMap.put(queueID, pendingCounters);
}
return perAddressMap;
}
Aggregations