use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testDataWithContentTypeOther.
public void testDataWithContentTypeOther() throws Exception {
final byte[] expected = "helloworld".getBytes(UTF_8);
final Data value = new Data(new Binary(expected));
final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("application/bin"));
Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "application/octet-stream", convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertArrayEquals("Unexpected content", expected, getBytes(content));
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testAmqpValueWithList.
public void testAmqpValueWithList() throws Exception {
final List<Object> originalList = new ArrayList<>();
originalList.add(new Binary(new byte[] { 0x00, (byte) 0xFF }));
originalList.add(42);
originalList.add(null);
final AmqpValue amqpValue = new AmqpValue(originalList);
Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "jms/stream-message", convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
List<Object> convertedList = new JmsStreamMessageToList().toObject(getBytes(content));
assertEquals("Unexpected size", originalList.size(), convertedList.size());
assertArrayEquals("Unexpected binary item", ((Binary) originalList.get(0)).getArray(), (byte[]) convertedList.get(0));
assertEquals("Unexpected int item", originalList.get(1), convertedList.get(1));
assertEquals("Unexpected null item", originalList.get(2), convertedList.get(2));
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method doTestConvertOfDataSectionForTextualType.
private void doTestConvertOfDataSectionForTextualType(final String contentType) throws Exception {
final String expected = "testContent";
final Data value = new Data(new Binary(expected.getBytes(UTF_8)));
final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf(contentType));
Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertEquals("Unexpected content", expected, new String(getBytes(content), UTF_8));
assertEquals("Unexpected mime type", "text/plain", convertedMessage.getMessageHeader().getMimeType());
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method resumeReceivingLinkWithSingleUnsettledAccepted.
@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.6.13", description = "When a suspended link having unsettled deliveries is resumed," + " the unsettled field from the attach frame will carry" + " the delivery-tags and delivery state of all deliveries" + " considered unsettled by the issuing link endpoint.")
public void resumeReceivingLinkWithSingleUnsettledAccepted() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSndSettleMode(SenderSettleMode.UNSETTLED).attach().consumeResponse();
Attach attach = interaction.getLatestResponse(Attach.class);
assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
interaction.flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
List<Transfer> transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer transfer = transfers.get(0);
Binary deliveryTag = transfer.getDeliveryTag();
assertThat(deliveryTag, is(notNullValue()));
assertThat(transfer.getSettled(), is(not(equalTo(true))));
Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
Detach detach = interaction.detach().consumeResponse().getLatestResponse(Detach.class);
assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
interaction.attachUnsettled(Collections.singletonMap(deliveryTag, new Accepted())).attach().consumeResponse(Attach.class);
Attach resumeAttach = interaction.getLatestResponse(Attach.class);
Map<Binary, DeliveryState> unsettled = resumeAttach.getUnsettled();
assertThat(unsettled, is(notNullValue()));
assertThat(unsettled.entrySet(), hasSize(1));
Map.Entry<Binary, DeliveryState> entry = unsettled.entrySet().iterator().next();
assertThat(entry.getKey(), is(equalTo(deliveryTag)));
interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer resumeTransfer = transfers.get(0);
assertThat(resumeTransfer.getResume(), is(equalTo(true)));
assertThat(resumeTransfer.getDeliveryTag(), is(equalTo(deliveryTag)));
assertThat(resumeTransfer.getPayload(), is(nullValue()));
if (!Boolean.TRUE.equals(resumeTransfer.getSettled())) {
interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionRole(Role.RECEIVER).disposition();
}
interaction.doCloseConnection();
if (getBrokerAdmin().isQueueDepthSupported()) {
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
}
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method resumeReceivingLinkOneUnsettledWithNoOutcome.
@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.6.13", description = "When a suspended link having unsettled deliveries is resumed," + " the unsettled field from the attach frame will carry" + " the delivery-tags and delivery state of all deliveries" + " considered unsettled by the issuing link endpoint.")
public void resumeReceivingLinkOneUnsettledWithNoOutcome() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSndSettleMode(SenderSettleMode.UNSETTLED).attach().consumeResponse();
Attach attach = interaction.getLatestResponse(Attach.class);
assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
interaction.flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
List<Transfer> transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer transfer = transfers.get(0);
Binary deliveryTag = transfer.getDeliveryTag();
assertThat(deliveryTag, is(notNullValue()));
Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
Detach detach = interaction.detach().consumeResponse(Detach.class).getLatestResponse(Detach.class);
assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
interaction.attachUnsettled(Collections.singletonMap(deliveryTag, null)).attach().consumeResponse(Attach.class);
Attach resumeAttach = interaction.getLatestResponse(Attach.class);
Map<Binary, DeliveryState> unsettled = resumeAttach.getUnsettled();
assertThat(unsettled, is(notNullValue()));
assertThat(unsettled.entrySet(), hasSize(1));
Map.Entry<Binary, DeliveryState> entry = unsettled.entrySet().iterator().next();
assertThat(entry.getKey(), is(equalTo(deliveryTag)));
interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer resumeTransfer = transfers.get(0);
assertThat(resumeTransfer.getResume(), is(equalTo(true)));
assertThat(resumeTransfer.getDeliveryTag(), is(equalTo(deliveryTag)));
assertThat(resumeTransfer.getPayload(), is(notNullValue()));
interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionRole(Role.RECEIVER).disposition();
interaction.doCloseConnection();
if (getBrokerAdmin().isQueueDepthSupported()) {
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), Matchers.is(Matchers.equalTo(0)));
}
}
}
Aggregations