Java Code Examples for org.apache.qpid.proton.amqp.messaging.Header#setDeliveryCount()
The following examples show how to use
org.apache.qpid.proton.amqp.messaging.Header#setDeliveryCount() .
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: HeaderType.java From qpid-proton-j with Apache License 2.0 | 6 votes |
public Header newInstance(Object described) { List l = (List) described; Header o = new Header(); switch(5 - l.size()) { case 0: o.setDeliveryCount( (UnsignedInteger) l.get( 4 ) ); case 1: o.setFirstAcquirer( (Boolean) l.get( 3 ) ); case 2: o.setTtl( (UnsignedInteger) l.get( 2 ) ); case 3: o.setPriority( (UnsignedByte) l.get( 1 ) ); case 4: o.setDurable( (Boolean) l.get( 0 ) ); } return o; }
Example 2
Source File: AMQPMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testGetHeader() { MessageImpl protonMessage = createProtonMessage(); AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null); Header decoded = message.getHeader(); assertNotSame(decoded, protonMessage.getHeader()); assertHeaderEquals(protonMessage.getHeader(), decoded); // Update the values decoded.setDeliveryCount(UnsignedInteger.ZERO); decoded.setTtl(UnsignedInteger.valueOf(255)); decoded.setFirstAcquirer(true); // Check that the message is unaffected. assertHeaderNotEquals(protonMessage.getHeader(), decoded); }
Example 3
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testGetDeliveryCountForReceivedMessageWithHeaderWithDeliveryCount() { Message message = Proton.message(); Header header = new Header(); header.setDeliveryCount(new UnsignedInteger(1)); message.setHeader(header); AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message); // JMS delivery count starts at one. assertEquals("expected delivery count value not found", 2, amqpMessageFacade.getDeliveryCount()); // Redelivered state inferred from delivery count assertTrue(amqpMessageFacade.isRedelivered()); assertEquals(1, amqpMessageFacade.getRedeliveryCount());; }
Example 4
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testSetRedeliveredWhenAlreadyRedeliveredDoesNotChangeDeliveryCount() { Message message = Proton.message(); Header header = new Header(); header.setDeliveryCount(new UnsignedInteger(1)); message.setHeader(header); AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message); // Redelivered state inferred from delivery count assertTrue(amqpMessageFacade.isRedelivered()); assertEquals(1, amqpMessageFacade.getRedeliveryCount());; amqpMessageFacade.setRedelivered(true); assertTrue(amqpMessageFacade.isRedelivered()); assertEquals(1, amqpMessageFacade.getRedeliveryCount());; }
Example 5
Source File: AmqpJmsMessageFacadeTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testSetRedeliveredFalseClearsDeliveryCount() { Message message = Proton.message(); Header header = new Header(); header.setDeliveryCount(new UnsignedInteger(1)); message.setHeader(header); AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message); // Redelivered state inferred from delivery count assertTrue(amqpMessageFacade.isRedelivered()); assertEquals(1, amqpMessageFacade.getRedeliveryCount());; amqpMessageFacade.setRedelivered(false); assertFalse(amqpMessageFacade.isRedelivered()); assertEquals(0, amqpMessageFacade.getRedeliveryCount());; }
Example 6
Source File: AmqpHeaderTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testCreateFromHeader() { Header protonHeader = new Header(); protonHeader.setPriority(UnsignedByte.valueOf((byte) 9)); protonHeader.setTtl(UnsignedInteger.valueOf(10)); protonHeader.setDeliveryCount(UnsignedInteger.valueOf(11)); protonHeader.setDurable(true); protonHeader.setFirstAcquirer(true); AmqpHeader header = new AmqpHeader(protonHeader); assertFalse(header.isDefault()); assertTrue(header.nonDefaultDurable()); assertTrue(header.nonDefaultPriority()); assertTrue(header.nonDefaultTimeToLive()); assertTrue(header.nonDefaultFirstAcquirer()); assertTrue(header.nonDefaultDeliveryCount()); assertEquals(true, header.isDurable()); assertEquals(true, header.isFirstAcquirer()); assertEquals(9, header.getPriority()); assertEquals(10, header.getTimeToLive()); assertEquals(11, header.getDeliveryCount()); }
Example 7
Source File: AmqpHeaderTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testSetHeaderWithDeliveryCountHeader() { AmqpHeader header = new AmqpHeader(); Header protonHeader = new Header(); protonHeader.setDeliveryCount(UnsignedInteger.valueOf(9)); header.setHeader(protonHeader); assertFalse(header.isDefault()); assertFalse(header.nonDefaultDurable()); assertFalse(header.nonDefaultPriority()); assertFalse(header.nonDefaultTimeToLive()); assertFalse(header.nonDefaultFirstAcquirer()); assertTrue(header.nonDefaultDeliveryCount()); assertEquals(false, header.isDurable()); assertEquals(false, header.isFirstAcquirer()); assertEquals(4, header.getPriority()); assertEquals(0, header.getTimeToLive()); assertEquals(9, header.getDeliveryCount()); }
Example 8
Source File: AmqpHeaderTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testSetHeaderWithHeaderWithAllSet() { AmqpHeader header = new AmqpHeader(); Header protonHeader = new Header(); protonHeader.setPriority(UnsignedByte.valueOf((byte) 9)); protonHeader.setTtl(UnsignedInteger.valueOf(10)); protonHeader.setDeliveryCount(UnsignedInteger.valueOf(11)); protonHeader.setDurable(true); protonHeader.setFirstAcquirer(true); header.setHeader(protonHeader); assertFalse(header.isDefault()); assertTrue(header.nonDefaultDurable()); assertTrue(header.nonDefaultPriority()); assertTrue(header.nonDefaultTimeToLive()); assertTrue(header.nonDefaultFirstAcquirer()); assertTrue(header.nonDefaultDeliveryCount()); assertEquals(true, header.isDurable()); assertEquals(true, header.isFirstAcquirer()); assertEquals(9, header.getPriority()); assertEquals(10, header.getTimeToLive()); assertEquals(11, header.getDeliveryCount()); }
Example 9
Source File: HeaderTypeCodecTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void doTestDecodeHeaderSeries(int size) throws IOException { Header header = new Header(); header.setDurable(Boolean.TRUE); header.setPriority(UnsignedByte.valueOf((byte) 3)); header.setDeliveryCount(UnsignedInteger.valueOf(10)); header.setFirstAcquirer(Boolean.FALSE); header.setTtl(UnsignedInteger.valueOf(500)); for (int i = 0; i < size; ++i) { encoder.writeObject(header); } buffer.clear(); for (int i = 0; i < size; ++i) { final Object result = decoder.readObject(); assertNotNull(result); assertTrue(result instanceof Header); Header decoded = (Header) result; assertEquals(3, decoded.getPriority().intValue()); assertTrue(decoded.getDurable().booleanValue()); } }
Example 10
Source File: HeaderTypeCodecTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testDecodeHeaderArray() throws IOException { Header header = new Header(); header.setDurable(Boolean.TRUE); header.setPriority(UnsignedByte.valueOf((byte) 3)); header.setDeliveryCount(UnsignedInteger.valueOf(10)); header.setFirstAcquirer(Boolean.FALSE); header.setTtl(UnsignedInteger.valueOf(500)); Header[] source = new Header[32]; for (int i = 0; i < source.length; ++i) { source[i] = header; } encoder.writeObject(source); buffer.clear(); final Object result = decoder.readObject(); assertNotNull(result); assertTrue(result.getClass().isArray()); final Object[] resultArray = (Object[]) result; for (int i = 0; i < source.length; ++i) { assertTrue(resultArray[i] instanceof Header); Header decoded = (Header) resultArray[i]; assertEquals(3, decoded.getPriority().intValue()); assertTrue(decoded.getDurable().booleanValue()); assertEquals(header.getDeliveryCount(), decoded.getDeliveryCount()); } }
Example 11
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 12
Source File: FastPathHeaderType.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@Override public Header readValue() { DecoderImpl decoder = getDecoder(); ReadableBuffer buffer = decoder.getBuffer(); byte typeCode = decoder.getBuffer().get(); @SuppressWarnings("unused") int size = 0; int count = 0; switch (typeCode) { case EncodingCodes.LIST0: break; case EncodingCodes.LIST8: size = buffer.get() & 0xff; count = buffer.get() & 0xff; break; case EncodingCodes.LIST32: size = buffer.getInt(); count = buffer.getInt(); break; default: throw new DecodeException("Incorrect type found in Header encoding: " + typeCode); } Header header = new Header(); for (int index = 0; index < count; ++index) { switch (index) { case 0: header.setDurable(decoder.readBoolean(null)); break; case 1: header.setPriority(decoder.readUnsignedByte(null)); break; case 2: header.setTtl(decoder.readUnsignedInteger(null)); break; case 3: header.setFirstAcquirer(decoder.readBoolean(null)); break; case 4: header.setDeliveryCount(decoder.readUnsignedInteger(null)); break; default: throw new IllegalStateException("To many entries in Header encoding"); } } return header; }
Example 13
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))); }