Java Code Examples for org.apache.qpid.proton.message.impl.MessageImpl#setProperties()
The following examples show how to use
org.apache.qpid.proton.message.impl.MessageImpl#setProperties() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSetUserIDHasNoEffectOnMessagePropertiesWhenPresentButNoMessageID() { final String ID = UUID.randomUUID().toString(); MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setProperties(new Properties()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertNull(decoded.getUserID()); assertNotNull(decoded.getProperties()); assertNull(decoded.getProperties().getMessageId()); decoded.setUserID(ID); decoded.reencode(); assertNull(decoded.getUserID()); assertNotNull(decoded.getProperties()); assertNull(decoded.getProperties().getMessageId()); }
Example 2
Source File: AMQPPersisterTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private MessageImpl createProtonMessage(String address, byte[] content) { MessageImpl message = (MessageImpl) Proton.message(); Header header = new Header(); header.setDurable(true); header.setPriority(UnsignedByte.valueOf((byte) 9)); Properties properties = new Properties(); properties.setCreationTime(new Date(System.currentTimeMillis())); properties.setTo(address); properties.setMessageId(UUID.randomUUID()); MessageAnnotations annotations = new MessageAnnotations(new LinkedHashMap<>()); ApplicationProperties applicationProperties = new ApplicationProperties(new LinkedHashMap<>()); AmqpValue body = new AmqpValue(Arrays.copyOf(content, content.length)); message.setHeader(header); message.setMessageAnnotations(annotations); message.setProperties(properties); message.setApplicationProperties(applicationProperties); message.setBody(body); return message; }
Example 3
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSetTimestampOnMessage() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setProperties(new Properties()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(0L, decoded.getTimestamp()); Date createTime = new Date(System.currentTimeMillis()); decoded.setTimestamp(createTime.getTime()); decoded.reencode(); assertEquals(createTime.getTime(), decoded.getTimestamp()); assertEquals(createTime, decoded.getProperties().getCreationTime()); }
Example 4
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSetExpirationToClearUpdatesPropertiesWhenPresent() { final Date expirationTime = new Date(System.currentTimeMillis()); MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setProperties(new Properties()); protonMessage.setExpiryTime(expirationTime.getTime()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(expirationTime.getTime(), decoded.getExpiration()); decoded.setExpiration(-1); assertEquals(0, decoded.getExpiration()); decoded.reencode(); assertEquals(0, decoded.getExpiration()); assertNull(decoded.getProperties().getAbsoluteExpiryTime()); }
Example 5
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSetExpirationUpdatesProperties() { final Date originalExpirationTime = new Date(System.currentTimeMillis()); final Date expirationTime = new Date(System.currentTimeMillis()); MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setProperties(new Properties()); protonMessage.setExpiryTime(originalExpirationTime.getTime()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(originalExpirationTime.getTime(), decoded.getExpiration()); decoded.setExpiration(expirationTime.getTime()); assertEquals(expirationTime.getTime(), decoded.getExpiration()); decoded.reencode(); assertEquals(expirationTime, decoded.getProperties().getAbsoluteExpiryTime()); }
Example 6
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSetReplyToFromMessageWithPropertiesCanClear() { final String REPLY_TO = "address-1"; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setProperties(new Properties()); protonMessage.setReplyTo(REPLY_TO); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(REPLY_TO, decoded.getReplyTo().toString()); decoded.setReplyTo(null); decoded.reencode(); assertEquals(null, decoded.getReplyTo()); assertEquals(null, decoded.getProperties().getReplyTo()); }
Example 7
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSetUserIDHasNoEffectOnMessagePropertiesWhenPresentWithMessageID() { final String ID = UUID.randomUUID().toString(); MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setProperties(new Properties()); protonMessage.setMessageId(ID); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertNotNull(decoded.getUserID()); assertNotNull(decoded.getProperties()); assertNotNull(decoded.getProperties().getMessageId()); assertEquals(ID, decoded.getUserID()); decoded.setUserID(ID); decoded.reencode(); assertNotNull(decoded.getUserID()); assertNotNull(decoded.getProperties()); assertNotNull(decoded.getProperties().getMessageId()); assertEquals(ID, decoded.getUserID()); }
Example 8
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testSetReplyToFromMessageWithProperties() { final String REPLY_TO = "address-1"; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setProperties(new Properties()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertNull(decoded.getReplyTo()); decoded.setReplyTo(new SimpleString(REPLY_TO)); decoded.reencode(); assertEquals(REPLY_TO, decoded.getReplyTo().toString()); assertEquals(REPLY_TO, decoded.getProperties().getReplyTo()); }
Example 9
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetUserIDFromMessageWithNoUserID() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setProperties(new Properties()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertNull(decoded.getAMQPUserID()); }
Example 10
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetExpirationFromMessageWithNoTTLInHeaderOrExpirationInProperties() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); protonMessage.setProperties(new Properties()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(0, decoded.getExpiration()); }
Example 11
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetExpirationFromMessageUsingAbsoluteExpiration() { final Date expirationTime = new Date(System.currentTimeMillis()); MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); Properties properties = new Properties(); properties.setAbsoluteExpiryTime(expirationTime); protonMessage.setProperties(properties); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(expirationTime.getTime(), decoded.getExpiration()); }
Example 12
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetExpirationFromMessageUsingAbsoluteExpirationNegative() { final Date expirationTime = new Date(-1); MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); Properties properties = new Properties(); properties.setAbsoluteExpiryTime(expirationTime); protonMessage.setProperties(properties); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(0, decoded.getExpiration()); }
Example 13
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetExpirationFromMessageAbsoluteExpirationOVerrideTTL() { final Date expirationTime = new Date(System.currentTimeMillis()); final long ttl = 100000; MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); protonMessage.setTtl(ttl); Properties properties = new Properties(); properties.setAbsoluteExpiryTime(expirationTime); protonMessage.setProperties(properties); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(expirationTime.getTime(), decoded.getExpiration()); }
Example 14
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetReplyToFromMessageWithNoReplyTo() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setProperties(new Properties()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertNull(decoded.getReplyTo()); }
Example 15
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetGroupIDFromMessageWithNoGroupId() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setProperties(new Properties()); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertNull(decoded.getGroupID()); }
Example 16
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetTimestampFromMessage() { Date timestamp = new Date(System.currentTimeMillis()); MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader(new Header()); Properties properties = new Properties(); properties.setCreationTime(timestamp); protonMessage.setProperties(properties); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); assertEquals(timestamp.getTime(), decoded.getTimestamp()); }
Example 17
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testGetSendBufferWithoutDeliveryAnnotations() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); Header header = new Header(); header.setDeliveryCount(new UnsignedInteger(1)); protonMessage.setHeader(header); Properties properties = new Properties(); properties.setTo("someNiceLocal"); protonMessage.setProperties(properties); protonMessage.setBody(new AmqpValue("Sample payload")); DeliveryAnnotations deliveryAnnotations = new DeliveryAnnotations(new HashMap<>()); final String annotationKey = "annotationKey"; final String annotationValue = "annotationValue"; deliveryAnnotations.getValue().put(Symbol.getSymbol(annotationKey), annotationValue); protonMessage.setDeliveryAnnotations(deliveryAnnotations); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); ReadableBuffer sendBuffer = decoded.getSendBuffer(1); assertEquals(decoded.getEncodeSize(), sendBuffer.capacity()); AMQPStandardMessage msgFromSendBuffer = new AMQPStandardMessage(0, sendBuffer, null, null); assertEquals("someNiceLocal", msgFromSendBuffer.getAddress()); assertNull(msgFromSendBuffer.getDeliveryAnnotations()); // again with higher deliveryCount ReadableBuffer sendBuffer2 = decoded.getSendBuffer(5); assertEquals(decoded.getEncodeSize(), sendBuffer2.capacity()); AMQPStandardMessage msgFromSendBuffer2 = new AMQPStandardMessage(0, sendBuffer2, null, null); assertEquals("someNiceLocal", msgFromSendBuffer2.getAddress()); assertNull(msgFromSendBuffer2.getDeliveryAnnotations()); }
Example 18
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private MessageImpl createProtonMessage() { MessageImpl message = (MessageImpl) Proton.message(); Header header = new Header(); header.setDurable(true); header.setPriority(UnsignedByte.valueOf((byte) 9)); Properties properties = new Properties(); properties.setCreationTime(new Date(System.currentTimeMillis())); properties.setTo(TEST_TO_ADDRESS); properties.setMessageId(UUID.randomUUID()); MessageAnnotations annotations = new MessageAnnotations(new LinkedHashMap<>()); annotations.getValue().put(Symbol.valueOf(TEST_MESSAGE_ANNOTATION_KEY), TEST_MESSAGE_ANNOTATION_VALUE); ApplicationProperties applicationProperties = new ApplicationProperties(new LinkedHashMap<>()); applicationProperties.getValue().put(TEST_APPLICATION_PROPERTY_KEY, TEST_APPLICATION_PROPERTY_VALUE); AmqpValue body = new AmqpValue(TEST_STRING_BODY); message.setHeader(header); message.setMessageAnnotations(annotations); message.setProperties(properties); message.setApplicationProperties(applicationProperties); message.setBody(body); return message; }
Example 19
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testGetSendBufferWithDeliveryAnnotations() { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); Header header = new Header(); header.setDeliveryCount(new UnsignedInteger(1)); protonMessage.setHeader(header); Properties properties = new Properties(); properties.setTo("someNiceLocal"); protonMessage.setProperties(properties); protonMessage.setBody(new AmqpValue("Sample payload")); AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); DeliveryAnnotations newDeliveryAnnotations = new DeliveryAnnotations(new HashMap<>()); final String annotationKey = "annotationKey"; final String annotationValue = "annotationValue"; newDeliveryAnnotations.getValue().put(Symbol.getSymbol(annotationKey), annotationValue); decoded.setDeliveryAnnotationsForSendBuffer(newDeliveryAnnotations); ReadableBuffer sendBuffer = decoded.getSendBuffer(1); assertEquals(decoded.getEncodeSize(), sendBuffer.capacity()); AMQPStandardMessage msgFromSendBuffer = new AMQPStandardMessage(0, sendBuffer, null, null); assertEquals("someNiceLocal", msgFromSendBuffer.getAddress()); assertNotNull(msgFromSendBuffer.getDeliveryAnnotations()); assertEquals(1, msgFromSendBuffer.getDeliveryAnnotations().getValue().size()); assertEquals(annotationValue, msgFromSendBuffer.getDeliveryAnnotations().getValue().get(Symbol.getSymbol(annotationKey))); // again with higher deliveryCount DeliveryAnnotations newDeliveryAnnotations2 = new DeliveryAnnotations(new HashMap<>()); final String annotationKey2 = "annotationKey2"; final String annotationValue2 = "annotationValue2"; newDeliveryAnnotations2.getValue().put(Symbol.getSymbol(annotationKey2), annotationValue2); decoded.setDeliveryAnnotationsForSendBuffer(newDeliveryAnnotations2); ReadableBuffer sendBuffer2 = decoded.getSendBuffer(5); assertEquals(decoded.getEncodeSize(), sendBuffer2.capacity()); AMQPStandardMessage msgFromSendBuffer2 = new AMQPStandardMessage(0, sendBuffer2, null, null); assertEquals("someNiceLocal", msgFromSendBuffer2.getAddress()); assertNotNull(msgFromSendBuffer2.getDeliveryAnnotations()); assertEquals(1, msgFromSendBuffer2.getDeliveryAnnotations().getValue().size()); assertEquals(annotationValue2, msgFromSendBuffer2.getDeliveryAnnotations().getValue().get(Symbol.getSymbol(annotationKey2))); }
Example 20
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testDecodeMultiThreaded() throws Exception { MessageImpl protonMessage = (MessageImpl) Message.Factory.create(); protonMessage.setHeader( new Header()); Properties properties = new Properties(); properties.setTo("someNiceLocal"); protonMessage.setProperties(properties); protonMessage.getHeader().setDeliveryCount(new UnsignedInteger(7)); protonMessage.getHeader().setDurable(Boolean.TRUE); protonMessage.setApplicationProperties(new ApplicationProperties(new HashMap<>())); final AtomicInteger failures = new AtomicInteger(0); for (int testTry = 0; testTry < 100; testTry++) { AMQPStandardMessage decoded = encodeAndDecodeMessage(protonMessage); Thread[] threads = new Thread[100]; CountDownLatch latchAlign = new CountDownLatch(threads.length); CountDownLatch go = new CountDownLatch(1); Runnable run = new Runnable() { @Override public void run() { try { latchAlign.countDown(); go.await(); Assert.assertNotNull(decoded.getHeader()); // this is a method used by Core Converter decoded.getProtonMessage(); Assert.assertNotNull(decoded.getHeader()); } catch (Throwable e) { e.printStackTrace(); failures.incrementAndGet(); } } }; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(run); threads[i].start(); } Assert.assertTrue(latchAlign.await(10, TimeUnit.SECONDS)); go.countDown(); for (Thread thread : threads) { thread.join(5000); Assert.assertFalse(thread.isAlive()); } Assert.assertEquals(0, failures.get()); } }