Search in sources :

Example 1 with ActiveMQBytesMessage

use of org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage in project activemq-artemis by apache.

the class AbstractPersistentStatTestSupport method createMessage.

/**
 * Generate random messages between 100 bytes and maxMessageSize
 *
 * @param session
 * @return
 * @throws JMSException
 * @throws ActiveMQException
 */
protected BytesMessage createMessage(int count, Session session, int maxMessageSize, AtomicLong publishedMessageSize) throws JMSException, ActiveMQException {
    final ActiveMQBytesMessage message = (ActiveMQBytesMessage) session.createBytesMessage();
    final Random randomSize = new Random();
    int size = randomSize.nextInt((maxMessageSize - 100) + 1) + 100;
    final byte[] data = new byte[size];
    final Random rng = new Random();
    rng.nextBytes(data);
    message.writeBytes(data);
    if (publishedMessageSize != null) {
        publishedMessageSize.addAndGet(message.getCoreMessage().getPersistentSize());
    }
    return message;
}
Also used : Random(java.util.Random) ActiveMQBytesMessage(org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage)

Example 2 with ActiveMQBytesMessage

use of org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage in project activemq-artemis by apache.

the class MessageHeaderTest method testCopyOnForeignBytesMessage.

@Test
public void testCopyOnForeignBytesMessage() throws JMSException {
    ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
    ClientSession session = new FakeSession(clientMessage);
    BytesMessage foreignBytesMessage = new SimpleJMSBytesMessage();
    for (int i = 0; i < 20; i++) {
        foreignBytesMessage.writeByte((byte) i);
    }
    ActiveMQBytesMessage copy = new ActiveMQBytesMessage(foreignBytesMessage, session);
    foreignBytesMessage.reset();
    copy.reset();
    MessageHeaderTestBase.ensureEquivalent(foreignBytesMessage, copy);
}
Also used : ActiveMQBytesMessage(org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) BytesMessage(javax.jms.BytesMessage) ActiveMQBytesMessage(org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) Test(org.junit.Test)

Aggregations

ActiveMQBytesMessage (org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage)2 Random (java.util.Random)1 BytesMessage (javax.jms.BytesMessage)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ClientMessageImpl (org.apache.activemq.artemis.core.client.impl.ClientMessageImpl)1 Test (org.junit.Test)1