Search in sources :

Example 1 with QueueConsumer

use of org.apache.qpid.server.queue.QueueConsumer 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 QueueConsumer

use of org.apache.qpid.server.queue.QueueConsumer in project qpid-broker-j by apache.

the class LegacyAccessControlAdapterTest method testAuthoriseCreateConsumer.

@Test
public void testAuthoriseCreateConsumer() {
    Queue queue = mock(Queue.class);
    when(queue.getParent()).thenReturn(_virtualHost);
    when(queue.getAttribute(Queue.NAME)).thenReturn(TEST_QUEUE);
    when(queue.getAttribute(Queue.DURABLE)).thenReturn(true);
    when(queue.getAttribute(Queue.LIFETIME_POLICY)).thenReturn(LifetimePolicy.PERMANENT);
    when(queue.getAttribute(Queue.EXCLUSIVE)).thenReturn(ExclusivityPolicy.NONE);
    when(queue.getAttribute(Queue.CREATED_BY)).thenReturn(TEST_USER);
    when(queue.getCategoryClass()).thenReturn(Queue.class);
    Session session = mock(Session.class);
    when(session.getCategoryClass()).thenReturn(Session.class);
    when(session.getAttribute(Session.NAME)).thenReturn("1");
    QueueConsumer consumer = mock(QueueConsumer.class);
    when(consumer.getAttribute(QueueConsumer.NAME)).thenReturn("1");
    when(consumer.getParent()).thenReturn(queue);
    when(consumer.getCategoryClass()).thenReturn(Consumer.class);
    ObjectProperties properties = new ObjectProperties();
    properties.put(Property.NAME, TEST_QUEUE);
    properties.put(Property.VIRTUALHOST_NAME, TEST_VIRTUAL_HOST);
    properties.put(Property.AUTO_DELETE, false);
    properties.put(Property.TEMPORARY, false);
    properties.put(Property.DURABLE, true);
    properties.put(Property.EXCLUSIVE, false);
    properties.put(Property.CREATED_BY, TEST_USER);
    assertAuthorization(LegacyOperation.CREATE, consumer, LegacyOperation.CONSUME, ObjectType.QUEUE, properties, Collections.emptyMap());
}
Also used : QueueConsumer(org.apache.qpid.server.queue.QueueConsumer) Test(org.junit.Test)

Example 3 with QueueConsumer

use of org.apache.qpid.server.queue.QueueConsumer in project qpid-broker-j by apache.

the class Session_1_0Test method testReceiveAttachSharedTopicNonDurableNoContainer.

@Test
public void testReceiveAttachSharedTopicNonDurableNoContainer() throws Exception {
    final String linkName = "testLink";
    final String address = "amq.direct/" + TOPIC_NAME;
    Attach attach = createSharedTopicAttach(false, linkName, address, true);
    Attach attach2 = createSharedTopicAttach(false, linkName, address, true);
    _session.receiveAttach(attach);
    assertAttachSent(_connection, _session, attach);
    assertQueues(TOPIC_NAME, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
    AMQPConnection_1_0 secondConnection = createAmqpConnection_1_0();
    Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
    secondSession.receiveAttach(attach2);
    assertAttachSent(secondConnection, secondSession, attach2);
    assertQueues(TOPIC_NAME, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
    final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
    assertEquals("Unexpected number of queues after attach", (long) 1, (long) queues.size());
    Queue<?> queue = queues.iterator().next();
    Collection<QueueConsumer<?, ?>> consumers = queue.getConsumers();
    assertEquals("Unexpected number of consumers", (long) 2, (long) 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) Test(org.junit.Test)

Example 4 with QueueConsumer

use of org.apache.qpid.server.queue.QueueConsumer in project qpid-broker-j by apache.

the class Session_1_0Test method testReceiveAttachSharedTopicNonDurableWithContainer.

@Test
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", (long) 2, (long) queues.size());
    for (Queue<?> queue : queues) {
        Collection<QueueConsumer<?, ?>> consumers = queue.getConsumers();
        assertEquals("Unexpected number of consumers on queue " + queue.getName(), (long) 1, (long) 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) Test(org.junit.Test)

Aggregations

QueueConsumer (org.apache.qpid.server.queue.QueueConsumer)4 Queue (org.apache.qpid.server.model.Queue)3 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)3 Test (org.junit.Test)3 FrameBody (org.apache.qpid.server.protocol.v1_0.type.FrameBody)1 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)1 Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)1