use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class Session_1_0Test method assertFilter.
private void assertFilter(final Attach sentAttach, final String selectorExpression) {
Source source = (Source) sentAttach.getSource();
Map<Symbol, Filter> filter = source.getFilter();
assertNotNull("Filter is not set in response", filter);
assertEquals("Unexpected filter size", 1, filter.size());
assertTrue("Selector is not found", filter.containsKey(JMS_SELECTOR_FILTER));
Filter jmsSelectorFilter = filter.get(JMS_SELECTOR_FILTER);
assertTrue("Unexpected selector filter", jmsSelectorFilter instanceof JMSSelectorFilter);
assertEquals("Unexpected selector", selectorExpression, ((JMSSelectorFilter) jmsSelectorFilter).getValue());
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class Session_1_0Test method testSeparateSubscriptionNameSpaces.
public void testSeparateSubscriptionNameSpaces() throws Exception {
AMQPConnection_1_0 secondConnection = createAmqpConnection_1_0();
Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
Attach durableSharedWithContainerId = createSharedTopicAttach(true, linkName + "|1", address, false);
_session.receiveAttach(durableSharedWithContainerId);
assertAttachSent(_connection, _session, durableSharedWithContainerId, 0);
Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
assertEquals("Unexpected number of queues after durable non shared with containerId", 1, queues.size());
Attach durableNonSharedWithContainerId = createTopicAttach(true, linkName, address, false);
_session.receiveAttach(durableNonSharedWithContainerId);
assertAttachFailed(_connection, _session, durableNonSharedWithContainerId, 1);
queues = _virtualHost.getChildren(Queue.class);
assertEquals("Unexpected number of queues after durable non shared with containerId", 1, queues.size());
Attach nonDurableSharedWithContainerId = createSharedTopicAttach(false, linkName + "|3", address, false);
_session.receiveAttach(nonDurableSharedWithContainerId);
assertAttachSent(_connection, _session, nonDurableSharedWithContainerId, 3);
queues = _virtualHost.getChildren(Queue.class);
assertEquals("Unexpected number of queues after durable non shared with containerId", 2, queues.size());
Attach durableSharedWithoutContainerId = createSharedTopicAttach(true, linkName + "|4", address, true);
secondSession.receiveAttach(durableSharedWithoutContainerId);
assertAttachSent(secondConnection, secondSession, durableSharedWithoutContainerId, 0);
queues = _virtualHost.getChildren(Queue.class);
assertEquals("Unexpected number of queues after durable non shared with containerId", 3, queues.size());
Attach nonDurableSharedWithoutContainerId = createSharedTopicAttach(false, linkName + "|5", address, true);
secondSession.receiveAttach(nonDurableSharedWithoutContainerId);
assertAttachSent(secondConnection, secondSession, nonDurableSharedWithoutContainerId, 1);
queues = _virtualHost.getChildren(Queue.class);
assertEquals("Unexpected number of queues after durable non shared with containerId", 4, queues.size());
Attach nonDurableNonSharedWithoutContainerId = createTopicAttach(false, linkName + "|6", address, true);
secondSession.receiveAttach(nonDurableNonSharedWithoutContainerId);
assertAttachSent(secondConnection, secondSession, nonDurableNonSharedWithoutContainerId, 2);
queues = _virtualHost.getChildren(Queue.class);
assertEquals("Unexpected number of queues after durable non shared with containerId", 5, queues.size());
Attach nonDurableNonSharedWithContainerId = createTopicAttach(false, linkName + "|6", address, false);
_session.receiveAttach(nonDurableNonSharedWithContainerId);
assertAttachSent(_connection, _session, nonDurableNonSharedWithContainerId, 4);
queues = _virtualHost.getChildren(Queue.class);
assertEquals("Unexpected number of queues after durable non shared with containerId", 6, queues.size());
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach 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.server.protocol.v1_0.type.transport.Attach 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)));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method rejectNewDeliveryWhilstUnsettledIncomplete.
@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.7.3", description = "If set to true [incomplete-unsettled] indicates that the unsettled map provided is not complete. " + "When the map is incomplete the recipient of the map cannot take the absence of a delivery tag from " + "the map as evidence of settlement. On receipt of an incomplete unsettled map a sending endpoint MUST " + "NOT send any new deliveries (i.e. deliveries where resume is not set to true) to its partner (and " + "a receiving endpoint which sent an incomplete unsettled map MUST detach with an error on " + "receiving a transfer which does not have the resume flag set to true).")
public void rejectNewDeliveryWhilstUnsettledIncomplete() throws Exception {
final String destination = BrokerAdmin.TEST_QUEUE_NAME;
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse();
// 0. Open connection with small max-frame-size
final Open open = interaction.openMaxFrameSize(UnsignedInteger.valueOf(MIN_MAX_FRAME_SIZE)).open().consumeResponse().getLatestResponse(Open.class);
interaction.begin().consumeResponse(Begin.class);
// 1. attach with ReceiverSettleMode.SECOND
final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
interaction.attachHandle(linkHandle1).attachRole(Role.SENDER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachTargetAddress(destination).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
// 2. send enough unsettled deliverys to cause incomplete-unsettled to be true
// assume each delivery requires at least 1 byte, therefore max-frame-size deliveries should be enough
interaction.transferHandle(linkHandle1).transferPayloadData(TEST_MESSAGE_CONTENT);
Map<Binary, DeliveryState> localUnsettled = new HashMap<>(open.getMaxFrameSize().intValue());
for (int i = 0; i < open.getMaxFrameSize().intValue(); ++i) {
final Binary deliveryTag = new Binary(String.valueOf(i).getBytes(StandardCharsets.UTF_8));
final Disposition responseDisposition = interaction.transferDeliveryId(UnsignedInteger.valueOf(i)).transferDeliveryTag(deliveryTag).transfer().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
assertThat(responseDisposition.getSettled(), is(Boolean.FALSE));
localUnsettled.put(deliveryTag, null);
}
// 3. detach the link
interaction.detach().consumeResponse(Detach.class);
// 4. resume the link
final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
final Binary sampleLocalUnsettled = localUnsettled.keySet().iterator().next();
Map<Binary, DeliveryState> unsettled = Collections.singletonMap(sampleLocalUnsettled, localUnsettled.get(sampleLocalUnsettled));
final Response<?> latestResponse = interaction.attachHandle(linkHandle2).attachUnsettled(unsettled).attachIncompleteUnsettled(true).attach().consumeResponse(End.class, Attach.class).getLatestResponse();
assumeThat(latestResponse.getBody(), is(instanceOf(Attach.class)));
// 5. ensure attach has incomplete-unsettled
final Attach responseAttach = (Attach) latestResponse.getBody();
assertThat(responseAttach.getIncompleteUnsettled(), is(equalTo(true)));
// 6. send new transfer
final Binary newDeliveryTag = new Binary("newTransfer".getBytes(StandardCharsets.UTF_8));
final Detach detachWithError = interaction.transferHandle(linkHandle2).transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(newDeliveryTag).transfer().consumeResponse().getLatestResponse(Detach.class);
assertThat(detachWithError.getError(), is(notNullValue()));
final Error detachError = detachWithError.getError();
assertThat(detachError.getCondition(), is(equalTo(AmqpError.ILLEGAL_STATE)));
}
}
Aggregations