Search in sources :

Example 1 with Target

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());
}
Also used : Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) QueueConsumer(org.apache.qpid.server.queue.QueueConsumer) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) FrameBody(org.apache.qpid.server.protocol.v1_0.type.FrameBody) Queue(org.apache.qpid.server.model.Queue) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source)

Example 2 with Target

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;
}
Also used : BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget)

Example 3 with Target

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)));
    }
}
Also used : Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 4 with Target

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)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 5 with Target

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));
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) DeleteOnClose(org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnClose) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open)

Aggregations

Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)14 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)11 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)11 Test (org.junit.Test)11 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)10 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)9 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)9 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)8 StoreException (org.apache.qpid.server.store.StoreException)8 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)7 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)6 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)6 PreparedStatement (java.sql.PreparedStatement)5 BaseTarget (org.apache.qpid.server.protocol.v1_0.type.BaseTarget)5 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)5 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)5 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)4 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)4 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)4