use of org.apache.activemq.artemis.jms.client.ActiveMQMessage in project activemq-artemis by apache.
the class MessageHeaderTest method testCopyOnForeignMessage.
@Test
public void testCopyOnForeignMessage() throws JMSException {
ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
ClientSession session = new FakeSession(clientMessage);
Message foreignMessage = new SimpleJMSMessage();
ActiveMQMessage copy = new ActiveMQMessage(foreignMessage, session);
MessageHeaderTestBase.ensureEquivalent(foreignMessage, copy);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQMessage in project activemq-artemis by apache.
the class JMSExpirationHeaderTest method testReceiveTimeoutPreservation.
@Test
public void testReceiveTimeoutPreservation() throws Exception {
final long timeToWaitForReceive = 5000;
final CountDownLatch receiverLatch = new CountDownLatch(1);
// start the receiver thread
Thread receiverThread = new Thread(new Runnable() {
@Override
public void run() {
try {
long t1 = System.currentTimeMillis();
expectedMessage = queueConsumer.receive(timeToWaitForReceive);
effectiveReceiveTime = System.currentTimeMillis() - t1;
} catch (Exception e) {
log.trace("receive() exits with an exception", e);
} finally {
receiverLatch.countDown();
}
}
}, "receiver thread");
receiverThread.start();
final CountDownLatch senderLatch = new CountDownLatch(1);
// start the sender thread
Thread senderThread = new Thread(new Runnable() {
@Override
public void run() {
try {
// wait for 3 secs
Thread.sleep(3000);
// send an expired message
Message m = queueProducerSession.createMessage();
queueProducer.send(m, DeliveryMode.NON_PERSISTENT, 4, -1);
ActiveMQMessage msg = (ActiveMQMessage) m;
if (!msg.getCoreMessage().isExpired()) {
log.error("The message " + m + " should have expired");
testFailed = true;
return;
}
} catch (Exception e) {
log.error("This exception will fail the test", e);
testFailed = true;
} finally {
senderLatch.countDown();
}
}
}, "sender thread");
senderThread.start();
ActiveMQTestBase.waitForLatch(senderLatch);
ActiveMQTestBase.waitForLatch(receiverLatch);
if (testFailed) {
ProxyAssertSupport.fail("Test failed by the sender thread. Watch for exception in logs");
}
log.trace("planned waiting time: " + timeToWaitForReceive + " effective waiting time " + effectiveReceiveTime);
ProxyAssertSupport.assertTrue(effectiveReceiveTime >= timeToWaitForReceive);
// well, how exactly I did come
ProxyAssertSupport.assertTrue(effectiveReceiveTime < timeToWaitForReceive * 1.5);
// up with this coeficient is
// not clear even to me, I just
// noticed that if I use 1.01
// this assertion sometimes
// fails;
ProxyAssertSupport.assertNull(expectedMessage);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQMessage in project activemq-artemis by apache.
the class AbstractPersistentStatTestSupport method consumeDurableTestMessages.
protected void consumeDurableTestMessages(Connection connection, String sub, int size, String topicName, AtomicLong publishedMessageSize) throws Exception {
Session session = connection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(topicName);
try {
TopicSubscriber consumer = session.createDurableSubscriber(topic, sub);
for (int i = 0; i < size; i++) {
ActiveMQMessage message = (ActiveMQMessage) consumer.receive();
if (publishedMessageSize != null) {
publishedMessageSize.addAndGet(-message.getCoreMessage().getEncodeSize());
}
}
} finally {
session.close();
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQMessage in project activemq-artemis by apache.
the class BridgeTestBase method sendMessages.
protected void sendMessages(final ConnectionFactory cf, final Destination dest, final int start, final int numMessages, final boolean persistent, final boolean largeMessage) throws Exception {
Connection conn = null;
try {
conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(dest);
prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
for (int i = start; i < start + numMessages; i++) {
if (largeMessage) {
BytesMessage msg = sess.createBytesMessage();
((ActiveMQMessage) msg).setInputStream(ActiveMQTestBase.createFakeLargeStream(1024L * 1024L));
msg.setStringProperty("msg", "message" + i);
prod.send(msg);
} else {
TextMessage tm = sess.createTextMessage("message" + i);
prod.send(tm);
}
}
} finally {
if (conn != null) {
conn.close();
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQMessage in project activemq-artemis by apache.
the class OpenWireGroupingTest method setProperty.
protected void setProperty(Message message) {
if (coreSend) {
((ActiveMQMessage) message).getCoreMessage().putStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_GROUP_ID, new SimpleString("foo"));
} else {
org.apache.activemq.command.ActiveMQMessage m = (org.apache.activemq.command.ActiveMQMessage) message;
m.setGroupID("foo");
}
}
Aggregations