use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class MultiTransferTest method multiTransferInterleaved.
@Test
@SpecificationTest(section = "2.6.14", description = "[...]messages being transferred along different links MAY be interleaved")
public void multiTransferInterleaved() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
QpidByteBuffer[] messagePayload1 = Utils.splitPayload("testData1", 2);
QpidByteBuffer[] messagePayload2 = Utils.splitPayload("testData2", 2);
UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
Binary deliveryTag1 = new Binary("testTransfer1".getBytes(UTF_8));
Binary deliveryTag2 = new Binary("testTransfer2".getBytes(UTF_8));
UnsignedInteger deliverId1 = UnsignedInteger.ZERO;
UnsignedInteger deliveryId2 = UnsignedInteger.ONE;
Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachName("testLink1").attachHandle(linkHandle1).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).attachName("testLink2").attachHandle(linkHandle2).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle1).transferDeliveryId(deliverId1).transferDeliveryTag(deliveryTag1).transferMore(true).transferPayload(messagePayload1[0]).transfer().sync().transferHandle(linkHandle2).transferDeliveryId(deliveryId2).transferDeliveryTag(deliveryTag2).transferMore(true).transferPayload(messagePayload2[0]).transfer().sync().transferHandle(linkHandle1).transferDeliveryId(deliverId1).transferDeliveryTag(deliveryTag1).transferMore(false).transferPayload(messagePayload1[1]).transfer().sync().transferHandle(linkHandle2).transferDeliveryId(deliveryId2).transferDeliveryTag(deliveryTag2).transferMore(false).transferPayload(messagePayload2[1]).transfer().sync();
for (final QpidByteBuffer payload : messagePayload1) {
payload.dispose();
}
for (final QpidByteBuffer payload : messagePayload2) {
payload.dispose();
}
Map<UnsignedInteger, Disposition> dispositionMap = new HashMap<>();
for (int i = 0; i < 2; i++) {
Disposition disposition = interaction.consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
dispositionMap.put(disposition.getFirst(), disposition);
assertThat(disposition.getLast(), isOneOf(null, disposition.getFirst()));
assertThat(disposition.getSettled(), is(equalTo(false)));
assertThat(disposition.getState(), is(instanceOf(Accepted.class)));
}
assertThat("Unexpected number of dispositions", dispositionMap.size(), equalTo(2));
assertThat(dispositionMap.containsKey(deliverId1), is(true));
assertThat(dispositionMap.containsKey(deliveryId2), is(true));
}
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class TransferTest method transfersWithDuplicateUnsettledDeliveryTag.
@Test
@SpecificationTest(section = "2.7.5", description = "[delivery-tag] uniquely identifies the delivery attempt for a given message on this link.")
public void transfersWithDuplicateUnsettledDeliveryTag() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Binary deliveryTag = new Binary("testDeliveryTag".getBytes(UTF_8));
Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
Flow flow = interaction.getLatestResponse(Flow.class);
assertThat(flow.getLinkCredit().intValue(), is(greaterThan(1)));
interaction.transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(deliveryTag).transferPayloadData("test").transfer().sync().transferDeliveryTag(deliveryTag).transferDeliveryId(UnsignedInteger.ONE).transferPayloadData("test2").transfer().sync();
do {
interaction.consumeResponse();
Response<?> response = interaction.getLatestResponse();
assertThat(response, is(notNullValue()));
Object body = response.getBody();
if (body instanceof ErrorCarryingFrameBody) {
Error error = ((ErrorCarryingFrameBody) body).getError();
assertThat(error, is(notNullValue()));
break;
} else if (body instanceof Disposition) {
Disposition disposition = (Disposition) body;
assertThat(disposition.getSettled(), is(equalTo(false)));
assertThat(disposition.getFirst(), is(not(equalTo(UnsignedInteger.ONE))));
assertThat(disposition.getLast(), is(not(equalTo(UnsignedInteger.ONE))));
} else if (!(body instanceof Flow)) {
fail("Unexpected response " + body);
}
} while (true);
}
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class TransferTest method receiveMixtureOfTransactionalAndNonTransactionalDeliveries.
@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void receiveMixtureOfTransactionalAndNonTransactionalDeliveries() throws Exception {
int numberOfMessages = 4;
for (int i = 0; i < numberOfMessages; i++) {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_DATA + "_" + i);
}
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).attachHandle(UnsignedInteger.ZERO).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.valueOf(numberOfMessages)).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.valueOf(numberOfMessages)).flowHandleFromLinkHandle().flow();
for (int i = 0; i < numberOfMessages; i++) {
interaction.receiveDelivery(Flow.class).decodeLatestDelivery();
Object data = interaction.getDecodedLatestDelivery();
assertThat(data, Is.is(CoreMatchers.equalTo(TEST_MESSAGE_DATA + "_" + i)));
assertThat(interaction.getLatestDeliveryId(), Is.is(equalTo(UnsignedInteger.valueOf(i))));
}
final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ONE);
interaction.txnAttachCoordinatorLink(txnState).txnDeclare(txnState);
interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionFirst(UnsignedInteger.ZERO).dispositionLast(UnsignedInteger.ONE).dispositionState(new Accepted()).disposition().dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionFirst(UnsignedInteger.valueOf(2)).dispositionLast(UnsignedInteger.valueOf(3)).dispositionTransactionalState(txnState.getCurrentTransactionId(), new Accepted()).disposition();
final Discharge discharge = new Discharge();
discharge.setTxnId(txnState.getCurrentTransactionId());
discharge.setFail(false);
interaction.transferHandle(txnState.getHandle()).transferDeliveryId(UnsignedInteger.valueOf(4)).transferDeliveryTag(new Binary(("transaction-" + 4).getBytes(StandardCharsets.UTF_8))).transferPayloadData(discharge).transfer();
Disposition declareTransactionDisposition = null;
Flow coordinatorFlow = null;
do {
interaction.consumeResponse(Disposition.class, Flow.class);
Response<?> response = interaction.getLatestResponse();
if (response.getBody() instanceof Disposition) {
declareTransactionDisposition = (Disposition) response.getBody();
}
if (response.getBody() instanceof Flow) {
final Flow flowResponse = (Flow) response.getBody();
if (flowResponse.getHandle().equals(txnState.getHandle())) {
coordinatorFlow = flowResponse;
}
}
} while (declareTransactionDisposition == null || coordinatorFlow == null);
if (getBrokerAdmin().isQueueDepthSupported()) {
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
}
String messageText = TEST_MESSAGE_DATA + "_" + 4;
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageText);
Object receivedMessage = Utils.receiveMessage(_brokerAddress, BrokerAdmin.TEST_QUEUE_NAME);
assertThat(receivedMessage, is(equalTo(messageText)));
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class AMQPConnection_1_0Impl method receiveSaslInit.
@Override
public void receiveSaslInit(final SaslInit saslInit) {
assertState(ConnectionState.AWAIT_SASL_INIT);
if (saslInit.getHostname() != null && !"".equals(saslInit.getHostname().trim())) {
_localHostname = saslInit.getHostname();
} else if (getNetwork().getSelectedHost() != null) {
_localHostname = getNetwork().getSelectedHost();
}
String mechanism = saslInit.getMechanism().toString();
final Binary initialResponse = saslInit.getInitialResponse();
byte[] response = initialResponse == null ? new byte[0] : initialResponse.getArray();
List<String> availableMechanisms = _subjectCreator.getAuthenticationProvider().getAvailableMechanisms(getTransport().isSecure());
if (!availableMechanisms.contains(mechanism)) {
handleSaslError();
} else {
_saslNegotiator = _subjectCreator.createSaslNegotiator(mechanism, this);
processSaslResponse(response);
}
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class AMQPConnection_1_0Impl method receiveSaslResponse.
@Override
public void receiveSaslResponse(final SaslResponse saslResponse) {
assertState(ConnectionState.AWAIT_SASL_RESPONSE);
final Binary responseBinary = saslResponse.getResponse();
byte[] response = responseBinary == null ? new byte[0] : responseBinary.getArray();
processSaslResponse(response);
}
Aggregations