use of org.apache.activemq.artemis.core.client.impl.ClientMessageImpl in project activemq-artemis by apache.
the class MessageBufferTest method simpleTest.
@Test
public void simpleTest() throws Exception {
final String data = "Simple Text " + UUID.randomUUID().toString();
final String queueName = "simpleQueue";
final String addressName = "simpleAddress";
session.createQueue(addressName, RoutingType.ANYCAST, queueName);
ClientProducer producer = session.createProducer(addressName);
ClientMessageImpl message = (ClientMessageImpl) session.createMessage(true);
message.getBodyBuffer().writeString(data);
for (int i = 0; i < 100; i++) {
message.putStringProperty("key", "int" + i);
// JMS layer will always call this before sending
message.getBodyBuffer().resetReaderIndex();
producer.send(message);
session.commit();
Assert.assertTrue("Message body growing indefinitely and unexpectedly", message.getBodySize() < 1000);
}
producer.send(message);
producer.close();
ClientConsumer consumer = session.createConsumer(queueName);
session.start();
assertNotNull(message);
message.acknowledge();
assertEquals(data, message.getBodyBuffer().readString());
}
use of org.apache.activemq.artemis.core.client.impl.ClientMessageImpl in project activemq-artemis by apache.
the class MessageImplTest method getSetAttributes.
@Test
public void getSetAttributes() {
for (int j = 0; j < 10; j++) {
byte[] bytes = new byte[1000];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = RandomUtil.randomByte();
}
final byte type = RandomUtil.randomByte();
final boolean durable = RandomUtil.randomBoolean();
final long expiration = RandomUtil.randomLong();
final long timestamp = RandomUtil.randomLong();
final byte priority = RandomUtil.randomByte();
ICoreMessage message1 = new ClientMessageImpl(type, durable, expiration, timestamp, priority, 100);
ICoreMessage message = message1;
Assert.assertEquals(type, message.getType());
Assert.assertEquals(durable, message.isDurable());
Assert.assertEquals(expiration, message.getExpiration());
Assert.assertEquals(timestamp, message.getTimestamp());
Assert.assertEquals(priority, message.getPriority());
final SimpleString destination = new SimpleString(RandomUtil.randomString());
final boolean durable2 = RandomUtil.randomBoolean();
final long expiration2 = RandomUtil.randomLong();
final long timestamp2 = RandomUtil.randomLong();
final byte priority2 = RandomUtil.randomByte();
message.setAddress(destination);
Assert.assertEquals(destination, message.getAddressSimpleString());
message.setDurable(durable2);
Assert.assertEquals(durable2, message.isDurable());
message.setExpiration(expiration2);
Assert.assertEquals(expiration2, message.getExpiration());
message.setTimestamp(timestamp2);
Assert.assertEquals(timestamp2, message.getTimestamp());
message.setPriority(priority2);
Assert.assertEquals(priority2, message.getPriority());
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientMessageImpl in project activemq-artemis by apache.
the class CoreMessageTest method generate.
public String generate(String body) throws Exception {
ClientMessageImpl message = new ClientMessageImpl(MESSAGE_TYPE, DURABLE, EXPIRATION, TIMESTAMP, PRIORITY, 10 * 1024, null);
TextMessageUtil.writeBodyText(message.getBodyBuffer(), SimpleString.toSimpleString(body));
message.setAddress(ADDRESS);
message.setUserID(uuid);
message.getProperties().putSimpleStringProperty(PROP1_NAME, PROP1_VALUE);
ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(10 * 1024);
message.sendBuffer(buffer.byteBuf(), 0);
byte[] bytes = new byte[buffer.byteBuf().writerIndex()];
buffer.byteBuf().readBytes(bytes);
return encodeString(bytes);
// replace the code
}
use of org.apache.activemq.artemis.core.client.impl.ClientMessageImpl in project activemq-artemis by apache.
the class MessageHeaderTest method testCopyOnForeignMapMessage.
@Test
public void testCopyOnForeignMapMessage() throws JMSException {
ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
ClientSession session = new FakeSession(clientMessage);
MapMessage foreignMapMessage = new SimpleJMSMapMessage();
foreignMapMessage.setInt("int", 1);
foreignMapMessage.setString("string", "test");
ActiveMQMapMessage copy = new ActiveMQMapMessage(foreignMapMessage, session);
MessageHeaderTestBase.ensureEquivalent(foreignMapMessage, copy);
}
use of org.apache.activemq.artemis.core.client.impl.ClientMessageImpl 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);
}
Aggregations