org.apache.qpid.proton.amqp.UnsignedInteger Java Examples

The following examples show how to use org.apache.qpid.proton.amqp.UnsignedInteger. 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: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHeaderWithDeliveryCountAmqpHeader() {
    AmqpHeader header = new AmqpHeader();

    AmqpHeader amqpHeader = new AmqpHeader();
    amqpHeader.setDeliveryCount(UnsignedInteger.valueOf(9));

    header.setHeader(amqpHeader);

    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 #2
Source File: TransferTypeTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncodeDecodeTransfers() {
    Transfer transfer = new Transfer();
    transfer.setHandle(UnsignedInteger.ONE);
    transfer.setDeliveryTag(new Binary(new byte[] {0, 1}));
    transfer.setMessageFormat(UnsignedInteger.ZERO);
    transfer.setDeliveryId(UnsignedInteger.valueOf(127));
    transfer.setAborted(false);
    transfer.setBatchable(true);
    transfer.setRcvSettleMode(ReceiverSettleMode.SECOND);

    encoder.writeObject(transfer);
    buffer.clear();
    final Transfer outputValue = (Transfer) decoder.readObject();

    assertEquals(transfer.getHandle(), outputValue.getHandle());
    assertEquals(transfer.getMessageFormat(), outputValue.getMessageFormat());
    assertEquals(transfer.getDeliveryTag(), outputValue.getDeliveryTag());
    assertEquals(transfer.getDeliveryId(), outputValue.getDeliveryId());
    assertEquals(transfer.getAborted(), outputValue.getAborted());
    assertEquals(transfer.getBatchable(), outputValue.getBatchable());
    assertEquals(transfer.getRcvSettleMode(), outputValue.getRcvSettleMode());
}
 
Example #3
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHeaderWithAmqpHeaderWithAllSet() {
    AmqpHeader header = new AmqpHeader();

    AmqpHeader amqpHeader = new AmqpHeader();
    amqpHeader.setPriority(UnsignedByte.valueOf((byte) 9));
    amqpHeader.setTimeToLive(UnsignedInteger.valueOf(10));
    amqpHeader.setDeliveryCount(UnsignedInteger.valueOf(11));
    amqpHeader.setDurable(true);
    amqpHeader.setFirstAcquirer(true);

    header.setHeader(amqpHeader);

    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 #4
Source File: MessageImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public void setGroupSequence(long groupSequence)
{
    if(_properties == null)
    {
        if(groupSequence == 0l)
        {
            return;
        }
        else
        {
            _properties = new Properties();
        }
    }
    _properties.setGroupSequence(UnsignedInteger.valueOf((int) groupSequence));
}
 
Example #5
Source File: Benchmark.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private void benchmarkApplicationProperties() throws IOException {
    ApplicationProperties properties = new ApplicationProperties(new HashMap<String, Object>());
    properties.getValue().put("test1", UnsignedByte.valueOf((byte) 128));
    properties.getValue().put("test2", UnsignedShort.valueOf((short) 128));
    properties.getValue().put("test3", UnsignedInteger.valueOf((byte) 128));

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        outputBuf.byteBuffer().clear();
        encoder.writeObject(properties);
    }
    resultSet.encodesComplete();

    CompositeReadableBuffer inputBuf = convertToComposite(outputBuf);
    decoder.setBuffer(inputBuf);

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        decoder.readObject();
        inputBuf.flip();
    }
    resultSet.decodesComplete();

    time("ApplicationProperties", resultSet);
}
 
Example #6
Source File: ReceiverImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public int recv(final WritableBuffer buffer)
{
    if (_current == null) {
        throw new IllegalStateException("no current delivery");
    }

    int consumed = _current.recv(buffer);
    if (consumed > 0) {
        getSession().incrementIncomingBytes(-consumed);
        if (getSession().getTransportSession().getIncomingWindowSize().equals(UnsignedInteger.ZERO)) {
            modified();
        }
    }
    return consumed;
}
 
Example #7
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHeaderWithTimeToLiveAmqpHeader() {
    AmqpHeader header = new AmqpHeader();

    AmqpHeader amqpHeader = new AmqpHeader();
    amqpHeader.setTimeToLive(UnsignedInteger.valueOf(9));

    header.setHeader(amqpHeader);

    assertFalse(header.isDefault());
    assertFalse(header.nonDefaultDurable());
    assertFalse(header.nonDefaultPriority());
    assertTrue(header.nonDefaultTimeToLive());
    assertFalse(header.nonDefaultFirstAcquirer());
    assertFalse(header.nonDefaultDeliveryCount());

    assertEquals(false, header.isDurable());
    assertEquals(false, header.isFirstAcquirer());
    assertEquals(4, header.getPriority());
    assertEquals(9, header.getTimeToLive());
    assertEquals(0, header.getDeliveryCount());
}
 
Example #8
Source File: ReceivedType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public Received newInstance(Object described)
{
    List<?> l = (List<?>) described;

    Received o = new Received();

    switch(2 - l.size())
    {
        case 0:
            o.setSectionOffset((UnsignedLong) l.get( 1 ));
        case 1:
            o.setSectionNumber((UnsignedInteger) l.get( 0 ));
    }

    return o;
}
 
Example #9
Source File: TargetType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public int size()
{
    return _impl.getCapabilities() != null
              ? 7
              : _impl.getDynamicNodeProperties() != null
              ? 6
              : _impl.getDynamic()
              ? 5
              : (_impl.getTimeout() != null && !_impl.getTimeout().equals(UnsignedInteger.ZERO))
              ? 4
              : !_impl.getExpiryPolicy().equals(TerminusExpiryPolicy.SESSION_END)
              ? 3
              : !_impl.getDurable().equals(TerminusDurability.NONE)
              ? 2
              : _impl.getAddress() != null
              ? 1
              : 0;

}
 
Example #10
Source File: AmqpManagementTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Some clients use Unsigned types from org.apache.qpid.proton.amqp
 * @throws Exception
 */
@Test(timeout = 60000)
public void testUnsignedValues() throws Exception {
   int sequence = 42;
   LinkedHashMap<String, Object> map = new LinkedHashMap<>();
   map.put("sequence", new UnsignedInteger(sequence));
   ServerJMSMapMessage msg = createMapMessage(1, map, null);
   assertEquals(msg.getInt("sequence"), sequence);

   map.clear();
   map.put("sequence", new UnsignedLong(sequence));
   msg = createMapMessage(1, map, null);
   assertEquals(msg.getLong("sequence"), sequence);

   map.clear();
   map.put("sequence", new UnsignedShort((short)sequence));
   msg = createMapMessage(1, map, null);
   assertEquals(msg.getShort("sequence"), sequence);

   map.clear();
   map.put("sequence", new UnsignedByte((byte) sequence));
   msg = createMapMessage(1, map, null);
   assertEquals(msg.getByte("sequence"), sequence);
}
 
Example #11
Source File: DetachTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testCopy() {
    Detach detach = new Detach();
    Detach copyOf = detach.copy();

    assertNull(copyOf.getError());

    detach.setError(new ErrorCondition());
    detach.setClosed(true);
    detach.setHandle(UnsignedInteger.ONE);

    copyOf = detach.copy();

    assertNotNull(copyOf.getError());
    assertEquals(detach.getClosed(), copyOf.getClosed());
    assertEquals(detach.getHandle(), copyOf.getHandle());
}
 
Example #12
Source File: AmqpHeaderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@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 #13
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTtlSynthesizedExpirationOnReceivedMessageWithTtlButNoAbsoluteExpiration() throws JMSException {
    Long ttl = 123L;

    Message message = Proton.message();
    Header header = new Header();
    header.setTtl(UnsignedInteger.valueOf(ttl));
    message.setHeader(header);

    long start = System.currentTimeMillis();
    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);
    long end = System.currentTimeMillis();

    long expiration = amqpMessageFacade.getExpiration();

    assertTrue("Should have sythesized expiration based on current time + ttl", start + ttl <= expiration);
    assertTrue("Should have sythesized expiration based on current time + ttl", expiration <= end + ttl);

    long expiration2 = amqpMessageFacade.getExpiration();
    assertEquals("Second retrieval should return same result", expiration, expiration2);

    amqpMessageFacade = amqpMessageFacade.copy();
    long expiration3 = amqpMessageFacade.getExpiration();
    assertEquals("Thrid retrieval from copy should return same result", expiration, expiration3);
}
 
Example #14
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testOnSendOverridesTtlOnMessageReceivedWithTtl() throws Exception {
    Message message = Proton.message();
    int origTtl = 5;
    int newTtl = 10;
    message.setTtl(origTtl);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("TTL has been unset already", origTtl, message.getTtl());

    amqpMessageFacade.onSend(newTtl);

    // check value on underlying TTL field is NOT set
    assertEquals("TTL has not been overriden", newTtl, amqpMessageFacade.getAmqpHeader().getTimeToLive());
    assertEquals("TTL field on underlying message should be set", UnsignedInteger.valueOf(newTtl), amqpMessageFacade.getHeader().getTtl());
}
 
Example #15
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeliveryCountSetFromMessageWithNonDefaultValue() throws Exception {
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setDeliveryCount(2);
    message.setBody(new AmqpValue("test"));

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass());
    assertTrue(jmsMessage.getJMSRedelivered());

    assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, jmsMessage.getFacade().getClass());
    AmqpJmsTextMessageFacade facade = (AmqpJmsTextMessageFacade) jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals(2, facade.getRedeliveryCount());
    assertEquals(2, facade.getAmqpHeader().getDeliveryCount());
    assertEquals(UnsignedInteger.valueOf(2), facade.getHeader().getDeliveryCount());
}
 
Example #16
Source File: TestAmqpPeer.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public void expectLinkFlowRespondWithTransfer(final HeaderDescribedType headerDescribedType,
                                              final MessageAnnotationsDescribedType messageAnnotationsDescribedType,
                                              final PropertiesDescribedType propertiesDescribedType,
                                              final ApplicationPropertiesDescribedType appPropertiesDescribedType,
                                              final DescribedType content,
                                              final int count)
{
    expectLinkFlowRespondWithTransfer(headerDescribedType, messageAnnotationsDescribedType, propertiesDescribedType,
                                      appPropertiesDescribedType, content, count, false, false,
                                      Matchers.greaterThanOrEqualTo(UnsignedInteger.valueOf(count)), 1, false, false);
}
 
Example #17
Source File: AmqpHeader.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public void setTimeToLive(long timeToLive) {
    if (timeToLive > 0 && timeToLive < UINT_MAX) {
        setTimeToLive(UnsignedInteger.valueOf(timeToLive));
    } else {
        setTimeToLive(null);
    }
}
 
Example #18
Source File: DispositionType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public Disposition newInstance(Object described)
{
    List l = (List) described;

    Disposition o = new Disposition();

    if(l.isEmpty())
    {
        throw new DecodeException("The first field cannot be omitted");
    }

    switch(6 - l.size())
    {

        case 0:
            Boolean batchable = (Boolean) l.get(5);
            o.setBatchable(batchable == null ? false : batchable);
        case 1:
            o.setState( (DeliveryState) l.get( 4 ) );
        case 2:
            Boolean settled = (Boolean) l.get(3);
            o.setSettled(settled == null ? false : settled);
        case 3:
            o.setLast( (UnsignedInteger) l.get( 2 ) );
        case 4:
            o.setFirst( (UnsignedInteger) l.get( 1 ) );
        case 5:
            o.setRole( Boolean.TRUE.equals(l.get( 0 )) ? Role.RECEIVER : Role.SENDER );
    }


    return o;
}
 
Example #19
Source File: BeginType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public int size()
{
    return _begin.getProperties() != null
              ? 8
              : _begin.getDesiredCapabilities() != null
              ? 7
              : _begin.getOfferedCapabilities() != null
              ? 6
              : (_begin.getHandleMax() != null && !_begin.getHandleMax().equals(UnsignedInteger.MAX_VALUE))
              ? 5
              : 4;

}
 
Example #20
Source File: Flow.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public void setIncomingWindow(UnsignedInteger incomingWindow)
{
    if( incomingWindow == null )
    {
        throw new NullPointerException("the incoming-window field is mandatory");
    }

    _incomingWindow = incomingWindow;
}
 
Example #21
Source File: HeaderTypeCodecTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@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 #22
Source File: EncoderImpl.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void writeUnsignedInteger(final UnsignedInteger uint)
{
    if(uint == null)
    {
        writeNull();
    }
    else
    {
        _unsignedIntegerType.fastWrite(this, uint);
    }
}
 
Example #23
Source File: MessageImpl.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void setDeliveryCount(long deliveryCount)
{
    if (_header == null)
    {
        if (deliveryCount == 0l)
        {
            return;
        }
        _header = new Header();
    }
    _header.setDeliveryCount(UnsignedInteger.valueOf(deliveryCount));
}
 
Example #24
Source File: Flow.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public void setOutgoingWindow(UnsignedInteger outgoingWindow)
{
    if( outgoingWindow == null )
    {
        throw new NullPointerException("the outgoing-window field is mandatory");
    }

    _outgoingWindow = outgoingWindow;
}
 
Example #25
Source File: TestAmqpPeer.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private UnsignedInteger calculateNewDeliveryCount(FlowMatcher flowMatcher, int creditToConsume) {
    UnsignedInteger dc = (UnsignedInteger) flowMatcher.getReceivedDeliveryCount();
    UnsignedInteger lc = (UnsignedInteger) flowMatcher.getReceivedLinkCredit();

    assertThat(UnsignedInteger.valueOf(creditToConsume), lessThan(lc));

    return dc.add(UnsignedInteger.valueOf(creditToConsume));
}
 
Example #26
Source File: ConsumerIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=20000)
public void testConsumerReceiveNoWaitThrowsIfConnectionLost() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();

        Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Queue queue = session.createQueue("queue");
        connection.start();

        testPeer.expectReceiverAttach();
        testPeer.expectLinkFlow(false, notNullValue(UnsignedInteger.class));
        testPeer.expectLinkFlow(true, notNullValue(UnsignedInteger.class));
        testPeer.dropAfterLastHandler();

        final MessageConsumer consumer = session.createConsumer(queue);

        try {
            consumer.receiveNoWait();
            fail("An exception should have been thrown");
        } catch (JMSException jmse) {
            // Expected
        }
    }
}
 
Example #27
Source File: UnsignedIntegerType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
UnsignedIntegerType(final EncoderImpl encoder, final DecoderImpl decoder)
{
    _unsignedIntegerEncoding = new AllUnsignedIntegerEncoding(encoder, decoder);
    _smallUnsignedIntegerEncoding = new SmallUnsignedIntegerEncoding(encoder, decoder);
    _zeroUnsignedIntegerEncoding = new ZeroUnsignedIntegerEncoding(encoder, decoder);
    encoder.register(UnsignedInteger.class, this);
    decoder.register(this);
}
 
Example #28
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetGroupSequenceOnReceivedMessageWithGroupSequenceMaxUnsignedIntValue() {
    Message message = Proton.message();

    Properties props = new Properties();
    props.setGroupSequence(UnsignedInteger.valueOf(MAX_UINT));
    message.setProperties(props);

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    // The unsigned int value 2^32-1 will be represented as a negative, and should be the largest such value, -1
    assertEquals("GroupSequence not as expected", -1, amqpMessageFacade.getGroupSequence());
}
 
Example #29
Source File: UnsignedIntegerTypeTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetEncodingWithSmallPositiveValue()
{
    DecoderImpl decoder = new DecoderImpl();
    EncoderImpl encoder = new EncoderImpl(decoder);
    UnsignedIntegerType ult = new UnsignedIntegerType(encoder, decoder);

    //values between 0 and 255 are encoded as a specific 'small' type using a single byte
    UnsignedIntegerEncoding encoding = ult.getEncoding(UnsignedInteger.valueOf(1L));
    assertEquals("incorrect encoding returned", EncodingCodes.SMALLUINT, encoding.getEncodingCode());
}
 
Example #30
Source File: ConnectionIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private void doMaxFrameSizeInfluencesOutgoingFrameSizeTestImpl(int frameSize, int bytesPayloadSize, int numFrames) throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        testPeer.expectSaslLayerDisabledConnect(equalTo(UnsignedInteger.valueOf(frameSize)));
        // Each connection creates a session for managing temporary destinations etc
        testPeer.expectBegin();

        String uri = "amqp://localhost:" + testPeer.getServerPort() + "?amqp.saslLayer=false&amqp.maxFrameSize=" + frameSize;
        ConnectionFactory factory = new JmsConnectionFactory(uri);
        Connection connection = factory.createConnection();

        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("myQueue");
        MessageProducer producer = session.createProducer(queue);

        // Expect n-1 transfers of maxFrameSize
        for (int i = 1; i < numFrames; i++) {
            testPeer.expectTransfer(frameSize);
        }
        // Plus one more of unknown size (framing overhead).
        testPeer.expectTransfer(0);

        // Send the message
        byte[] orig = createBytePyload(bytesPayloadSize);
        BytesMessage message = session.createBytesMessage();
        message.writeBytes(orig);

        producer.send(message);

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}