Search in sources :

Example 11 with Interaction

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

the class PublisherConfirmsTest method publishUnroutableMessageWithTransactionalConfirms.

@Test
public void publishUnroutableMessageWithTransactionalConfirms() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).tx().select().consumeResponse(TxSelectOkBody.class).basic().confirmSelect().consumeResponse(ConfirmSelectOkBody.class).basic().publishExchange("").publishRoutingKey("unrouteable").publishMandatory(true).publishMessage().basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).publishMandatory(true).publishMessage();
        final BasicNackBody nackBody = interaction.consumeResponse().getLatestResponse(BasicNackBody.class);
        assertThat(nackBody.getDeliveryTag(), is(equalTo(1L)));
        final BasicAckBody ackBody = interaction.consumeResponse().getLatestResponse(BasicAckBody.class);
        assertThat(ackBody.getDeliveryTag(), is(equalTo(2L)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
        interaction.tx().commit();
        final Set<Class<?>> outstanding = Sets.newHashSet(TxCommitOkBody.class, BasicReturnBody.class, ContentHeaderBody.class);
        while (!outstanding.isEmpty()) {
            final Response<?> response = interaction.consumeResponse(outstanding.toArray(new Class<?>[outstanding.size()])).getLatestResponse();
            final boolean remove = outstanding.remove(response.getBody().getClass());
            assertThat("" + response, remove, is(equalTo(true)));
        }
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v0_8.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v0_8.Interaction) TxSelectOkBody(org.apache.qpid.server.protocol.v0_8.transport.TxSelectOkBody) BasicAckBody(org.apache.qpid.server.protocol.v0_8.transport.BasicAckBody) BasicNackBody(org.apache.qpid.server.protocol.v0_8.transport.BasicNackBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 12 with Interaction

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

the class TransactionTimeoutTest method publishTransactionTimeout.

@Test
public void publishTransactionTimeout() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).tx().select().consumeResponse(TxSelectOkBody.class).basic().contentHeaderPropertiesContentType("text/plain").contentHeaderPropertiesHeaders(Collections.singletonMap("test", "testValue")).contentHeaderPropertiesDeliveryMode((byte) 1).contentHeaderPropertiesPriority((byte) 1).publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).content("Test").publishMessage().exchange().declarePassive(true).declare().consumeResponse(ExchangeDeclareOkBody.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
        final ConnectionCloseBody close = interaction.consumeResponse().getLatestResponse(ConnectionCloseBody.class);
        assertThat(close.getReplyCode(), is(equalTo(ErrorCodes.RESOURCE_ERROR)));
        assertThat(close.getReplyText().toString(), containsString("transaction timed out"));
        interaction.connection().closeOk();
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v0_8.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v0_8.Interaction) TxSelectOkBody(org.apache.qpid.server.protocol.v0_8.transport.TxSelectOkBody) ConnectionCloseBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody) Test(org.junit.Test)

Example 13 with Interaction

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

the class AnonymousTerminusTest method transferPreSettledToKnownDestination.

@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2. Sending A Message", description = "Messages sent over links into a routing node will be" + " forwarded to the node referenced in the to field of properties of the message" + " just as if a direct link has been established to that node.")
@Test
public void transferPreSettledToKnownDestination() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(generateMessagePayloadToDestination(BrokerAdmin.TEST_QUEUE_NAME)).transferSettled(Boolean.TRUE).transferDeliveryTag(_deliveryTag).transfer().sync();
        Object receivedMessage = Utils.receiveMessage(_brokerAddress, BrokerAdmin.TEST_QUEUE_NAME);
        assertThat(receivedMessage, is(equalTo(TEST_MESSAGE_CONTENT)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) 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 14 with Interaction

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

the class AnonymousTerminusTest method transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeSupportedBySource.

@Test
public void transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeSupportedBySource() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        final UnsignedInteger linkHandle = UnsignedInteger.ONE;
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
        interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.FALSE).transfer();
        Disposition disposition = interaction.consumeResponse().getLatestResponse(Disposition.class);
        assertThat(disposition.getSettled(), is(true));
        DeliveryState dispositionState = disposition.getState();
        assertThat(dispositionState, is(instanceOf(TransactionalState.class)));
        final TransactionalState receivedTxnState = (TransactionalState) dispositionState;
        assertThat(receivedTxnState.getOutcome(), is(instanceOf(Rejected.class)));
        final Error rejectedError = ((Rejected) receivedTxnState.getOutcome()).getError();
        assertThat(rejectedError.getCondition(), is(equalTo(AmqpError.NOT_FOUND)));
        assertThat(rejectedError.getInfo(), is(notNullValue()));
        assertThat(rejectedError.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
        interaction.txnDischarge(txnState, false);
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) 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) 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) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) TransactionalState(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 15 with Interaction

use of org.apache.qpid.tests.protocol.v1_0.Interaction 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)

Aggregations

Test (org.junit.Test)112 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)101 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)100 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)91 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)53 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)48 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)33 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)31 InetSocketAddress (java.net.InetSocketAddress)28 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)28 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)28 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)28 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)24 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)16 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)13 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)12 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)12 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)11 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)10 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)10