Search in sources :

Example 1 with MessageEncoder

use of org.apache.qpid.tests.protocol.v1_0.MessageEncoder in project qpid-broker-j by apache.

the class TransferTest method durableTransferWithoutRejectedOutcome.

@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.")
@BrokerSpecific(kind = BrokerAdmin.KIND_BROKER_J)
public void durableTransferWithoutRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        MessageEncoder messageEncoder = new MessageEncoder();
        final Header header = new Header();
        header.setDurable(true);
        messageEncoder.setHeader(header);
        messageEncoder.addData(getTestName());
        final Response<?> response = transport.newInteraction().negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).assertLatestResponse(Flow.class, this::assumeSufficientCredits).transferDeliveryId().transferPayload(messageEncoder.getPayload()).transferRcvSettleMode(ReceiverSettleMode.FIRST).transfer().consumeResponse().getLatestResponse();
        if (getBrokerAdmin().supportsRestart()) {
            assertThat(response, is(notNullValue()));
            assertThat(response.getBody(), is(instanceOf(Disposition.class)));
            final Disposition receivedDisposition = (Disposition) response.getBody();
            assertThat(receivedDisposition.getSettled(), is(true));
            assertThat(receivedDisposition.getState(), is(instanceOf(Outcome.class)));
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Accepted.ACCEPTED_SYMBOL));
        } else {
            assertThat(response, is(notNullValue()));
            assertThat(response.getBody(), is(instanceOf(Detach.class)));
            final Detach receivedDetach = (Detach) response.getBody();
            assertThat(receivedDetach.getError(), is(notNullValue()));
            assertThat(receivedDetach.getError().getCondition(), is(AmqpError.PRECONDITION_FAILED));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) MessageEncoder(org.apache.qpid.tests.protocol.v1_0.MessageEncoder) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) BrokerSpecific(org.apache.qpid.tests.utils.BrokerSpecific) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 2 with MessageEncoder

use of org.apache.qpid.tests.protocol.v1_0.MessageEncoder 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.")
@BrokerSpecific(kind = BrokerAdmin.KIND_BROKER_J)
public void durableTransferWithRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        MessageEncoder messageEncoder = new MessageEncoder();
        final Header header = new Header();
        header.setDurable(true);
        messageEncoder.setHeader(header);
        messageEncoder.addData(getTestName());
        final Disposition receivedDisposition = transport.newInteraction().negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).assertLatestResponse(Flow.class, this::assumeSufficientCredits).transferDeliveryId().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) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) 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) BrokerSpecific(org.apache.qpid.tests.utils.BrokerSpecific) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 3 with MessageEncoder

use of org.apache.qpid.tests.protocol.v1_0.MessageEncoder in project qpid-broker-j by apache.

the class AnonymousTerminusTest method generateMessagePayloadToDestination.

private QpidByteBuffer generateMessagePayloadToDestination(final String destinationName) {
    MessageEncoder messageEncoder = new MessageEncoder();
    final Properties properties = new Properties();
    properties.setTo(destinationName);
    messageEncoder.setProperties(properties);
    messageEncoder.addData(getTestName());
    return messageEncoder.getPayload();
}
Also used : MessageEncoder(org.apache.qpid.tests.protocol.v1_0.MessageEncoder) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 4 with MessageEncoder

use of org.apache.qpid.tests.protocol.v1_0.MessageEncoder in project qpid-broker-j by apache.

the class FilterTest method generateMessagePayloadWithApplicationProperties.

private QpidByteBuffer generateMessagePayloadWithApplicationProperties(final Map<String, Object> applicationProperties, String content) {
    MessageEncoder messageEncoder = new MessageEncoder();
    messageEncoder.setApplicationProperties(applicationProperties);
    messageEncoder.addData(content);
    return messageEncoder.getPayload();
}
Also used : MessageEncoder(org.apache.qpid.tests.protocol.v1_0.MessageEncoder)

Aggregations

MessageEncoder (org.apache.qpid.tests.protocol.v1_0.MessageEncoder)4 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)2 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)2 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)2 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)2 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)2 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)2 BrokerSpecific (org.apache.qpid.tests.utils.BrokerSpecific)2 Test (org.junit.Test)2 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)1 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)1