Search in sources :

Example 1 with Role

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

the class Session_1_0Test method assertAttachActions.

private void assertAttachActions(final Queue<?> queue, final Attach receivedAttach) {
    Collection<QueueConsumer<?, ?>> consumers = queue.getConsumers();
    assertEquals("Unexpected consumers size", (long) 1, (long) consumers.size());
    ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
    verify(_connection).sendFrame(eq(_session.getChannelId()), frameCapture.capture());
    Attach sentAttach = (Attach) frameCapture.getValue();
    assertEquals("Unexpected name", receivedAttach.getName(), sentAttach.getName());
    assertEquals("Unexpected role", Role.SENDER, sentAttach.getRole());
    Source receivedSource = (Source) receivedAttach.getSource();
    Source sentSource = (Source) sentAttach.getSource();
    assertEquals("Unexpected source address", receivedSource.getAddress(), sentSource.getAddress());
    assertArrayEquals("Unexpected source capabilities", receivedSource.getCapabilities(), sentSource.getCapabilities());
    assertEquals("Unexpected source durability", receivedSource.getDurable(), sentSource.getDurable());
    assertEquals("Unexpected source expiry policy", receivedSource.getExpiryPolicy(), sentSource.getExpiryPolicy());
    assertEquals("Unexpected source dynamic flag", receivedSource.getDynamic(), sentSource.getDynamic());
    Target receivedTarget = (Target) receivedAttach.getTarget();
    Target sentTarget = (Target) sentAttach.getTarget();
    assertEquals("Unexpected target address", receivedTarget.getAddress(), sentTarget.getAddress());
    assertArrayEquals("Unexpected target capabilities", receivedTarget.getCapabilities(), sentTarget.getCapabilities());
    assertEquals("Unexpected target durability", receivedTarget.getDurable(), sentTarget.getDurable());
    assertEquals("Unexpected target expiry policy", receivedTarget.getExpiryPolicy(), sentTarget.getExpiryPolicy());
    assertEquals("Unexpected target dynamic flag", receivedTarget.getDynamic(), sentTarget.getDynamic());
    final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
    assertEquals("Unexpected number of queues after attach", (long) 1, (long) queues.size());
}
Also used : Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) QueueConsumer(org.apache.qpid.server.queue.QueueConsumer) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) FrameBody(org.apache.qpid.server.protocol.v1_0.type.FrameBody) Queue(org.apache.qpid.server.model.Queue) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source)

Example 2 with Role

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

the class Session_1_0Test method testNullSourceLookup.

@Test
public void testNullSourceLookup() throws Exception {
    final String linkName = "testLink";
    final String address = "amq.direct/" + TOPIC_NAME;
    Attach attach = createTopicAttach(true, linkName, address, false);
    _session.receiveAttach(attach);
    assertAttachSent(_connection, _session, attach);
    assertQueues(TOPIC_NAME, LifetimePolicy.PERMANENT);
    sendDetach(_session, attach.getHandle(), false);
    Attach nullSourceAttach = createTopicAttach(true, linkName, address, false);
    nullSourceAttach.setSource(null);
    _session.receiveAttach(nullSourceAttach);
    ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
    verify(_connection, times(3)).sendFrame(eq(_session.getChannelId()), frameCapture.capture());
    Attach sentAttach = (Attach) frameCapture.getAllValues().get(2);
    assertEquals("Unexpected name", nullSourceAttach.getName(), sentAttach.getName());
    assertEquals("Unexpected role", Role.SENDER, sentAttach.getRole());
    assertNotNull("Unexpected source", sentAttach.getSource());
    Source source = (Source) sentAttach.getSource();
    assertEquals("Unexpected address", address, source.getAddress());
    assertTrue("Unexpected source capabilities", Arrays.asList(source.getCapabilities()).contains(Symbol.valueOf("topic")));
    Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
    assertEquals("Unexpected number of queues after unsubscribe", (long) 1, (long) queues.size());
}
Also used : Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) FrameBody(org.apache.qpid.server.protocol.v1_0.type.FrameBody) Queue(org.apache.qpid.server.model.Queue) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) Test(org.junit.Test)

Example 3 with Role

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

the class Session_1_0Test method assertAttachFailed.

private void assertAttachFailed(final AMQPConnection_1_0 connection, final Session_1_0 session, final Attach attach, int invocationOffset) {
    ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
    verify(connection, times(invocationOffset + 2)).sendFrame(eq(session.getChannelId()), frameCapture.capture());
    List<FrameBody> sentFrames = frameCapture.getAllValues();
    final boolean condition1 = sentFrames.get(invocationOffset) instanceof Attach;
    assertTrue("unexpected Frame sent", condition1);
    Attach sentAttach = (Attach) sentFrames.get(invocationOffset);
    assertEquals("Unexpected name", attach.getName(), sentAttach.getName());
    assertEquals("Unexpected role", Role.SENDER, sentAttach.getRole());
    assertEquals("Unexpected source", null, sentAttach.getSource());
    final boolean condition = sentFrames.get(invocationOffset + 1) instanceof Detach;
    assertTrue("unexpected Frame sent", condition);
    Detach sentDetach = (Detach) sentFrames.get(invocationOffset + 1);
    assertTrue("Unexpected closed state", sentDetach.getClosed());
}
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 4 with Role

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

the class Session_1_0 method updateDisposition.

private void updateDisposition(final Role role, final UnsignedInteger first, final UnsignedInteger last, final DeliveryState state, final boolean settled) {
    Disposition disposition = new Disposition();
    disposition.setRole(role);
    disposition.setFirst(first);
    disposition.setLast(last);
    disposition.setSettled(settled);
    disposition.setState(state);
    if (settled) {
        final DeliveryRegistry deliveryRegistry = role == Role.RECEIVER ? _incomingDeliveryRegistry : _outgoingDeliveryRegistry;
        SequenceNumber pos = new SequenceNumber(first.intValue());
        SequenceNumber end = new SequenceNumber(last.intValue());
        while (pos.compareTo(end) <= 0) {
            deliveryRegistry.removeDelivery(UnsignedInteger.valueOf(pos.intValue()));
            pos.incr();
        }
    }
    send(disposition);
}
Also used : Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) DeliveryRegistry(org.apache.qpid.server.protocol.v1_0.delivery.DeliveryRegistry)

Example 5 with Role

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

the class Session_1_0 method updateDisposition.

void updateDisposition(final LinkEndpoint<?, ?> linkEndpoint, final Set<Binary> deliveryTags, final DeliveryState state, final boolean settled) {
    final Role role = linkEndpoint.getRole();
    final Iterator<UnsignedInteger> iterator = getDeliveryIds(deliveryTags, linkEndpoint).iterator();
    if (iterator.hasNext()) {
        UnsignedInteger begin = iterator.next();
        UnsignedInteger end = begin;
        while (iterator.hasNext()) {
            final UnsignedInteger deliveryId = iterator.next();
            if (!end.add(UnsignedInteger.ONE).equals(deliveryId)) {
                updateDisposition(role, begin, end, state, settled);
                begin = deliveryId;
                end = begin;
            } else {
                end = deliveryId;
            }
        }
        updateDisposition(role, begin, end, state, settled);
    }
}
Also used : Role(org.apache.qpid.server.protocol.v1_0.type.transport.Role) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Aggregations

Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)5 DeliveryRegistry (org.apache.qpid.server.protocol.v1_0.delivery.DeliveryRegistry)4 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 Role (org.apache.qpid.server.protocol.v1_0.type.transport.Role)4 FrameBody (org.apache.qpid.server.protocol.v1_0.type.FrameBody)3 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)3 Queue (org.apache.qpid.server.model.Queue)2 Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)2 StoreException (org.apache.qpid.server.store.StoreException)2 Test (org.junit.Test)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 Binding (org.apache.qpid.server.model.Binding)1 LinkDefinition (org.apache.qpid.server.protocol.v1_0.LinkDefinition)1 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)1 UnsettledDelivery (org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery)1 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)1