Search in sources :

Example 6 with ActiveMQMessage

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);
}
Also used : MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) StreamMessage(javax.jms.StreamMessage) ActiveMQObjectMessage(org.apache.activemq.artemis.jms.client.ActiveMQObjectMessage) BytesMessage(javax.jms.BytesMessage) ActiveMQBytesMessage(org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage) ActiveMQMapMessage(org.apache.activemq.artemis.jms.client.ActiveMQMapMessage) ActiveMQStreamMessage(org.apache.activemq.artemis.jms.client.ActiveMQStreamMessage) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage) Test(org.junit.Test)

Example 7 with ActiveMQMessage

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);
}
Also used : Message(javax.jms.Message) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage) Test(org.junit.Test)

Example 8 with ActiveMQMessage

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();
    }
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) Topic(javax.jms.Topic) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session) TopicSession(javax.jms.TopicSession) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage)

Example 9 with ActiveMQMessage

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();
        }
    }
}
Also used : Connection(javax.jms.Connection) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage)

Example 10 with ActiveMQMessage

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");
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage)

Aggregations

ActiveMQMessage (org.apache.activemq.artemis.jms.client.ActiveMQMessage)11 Message (javax.jms.Message)5 TextMessage (javax.jms.TextMessage)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)5 Test (org.junit.Test)4 BytesMessage (javax.jms.BytesMessage)3 Session (javax.jms.Session)3 Connection (javax.jms.Connection)2 MapMessage (javax.jms.MapMessage)2 MessageProducer (javax.jms.MessageProducer)2 ObjectMessage (javax.jms.ObjectMessage)2 StreamMessage (javax.jms.StreamMessage)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ClientMessageImpl (org.apache.activemq.artemis.core.client.impl.ClientMessageImpl)2 ActiveMQBytesMessage (org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage)2 ActiveMQMapMessage (org.apache.activemq.artemis.jms.client.ActiveMQMapMessage)2 ActiveMQObjectMessage (org.apache.activemq.artemis.jms.client.ActiveMQObjectMessage)2 ActiveMQStreamMessage (org.apache.activemq.artemis.jms.client.ActiveMQStreamMessage)2 ActiveMQTextMessage (org.apache.activemq.artemis.jms.client.ActiveMQTextMessage)2