Search in sources :

Example 16 with Detach

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

the class DischargeTest method dischargeUnsettledAfterSenderClose.

@Test
@SpecificationTest(section = "4.4.4.1", description = "Transactional Posting [...]" + " Delivery Sent Unsettled By Controller; Resource Does Not Settle [...]" + " After a successful discharge, the state of unsettled deliveries at the resource MUST" + " reflect the outcome that was applied.")
public void dischargeUnsettledAfterSenderClose() throws Exception {
    assumeThat(getBrokerAdmin().isQueueDepthSupported(), is(true));
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachHandle(UnsignedInteger.ONE).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferTransactionalState(txnState.getCurrentTransactionId()).transferPayloadData("test message").transferHandle(UnsignedInteger.ONE).transfer().consumeResponse(Disposition.class).detachHandle(UnsignedInteger.ONE).detachClose(true).detach().consumeResponse(Detach.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
        interaction.txnDischarge(txnState, false);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) 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 17 with Detach

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

the class TransactionalTransferTest method assertUnknownTransactionIdError.

private void assertUnknownTransactionIdError(final Response<?> response) {
    assertThat(response, is(notNullValue()));
    final Object body = response.getBody();
    assertThat(body, is(notNullValue()));
    Error error = null;
    if (body instanceof Close) {
        error = ((Close) body).getError();
    } else if (body instanceof End) {
        error = ((End) body).getError();
    } else if (body instanceof Detach) {
        error = ((Detach) body).getError();
    } else {
        fail(String.format("Unexpected response %s", body.getClass().getSimpleName()));
    }
    assertThat(error, is(notNullValue()));
    assertThat(error.getCondition(), equalTo(TransactionError.UNKNOWN_ID));
}
Also used : Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach)

Example 18 with Detach

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

the class AttachTest method attachSenderWithNullSource.

@Test
@SpecificationTest(section = "2.6.3", description = "Note that if the application chooses not to create a terminus, the session endpoint will" + " still create a link endpoint and issue an attach indicating that the link endpoint has" + " no associated local terminus. In this case, the session endpoint MUST immediately" + " detach the newly created link endpoint.")
public void attachSenderWithNullSource() throws Exception {
    String queueName = "testQueue";
    getBrokerAdmin().createQueue(queueName);
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        Interaction interaction = transport.newInteraction();
        final Attach responseAttach = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachSource(null).attachTargetAddress(queueName).attachInitialDeliveryCount(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.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.INVALID_FIELD)));
        final End endResponse = interaction.flowHandleFromLinkHandle().flowEcho(true).flow().consumeResponse().getLatestResponse(End.class);
        assertThat(endResponse.getError(), is(notNullValue()));
    // QPID-7954
    // assertThat(endResponse.getError().getCondition(), is(equalTo(SessionError.ERRANT_LINK)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InetSocketAddress(java.net.InetSocketAddress) 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) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) 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 19 with Detach

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

the class AttachTest method attachReceiverWithNullTarget.

@Test
@SpecificationTest(section = "2.6.3", description = "Note that if the application chooses not to create a terminus, the session endpoint will" + " still create a link endpoint and issue an attach indicating that the link endpoint has" + " no associated local terminus. In this case, the session endpoint MUST immediately" + " detach the newly created link endpoint.")
public void attachReceiverWithNullTarget() throws Exception {
    String queueName = "testQueue";
    getBrokerAdmin().createQueue(queueName);
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        Interaction interaction = transport.newInteraction();
        final Attach responseAttach = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(queueName).attachTarget(null).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.INVALID_FIELD)));
        final End endResponse = interaction.flowHandleFromLinkHandle().flowEcho(true).flow().consumeResponse().getLatestResponse(End.class);
        assertThat(endResponse.getError(), is(notNullValue()));
    // QPID-7954
    // assertThat(endResponse.getError().getCondition(), is(equalTo(SessionError.ERRANT_LINK)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InetSocketAddress(java.net.InetSocketAddress) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) 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 20 with Detach

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

the class AbstractLinkEndpoint method detach.

protected void detach(Error error, boolean close) {
    if (error != null && !getSession().isSyntheticError(error)) {
        _errored = true;
    }
    // TODO: QPID-7954: improve detach
    switch(_state) {
        case ATTACHED:
            _state = State.DETACH_SENT;
            break;
        case DETACH_RECVD:
            _state = State.DETACHED;
            break;
        default:
            // disassociate the link from the session so that the new connection can use it.
            if (close) {
                getSession().dissociateEndpoint(this);
                destroy();
                _link.linkClosed();
            }
            return;
    }
    if (getSession().getSessionState() != SessionState.END_RECVD && !getSession().isEnded()) {
        Detach detach = new Detach();
        detach.setHandle(getLocalHandle());
        if (close) {
            detach.setClosed(close);
        }
        detach.setError(error);
        getSession().sendDetach(detach);
    }
    if (close) {
        destroy();
        _link.linkClosed();
    }
    setLocalHandle(null);
}
Also used : Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach)

Aggregations

Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)27 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)27 Test (org.junit.Test)27 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)24 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)23 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)21 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)13 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)12 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)11 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)11 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)10 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)10 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)9 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)9 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)8 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)8 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)7 Ignore (org.junit.Ignore)7 HashMap (java.util.HashMap)5 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)4