use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class SlowConsumerTest method testFastThenSlowConsumerSpared.
@Test
public void testFastThenSlowConsumerSpared() throws Exception {
locator.setAckBatchSize(0);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(true, true));
final ClientSession producerSession = addClientSession(sf.createSession(true, true));
final ClientProducer producer = addClientProducer(producerSession.createProducer(QUEUE));
final AtomicLong messagesProduced = new AtomicLong(0);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
long start = System.currentTimeMillis();
ClientMessage m = createTextMessage(producerSession, "m", true);
// send messages as fast as possible for 3 seconds
while (System.currentTimeMillis() < (start + 3000)) {
try {
producer.send(m);
messagesProduced.incrementAndGet();
} catch (ActiveMQException e) {
e.printStackTrace();
return;
}
}
start = System.currentTimeMillis();
// send 1 msg/second for 10 seconds
while (System.currentTimeMillis() < (start + 10000)) {
try {
producer.send(m);
messagesProduced.incrementAndGet();
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
}
});
t.start();
assertPaging();
ClientConsumer consumer = addClientConsumer(session.createConsumer(QUEUE));
session.start();
ClientMessage m = null;
long messagesConsumed = 0;
do {
m = consumer.receive(1500);
if (m != null) {
m.acknowledge();
messagesConsumed++;
}
} while (m != null);
assertEquals(messagesProduced.longValue(), messagesConsumed);
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class RedeliveryConsumerTest method setUp.
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
/**
* @param persistDeliveryCountBeforeDelivery
* @throws Exception
*/
private void setUp(final boolean persistDeliveryCountBeforeDelivery) throws Exception {
Configuration config = createDefaultInVMConfig().setPersistDeliveryCountBeforeDelivery(persistDeliveryCountBeforeDelivery);
server = createServer(true, config);
server.start();
locator = createInVMNonHALocator();
factory = createSessionFactory(locator);
ClientSession session = addClientSession(factory.createSession(false, false, false));
try {
session.createQueue(ADDRESS, ADDRESS, true);
} catch (ActiveMQException expected) {
// in case of restart
}
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class SessionCloseTest method testCanNotUseAClosedSession.
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testCanNotUseAClosedSession() throws Exception {
final ClientSession session = sf.createSession(false, true, true);
session.close();
Assert.assertTrue(session.isClosed());
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
session.createProducer();
}
});
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
session.createConsumer(RandomUtil.randomSimpleString());
}
});
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
session.createQueue(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString(), RandomUtil.randomBoolean());
}
});
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
session.createTemporaryQueue(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString());
}
});
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
session.start();
}
});
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
session.stop();
}
});
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
session.commit();
}
});
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
session.rollback();
}
});
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
session.queueQuery(RandomUtil.randomSimpleString());
}
});
ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {
@Override
public void run() throws ActiveMQException {
session.addressQuery(RandomUtil.randomSimpleString());
}
});
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class SessionCreateAndDeleteQueueTest method testDeleteQueueNotExist.
@Test
public void testDeleteQueueNotExist() throws Exception {
ClientSession session = createSessionFactory(locator).createSession(false, true, true);
try {
session.deleteQueue(queueName);
Assert.fail("should throw exception");
} catch (ActiveMQNonExistentQueueException neqe) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ReceiveTest method testReceiveOnClosedException.
@Test
public void testReceiveOnClosedException() throws Exception {
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession session = cf.createSession(false, true, true);
session.createQueue(addressA, queueA, false);
ClientConsumer cc = session.createConsumer(queueA);
session.start();
session.close();
try {
cc.receive();
Assert.fail("should throw exception");
} catch (ActiveMQObjectClosedException oce) {
// ok
} catch (ActiveMQException e) {
Assert.fail("Invalid Exception type:" + e.getType());
}
session.close();
}
Aggregations