Search in sources :

Example 26 with Attach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.

the class DeleteOnCloseTest method deleteOnCloseOnTarget.

@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 deleteOnCloseOnTarget() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        Target target = new Target();
        target.setDynamicNodeProperties(Collections.singletonMap(Session_1_0.LIFETIME_POLICY, new DeleteOnClose()));
        target.setDynamic(true);
        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.getTarget(), is(notNullValue()));
        final String newTempQueueAddress = ((Target) attachResponse.getTarget()).getAddress();
        assertThat(Utils.doesNodeExist(_brokerAddress, newTempQueueAddress), is(true));
        interaction.consumeResponse().getLatestResponse(Flow.class);
        interaction.detachClose(true).detach().consumeResponse().getLatestResponse(Detach.class);
        assertThat(Utils.doesNodeExist(_brokerAddress, newTempQueueAddress), 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) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 27 with Attach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.

the class DeleteOnCloseTest method doesNotDeleteOnDetach.

@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 doesNotDeleteOnDetach() 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.detach().consumeResponse().getLatestResponse(Detach.class);
        assertThat(Utils.doesNodeExist(_brokerAddress, newTempQueueAddress), is(true));
    }
}
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) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) 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 28 with Attach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.

the class MultiTransferTest method abortMultiTransferMessage.

// 
@Test
@SpecificationTest(section = "2.6.14", description = "The sender MAY indicate an aborted attempt to deliver a message by setting the abort flag on the last transfer." + "In this case the receiver MUST discard the message data that was transferred prior to the abort.")
public void abortMultiTransferMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        QpidByteBuffer[] payloads = Utils.splitPayload("testData", 2);
        final UnsignedInteger deliveryId = UnsignedInteger.ZERO;
        final Binary deliveryTag = new Binary("testTransfer".getBytes(UTF_8));
        Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(payloads[0]).transferDeliveryId(deliveryId).transferDeliveryTag(deliveryTag).transferMore(true).transfer().sync().transferPayload(null).transferMore(null).transferAborted(true).transfer();
        for (final QpidByteBuffer payload : payloads) {
            payload.dispose();
        }
        Response<?> latestResponse = interaction.consumeResponse(new Class<?>[] { null }).getLatestResponse();
        assertThat(latestResponse, is(nullValue()));
    }
}
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) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) 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 29 with Attach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach 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));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) HashMap(java.util.HashMap) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) 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 30 with Attach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.

the class TransferTest method durableTransferWithRejectedOutcome.

@Test
@SpecificationTest(section = "3.2.1", description = "Durable messages MUST NOT be lost even if an intermediary is unexpectedly terminated and " + "restarted. A target which is not capable of fulfilling this guarantee MUST NOT accept messages " + "where the durable header is set to true: if the source allows the rejected outcome then the " + "message SHOULD be rejected with the precondition-failed error, otherwise the link MUST be " + "detached by the receiver with the same error.")
public void durableTransferWithRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        MessageEncoder messageEncoder = new MessageEncoder();
        final Header header = new Header();
        header.setDurable(true);
        messageEncoder.setHeader(header);
        messageEncoder.addData("foo");
        final Disposition receivedDisposition = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(messageEncoder.getPayload()).transferRcvSettleMode(ReceiverSettleMode.FIRST).transfer().consumeResponse().getLatestResponse(Disposition.class);
        assertThat(receivedDisposition.getSettled(), is(true));
        assertThat(receivedDisposition.getState(), is(instanceOf(Outcome.class)));
        if (getBrokerAdmin().supportsRestart()) {
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Accepted.ACCEPTED_SYMBOL));
        } else {
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Rejected.REJECTED_SYMBOL));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) MessageEncoder(org.apache.qpid.tests.protocol.v1_0.MessageEncoder) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)85 Test (org.junit.Test)84 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)82 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)82 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)70 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)39 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)37 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)36 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)32 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)32 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)27 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)24 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)23 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)20 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)18 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)17 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)17 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)14 InetSocketAddress (java.net.InetSocketAddress)13 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)11