use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class FilterTest method unsupportedFilter.
@Test
@SpecificationTest(section = "3.5.1", description = "")
public void unsupportedFilter() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
final Map<Symbol, Filter> filters = new HashMap<>();
filters.put(Symbol.valueOf("selector-filter"), new JMSSelectorFilter("index=1"));
filters.put(Symbol.valueOf("test-filter"), new TestFilter("foo"));
final Attach responseAttach = interaction.negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachSourceFilter(filters).attach().consumeResponse().getLatestResponse(Attach.class);
assertThat(responseAttach.getName(), is(notNullValue()));
assertThat(responseAttach.getHandle().longValue(), is(both(greaterThanOrEqualTo(0L)).and(lessThan(UnsignedInteger.MAX_VALUE.longValue()))));
assertThat(responseAttach.getRole(), is(Role.SENDER));
assertThat(responseAttach.getSource(), is(nullValue()));
assertThat(responseAttach.getTarget(), is(nullValue()));
final Detach responseDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
assertThat(responseDetach.getClosed(), is(true));
assertThat(responseDetach.getError(), is(notNullValue()));
assertThat(responseDetach.getError().getCondition(), is(equalTo(AmqpError.NOT_IMPLEMENTED)));
interaction.doCloseConnection();
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class FilterTest method selectorFilter.
@Test
@SpecificationTest(section = "3.5.1", description = "A source can restrict the messages transferred from a source by specifying a filter.")
public void selectorFilter() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
Flow flow = interaction.getLatestResponse(Flow.class);
assumeThat("insufficient credit for the test", flow.getLinkCredit().intValue(), is(greaterThan(1)));
for (int i = 0; i < 2; i++) {
QpidByteBuffer payload = generateMessagePayloadWithApplicationProperties(Collections.singletonMap("index", i), getTestName());
interaction.transferPayload(payload).transferSettled(true).transfer();
}
interaction.detachClose(true).detach().close().sync();
}
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSourceFilter(Collections.singletonMap(Symbol.valueOf("selector-filter"), new JMSSelectorFilter("index=1"))).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
Object data = interaction.receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(data, is(equalTo(getTestName())));
Map<String, Object> applicationProperties = interaction.getLatestDeliveryApplicationProperties();
assertThat(applicationProperties, is(notNullValue()));
assertThat(applicationProperties.get("index"), is(equalTo(1)));
interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionState(new Accepted()).disposition();
interaction.close().sync();
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class DeleteOnCloseTest method deleteOnCloseOnSource.
@Test
@SpecificationTest(section = "3.5.10", description = "A node dynamically created with this lifetime policy will be deleted at the point that the link which caused its\n" + "creation ceases to exist.")
public void deleteOnCloseOnSource() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
Source source = new Source();
source.setDynamicNodeProperties(Collections.singletonMap(Session_1_0.LIFETIME_POLICY, new DeleteOnClose()));
source.setDynamic(true);
final Interaction interaction = transport.newInteraction();
final Attach attachResponse = interaction.negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSource(source).attach().consumeResponse().assertLatestResponse(this::assumeAttach).getLatestResponse(Attach.class);
assertThat(attachResponse.getSource(), is(notNullValue()));
final String newTempQueueAddress = ((Source) attachResponse.getSource()).getAddress();
try {
assertThat(Utils.doesNodeExist(getBrokerAdmin(), newTempQueueAddress), is(true));
} finally {
interaction.detachClose(true).detach().consumeResponse().getLatestResponse(Detach.class);
}
assertThat(Utils.doesNodeExist(getBrokerAdmin(), newTempQueueAddress), is(false));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class FlowTest method asynchronousNotification.
@Test
@SpecificationTest(section = "2.6.9", description = "Asynchronous notification can be accomplished as follows." + " The receiver maintains a target amount of link-credit for that link." + " As transfer arrive on the link, the sender’s link-credit decreases" + " as the delivery-count increases. When the sender’s link-credit falls below a threshold," + " the flow state MAY be sent to increase the sender’s link-credit back" + " to the desired target amount.")
public void asynchronousNotification() throws Exception {
BrokerAdmin brokerAdmin = getBrokerAdmin();
brokerAdmin.createQueue(BrokerAdmin.TEST_QUEUE_NAME);
final String[] contents = Utils.createTestMessageContents(3, getTestName());
Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, contents);
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
Interaction interaction = transport.newInteraction().negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class);
UnsignedInteger delta = UnsignedInteger.ONE;
UnsignedInteger incomingWindow = UnsignedInteger.valueOf(3);
Object receivedMessageContent1 = interaction.flowIncomingWindow(incomingWindow).flowNextIncomingIdFromPeerLatestSessionBeginAndDeliveryCount().flowLinkCredit(delta).flowHandleFromLinkHandle().flowDeliveryCount().flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flow().receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(receivedMessageContent1, is(equalTo(contents[0])));
UnsignedInteger firstDeliveryId = interaction.getLatestDeliveryId();
Object receivedMessageContent2 = interaction.flowIncomingWindow(incomingWindow).flowNextIncomingIdFromPeerLatestSessionBeginAndDeliveryCount().flowLinkCredit(delta).flowHandleFromLinkHandle().flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowDeliveryCount().flow().receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(receivedMessageContent2, is(equalTo(contents[1])));
UnsignedInteger secondDeliveryId = interaction.getLatestDeliveryId();
interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionFirst(firstDeliveryId).dispositionLast(secondDeliveryId).dispositionState(new Accepted()).disposition();
// detach link and consume detach to verify that no transfer was delivered
interaction.detachClose(true).detach().consume(Detach.class, Flow.class);
}
assertThat(Utils.receiveMessage(brokerAdmin, BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(contents[2])));
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class LinkStealingTest method subsequentAttachOnTheSameSession.
@Test
@SpecificationTest(section = "2.6.1. Naming a link", description = "Consequently, a link can only be active in one connection at a time." + " If an attempt is made to attach the link subsequently when it is not suspended," + " then the link can be ’stolen’, i.e., the second attach succeeds and the first" + " attach MUST then be closed with a link error of stolen. This behavior ensures" + " that in the event of a connection failure occurring and being noticed" + " by one party, that re-establishment has the desired effect.")
@Ignore("QPID-8328: Broker erroneously ends the session with internal error")
public void subsequentAttachOnTheSameSession() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
final Attach responseAttach = interaction.negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachInitialDeliveryCount(UnsignedInteger.ZERO).attachHandle(UnsignedInteger.ZERO).attach().consumeResponse().getLatestResponse(Attach.class);
assertThat(responseAttach.getName(), is(notNullValue()));
assertThat(responseAttach.getHandle().longValue(), is(both(greaterThanOrEqualTo(0L)).and(lessThan(UnsignedInteger.MAX_VALUE.longValue()))));
assertThat(responseAttach.getRole(), is(Role.RECEIVER));
assertThat(responseAttach.getTarget(), is(notNullValue()));
assertThat(responseAttach.getSource(), is(notNullValue()));
Detach stolenDetach = interaction.consumeResponse(Flow.class).attachHandle(UnsignedInteger.ONE).attach().consume(Detach.class, Attach.class, Flow.class);
assertThat(stolenDetach.getHandle().longValue(), is(equalTo(responseAttach.getHandle().longValue())));
assertThat(stolenDetach.getError(), is(notNullValue()));
assertThat(stolenDetach.getError().getCondition(), is(equalTo(LinkError.STOLEN)));
}
}
Aggregations