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
@BrokerSpecific(kind = KIND_BROKER_J)
@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(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).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), TEST_MESSAGE_CONTENT);
interaction.transferPayload(payload).transferSettled(true).transfer();
}
interaction.detachClose(true).detach().close().sync();
}
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).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(TEST_MESSAGE_CONTENT)));
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(_brokerAddress).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.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSource(source).attach().consumeResponse().getLatestResponse(Attach.class);
assertThat(attachResponse.getSource(), is(notNullValue()));
final String newTempQueueAddress = ((Source) attachResponse.getSource()).getAddress();
assertThat(Utils.doesNodeExist(_brokerAddress, newTempQueueAddress), is(true));
interaction.detachClose(true).detach().consumeResponse().getLatestResponse(Detach.class);
assertThat(Utils.doesNodeExist(_brokerAddress, newTempQueueAddress), is(false));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class MessageFormat method differentMessageFormatOnSameDeliveryFails.
@Test
@SpecificationTest(section = "2.7.5", description = "message-format: " + "This field MUST be specified for the first transfer of a multi-transfer message and can " + "only be omitted for continuation transfers. It is an error if the message-format on a " + "continuation transfer differs from the message-format on the first transfer of a delivery.")
public void differentMessageFormatOnSameDeliveryFails() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
QpidByteBuffer[] payloads = Utils.splitPayload("testData", 2);
final Response<?> latestResponse = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferMore(true).transferMessageFormat(UnsignedInteger.ZERO).transferPayload(payloads[0]).transfer().consumeResponse(null, Flow.class, Disposition.class).transferDeliveryTag(null).transferDeliveryId(null).transferMore(false).transferMessageFormat(UnsignedInteger.ONE).transferPayload(payloads[1]).transfer().consumeResponse(Detach.class, End.class, Close.class).getLatestResponse();
for (final QpidByteBuffer payload : payloads) {
payload.dispose();
}
assertThat(latestResponse, is(notNullValue()));
final Object responseBody = latestResponse.getBody();
final Error error;
if (responseBody instanceof Detach) {
error = ((Detach) responseBody).getError();
} else if (responseBody instanceof End) {
error = ((End) responseBody).getError();
} else if (responseBody instanceof Close) {
error = ((Close) responseBody).getError();
} else {
fail(String.format("Expected response of either Detach, End, or Close. Got '%s'", responseBody));
error = null;
}
assertThat(error, is(notNullValue()));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class TransferTest method exceedMaxMessageSizeLimit.
@Test
@SpecificationTest(section = "2.7.3", description = "max-message-size: This field indicates the maximum message size supported by the link" + " endpoint. Any attempt to deliver a message larger than this results in a" + " message-size-exceeded link-error. If this field is zero or unset, there is no maximum" + " size imposed by the link endpoint.")
public void exceedMaxMessageSizeLimit() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Binary deliveryTag = new Binary("testDeliveryTag".getBytes(UTF_8));
Interaction interaction = transport.newInteraction();
Open open = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).getLatestResponse(Open.class);
long maxFrameSize = open.getMaxFrameSize() == null ? Integer.MAX_VALUE : open.getMaxFrameSize().longValue();
Attach attach = interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).getLatestResponse(Attach.class);
final UnsignedLong maxMessageSizeLimit = attach.getMaxMessageSize();
assumeThat(maxMessageSizeLimit, is(notNullValue()));
assumeThat(maxMessageSizeLimit.longValue(), is(both(greaterThan(0L)).and(lessThan(MAX_MAX_MESSAGE_SIZE_WE_ARE_WILLING_TO_TEST))));
Flow flow = interaction.consumeResponse(Flow.class).getLatestResponse(Flow.class);
assertThat(flow.getLinkCredit().intValue(), is(greaterThan(1)));
final long chunkSize = Math.min(1024 * 1024, maxFrameSize - 100);
byte[] payloadChunk = createTestPaload(chunkSize);
interaction.transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(deliveryTag).transferPayloadData(payloadChunk).transferSettled(true).transferMore(true);
int payloadSize = 0;
while (payloadSize < maxMessageSizeLimit.longValue()) {
payloadSize += chunkSize;
interaction.transfer().sync();
}
while (true) {
Response<?> response = interaction.consumeResponse(Flow.class, Disposition.class, Detach.class).getLatestResponse();
if (response != null) {
if (response.getBody() instanceof Detach) {
break;
} else if (response.getBody() instanceof Disposition) {
assertThat(((Disposition) response.getBody()).getState(), is(instanceOf(Rejected.class)));
assertThat(((Rejected) ((Disposition) response.getBody()).getState()).getError(), is(notNullValue()));
assertThat(((Rejected) ((Disposition) response.getBody()).getState()).getError().getCondition(), is(equalTo(LinkError.MESSAGE_SIZE_EXCEEDED)));
}
}
}
Detach detach = interaction.getLatestResponse(Detach.class);
assertThat(detach.getError(), is(notNullValue()));
assertThat(detach.getError().getCondition(), is(equalTo(LinkError.MESSAGE_SIZE_EXCEEDED)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.
the class DischargeTest method dischargeUnknownTransactionIdWhenSourceDoesNotSupportRejectedOutcome.
@Test
@SpecificationTest(section = "4.3", description = "If the coordinator is unable to complete the discharge, the coordinator MUST convey the error to the controller " + "as a transaction-error. [...] If the source does not support " + "the rejected outcome, the transactional resource MUST detach the link to the coordinator, with the detach " + "performative carrying the transaction-error.")
public void dischargeUnknownTransactionIdWhenSourceDoesNotSupportRejectedOutcome() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
final Disposition disposition = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attachTarget(new Coordinator()).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayloadData(new Declare()).transfer().consumeResponse().getLatestResponse(Disposition.class);
assertThat(disposition.getSettled(), is(equalTo(true)));
assertThat(disposition.getState(), is(instanceOf(Declared.class)));
assertThat(((Declared) disposition.getState()).getTxnId(), is(notNullValue()));
interaction.consumeResponse(Flow.class);
final Discharge discharge = new Discharge();
discharge.setTxnId(new Binary("nonExistingTransaction".getBytes(UTF_8)));
final Detach detachResponse = interaction.transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(new Binary("discharge".getBytes(UTF_8))).transferPayloadData(discharge).transfer().consumeResponse(Detach.class).getLatestResponse(Detach.class);
Error error = detachResponse.getError();
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), is(equalTo(TransactionError.UNKNOWN_ID)));
}
}
Aggregations