use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.
the class Session_1_0Test method assertAttachActions.
private void assertAttachActions(final Queue<?> queue, final Attach receivedAttach) {
Collection<QueueConsumer<?, ?>> consumers = queue.getConsumers();
assertEquals("Unexpected consumers size", 1, consumers.size());
ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
verify(_connection).sendFrame(eq(_session.getChannelId()), frameCapture.capture());
Attach sentAttach = (Attach) frameCapture.getValue();
assertEquals("Unexpected name", receivedAttach.getName(), sentAttach.getName());
assertEquals("Unexpected role", Role.SENDER, sentAttach.getRole());
Source receivedSource = (Source) receivedAttach.getSource();
Source sentSource = (Source) sentAttach.getSource();
assertEquals("Unexpected source address", receivedSource.getAddress(), sentSource.getAddress());
assertArrayEquals("Unexpected source capabilities", receivedSource.getCapabilities(), sentSource.getCapabilities());
assertEquals("Unexpected source durability", receivedSource.getDurable(), sentSource.getDurable());
assertEquals("Unexpected source expiry policy", receivedSource.getExpiryPolicy(), sentSource.getExpiryPolicy());
assertEquals("Unexpected source dynamic flag", receivedSource.getDynamic(), sentSource.getDynamic());
Target receivedTarget = (Target) receivedAttach.getTarget();
Target sentTarget = (Target) sentAttach.getTarget();
assertEquals("Unexpected target address", receivedTarget.getAddress(), sentTarget.getAddress());
assertArrayEquals("Unexpected target capabilities", receivedTarget.getCapabilities(), sentTarget.getCapabilities());
assertEquals("Unexpected target durability", receivedTarget.getDurable(), sentTarget.getDurable());
assertEquals("Unexpected target expiry policy", receivedTarget.getExpiryPolicy(), sentTarget.getExpiryPolicy());
assertEquals("Unexpected target dynamic flag", receivedTarget.getDynamic(), sentTarget.getDynamic());
final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
assertEquals("Unexpected number of queues after attach", 1, queues.size());
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.
the class Interaction method copyAttach.
private Attach copyAttach(final Attach attach) {
final Attach attachCopy = new Attach();
attachCopy.setName(attach.getName());
attachCopy.setHandle(attach.getHandle());
attachCopy.setRole(attach.getRole());
attachCopy.setSndSettleMode(attach.getSndSettleMode());
attachCopy.setRcvSettleMode(attach.getRcvSettleMode());
final BaseSource baseSource = attach.getSource();
if (baseSource != null && baseSource instanceof Source) {
final Source source = (Source) baseSource;
final Source sourceCopy = new Source();
sourceCopy.setAddress(source.getAddress());
sourceCopy.setDurable(source.getDurable());
sourceCopy.setExpiryPolicy(source.getExpiryPolicy());
sourceCopy.setTimeout(source.getTimeout());
sourceCopy.setDynamic(source.getDynamic());
if (source.getDynamicNodeProperties() != null) {
sourceCopy.setDynamicNodeProperties(new LinkedHashMap<>(source.getDynamicNodeProperties()));
}
sourceCopy.setFilter(source.getFilter());
sourceCopy.setDefaultOutcome(source.getDefaultOutcome());
sourceCopy.setOutcomes(source.getOutcomes());
sourceCopy.setCapabilities(source.getCapabilities());
attachCopy.setSource(sourceCopy);
} else {
attachCopy.setSource(baseSource);
}
final BaseTarget baseTarget = attach.getTarget();
if (baseTarget != null && baseTarget instanceof Target) {
final Target target = (Target) baseTarget;
final Target targetCopy = new Target();
targetCopy.setAddress(target.getAddress());
targetCopy.setDurable(target.getDurable());
targetCopy.setExpiryPolicy(target.getExpiryPolicy());
targetCopy.setTimeout(target.getTimeout());
targetCopy.setDynamic(target.getDynamic());
if (target.getDynamicNodeProperties() != null) {
targetCopy.setDynamicNodeProperties(new LinkedHashMap<>(target.getDynamicNodeProperties()));
}
targetCopy.setCapabilities(target.getCapabilities());
attachCopy.setTarget(targetCopy);
} else {
attachCopy.setTarget(baseTarget);
}
if (attach.getUnsettled() != null) {
attachCopy.setUnsettled(new LinkedHashMap<>(attach.getUnsettled()));
}
attachCopy.setIncompleteUnsettled(attach.getIncompleteUnsettled());
attachCopy.setInitialDeliveryCount(attach.getInitialDeliveryCount());
attachCopy.setMaxMessageSize(attach.getMaxMessageSize());
attachCopy.setOfferedCapabilities(attach.getOfferedCapabilities());
attachCopy.setDesiredCapabilities(attach.getDesiredCapabilities());
if (attach.getProperties() != null) {
attachCopy.setProperties(new LinkedHashMap<>(attach.getProperties()));
}
return attachCopy;
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.
the class DecodeErrorTest method nodePropertiesSupportedDistributionModes.
@Test
@SpecificationTest(section = "3.5.9", description = "The value of this entry MUST be of a type which provides the lifetime-policy archetype.")
public void nodePropertiesSupportedDistributionModes() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Target target = new Target();
target.setDynamic(Boolean.TRUE);
target.setDynamicNodeProperties(Collections.singletonMap(Symbol.valueOf("supported-dist-modes"), UnsignedInteger.ZERO));
final Response<?> latestResponse = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachTarget(target).attachRole(Role.SENDER).attach().consumeResponse().getLatestResponse();
assertThat(latestResponse, is(notNullValue()));
final Object responseBody = latestResponse.getBody();
final Error error;
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()));
assertThat(error.getCondition(), is(equalTo(DECODE_ERROR)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferUnsettledToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource.
@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2.2 Routing Errors", description = "It is possible that a message sent to a routing node has an address in the to field" + " of properties which, if used in the address field of target of an attach," + " would result in an unsuccessful link establishment (for example," + " if the address cannot be resolved to a node). In this case the routing node" + " MUST communicate the error back to the sender of the message." + " [...]" + " If the source of the link does not support the rejected outcome," + " [...] then the routing node MUST detach the link with an error." + " [...] the info field of error MUST contain an entry with symbolic key delivery-tag" + " and binary value of the delivery-tag of the message which caused the failure.")
@Test
public void transferUnsettledToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transfer();
Detach detach = interaction.consumeResponse().getLatestResponse(Detach.class);
Error error = detach.getError();
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), is(equalTo(AmqpError.NOT_FOUND)));
assertThat(error.getInfo(), is(notNullValue()));
assertThat(error.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.
the class TemporaryDestinationTest method deleteOnCloseWithConnectionClose.
private void deleteOnCloseWithConnectionClose(final Symbol[] targetCapabilities) throws Exception {
String newTemporaryNodeAddress = null;
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
Target target = new Target();
target.setDynamicNodeProperties(Collections.singletonMap(Session_1_0.LIFETIME_POLICY, new DeleteOnClose()));
target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
target.setDynamic(true);
target.setCapabilities(targetCapabilities);
final Interaction interaction = transport.newInteraction();
final Attach attachResponse = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTarget(target).attach().consumeResponse().getLatestResponse(Attach.class);
assertThat(attachResponse.getSource(), is(notNullValue()));
assertThat(attachResponse.getTarget(), is(notNullValue()));
newTemporaryNodeAddress = ((Target) attachResponse.getTarget()).getAddress();
assertThat(newTemporaryNodeAddress, is(notNullValue()));
assertThat(Utils.doesNodeExist(_brokerAddress, newTemporaryNodeAddress), is(true));
interaction.consumeResponse().getLatestResponse(Flow.class);
interaction.doCloseConnection();
}
assertThat(Utils.doesNodeExist(_brokerAddress, newTemporaryNodeAddress), is(false));
}
Aggregations