Search in sources :

Example 71 with Attach

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

the class Session_1_0Test method testLinkStealing.

public void testLinkStealing() {
    _virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, QUEUE_NAME));
    Attach attach = createQueueAttach(true, getTestName(), QUEUE_NAME);
    AMQPConnection_1_0 connection1 = _connection;
    Session_1_0 session1 = _session;
    session1.receiveAttach(attach);
    Link_1_0<?, ?> link = _virtualHost.getSendingLink(connection1.getRemoteContainerId(), attach.getName());
    assertNotNull("Link is not created", link);
    assertAttachSent(connection1, session1, attach);
    AMQPConnection_1_0 connection2 = createAmqpConnection_1_0(connection1.getRemoteContainerId());
    Session_1_0 session2 = createSession_1_0(connection2, 0);
    session2.receiveAttach(attach);
    assertDetachSent(connection1, session1, LinkError.STOLEN, 1);
    assertAttachSent(connection2, session2, attach);
}
Also used : Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach)

Example 72 with Attach

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

the class Session_1_0Test method testReceiveAttachForInvalidUnsubscribe.

public void testReceiveAttachForInvalidUnsubscribe() throws Exception {
    final String linkName = "testLink";
    final String address = "amq.direct/" + TOPIC_NAME;
    Attach unsubscribeAttach = createTopicAttach(true, linkName, address, false);
    unsubscribeAttach.setSource(null);
    _session.receiveAttach(unsubscribeAttach);
    assertAttachFailed(_connection, _session, unsubscribeAttach);
    Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
    assertEquals("Unexpected number of queues after unsubscribe", 0, queues.size());
}
Also used : Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Queue(org.apache.qpid.server.model.Queue)

Example 73 with Attach

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

the class Session_1_0Test method testReceiveReattachRebindingQueueNoActiveLinks.

public void testReceiveReattachRebindingQueueNoActiveLinks() {
    final String linkName = "testLink";
    final String address = "amq.direct/" + TOPIC_NAME;
    Attach attach = createSharedTopicAttach(true, linkName, address, true);
    _session.receiveAttach(attach);
    assertAttachSent(_connection, _session, attach);
    assertQueues(TOPIC_NAME, LifetimePolicy.PERMANENT);
    sendDetach(_session, attach.getHandle(), false);
    ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
    verify(_connection, times(2)).sendFrame(eq(_session.getChannelId()), frameCapture.capture());
    assertTrue(frameCapture.getAllValues().get(1) instanceof Detach);
    assertQueues(TOPIC_NAME, LifetimePolicy.PERMANENT);
    String topicName2 = TOPIC_NAME + "2";
    final String address2 = "amq.direct/" + topicName2;
    Attach attach2 = createSharedTopicAttach(true, linkName, address2, true);
    _session.receiveAttach(attach2);
    assertAttachSent(_connection, _session, attach2, 2);
    assertQueues(topicName2, LifetimePolicy.PERMANENT);
}
Also used : Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) FrameBody(org.apache.qpid.server.protocol.v1_0.type.FrameBody) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach)

Example 74 with Attach

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

the class Session_1_0Test method testReceiveAttachSharedTopicNonDurableWithContainer.

public void testReceiveAttachSharedTopicNonDurableWithContainer() throws Exception {
    final String linkName = "testLink";
    final String address = "amq.direct/" + TOPIC_NAME;
    Attach attach = createSharedTopicAttach(false, linkName, address, false);
    Attach attach2 = createSharedTopicAttach(false, linkName, address, false);
    _session.receiveAttach(attach);
    assertAttachSent(_connection, _session, attach);
    assertQueues(TOPIC_NAME, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
    AMQPConnection_1_0 secondConnection = createAmqpConnection_1_0("testContainerId2");
    Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
    secondSession.receiveAttach(attach2);
    assertAttachSent(secondConnection, secondSession, attach2);
    final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
    assertEquals("Unexpected number of queues after attach", 2, queues.size());
    for (Queue<?> queue : queues) {
        Collection<QueueConsumer<?, ?>> consumers = queue.getConsumers();
        assertEquals("Unexpected number of consumers on queue " + queue.getName(), 1, consumers.size());
    }
}
Also used : QueueConsumer(org.apache.qpid.server.queue.QueueConsumer) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Queue(org.apache.qpid.server.model.Queue)

Example 75 with Attach

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

the class SendingLinkEndpoint method reattachLink.

@Override
protected void reattachLink(final Attach attach) throws AmqpErrorException {
    if (getSource() == null) {
        throw new IllegalStateException("Terminus should be set when resuming a Link.");
    }
    if (attach.getSource() == null) {
        throw new IllegalStateException("Attach.getSource should not be null when resuming a Link. That would be recovering the Link.");
    }
    Source newSource = (Source) attach.getSource();
    Source oldSource = getSource();
    final SendingDestination destination = getSession().getSendingDestination(getLink(), oldSource);
    prepareConsumerOptionsAndFilters(destination);
    if (getDestination() instanceof ExchangeSendingDestination && !Boolean.TRUE.equals(newSource.getDynamic())) {
        final SendingDestination newDestination = getSession().getSendingDestination(getLink(), newSource);
        if (getSession().updateSourceForSubscription(this, newSource, newDestination)) {
            setDestination(newDestination);
        }
    }
    attachReceived(attach);
}
Also used : MessageSource(org.apache.qpid.server.message.MessageSource) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source)

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