Search in sources :

Example 51 with Detach

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();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) JMSSelectorFilter(org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) JMSSelectorFilter(org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) Filter(org.apache.qpid.server.protocol.v1_0.type.messaging.Filter) TestFilter(org.apache.qpid.tests.protocol.v1_0.extensions.type.TestFilter) HashMap(java.util.HashMap) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) TestFilter(org.apache.qpid.tests.protocol.v1_0.extensions.type.TestFilter) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 52 with Detach

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();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) JMSSelectorFilter(org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) 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 53 with Detach

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));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) 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) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 54 with Detach

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])));
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) BrokerAdmin(org.apache.qpid.tests.utils.BrokerAdmin) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 55 with Detach

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

Aggregations

Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)43 Test (org.junit.Test)41 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)39 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)39 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)37 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)34 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)19 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)15 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)13 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)12 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)12 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)10 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)9 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)8 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)8 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)8 Ignore (org.junit.Ignore)8 HashMap (java.util.HashMap)7 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)7 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)7