Search in sources :

Example 1 with JmsDefaultPrefetchPolicy

use of org.apache.qpid.jms.policy.JmsDefaultPrefetchPolicy in project activemq-artemis by apache.

the class JMSMessageConsumerTest method testZeroPrefetchWithTwoConsumers.

@Test(timeout = 60000)
public void testZeroPrefetchWithTwoConsumers() throws Exception {
    JmsConnection connection = (JmsConnection) createConnection();
    ((JmsDefaultPrefetchPolicy) connection.getPrefetchPolicy()).setAll(0);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    javax.jms.Queue queue = session.createQueue(getQueueName());
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Msg1"));
    producer.send(session.createTextMessage("Msg2"));
    // now lets receive it
    MessageConsumer consumer1 = session.createConsumer(queue);
    MessageConsumer consumer2 = session.createConsumer(queue);
    TextMessage answer = (TextMessage) consumer1.receive(5000);
    assertNotNull(answer);
    assertEquals("Should have received a message!", answer.getText(), "Msg1");
    answer = (TextMessage) consumer2.receive(5000);
    assertNotNull(answer);
    assertEquals("Should have received a message!", answer.getText(), "Msg2");
    answer = (TextMessage) consumer2.receiveNoWait();
    assertNull("Should have not received a message!", answer);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) JmsDefaultPrefetchPolicy(org.apache.qpid.jms.policy.JmsDefaultPrefetchPolicy) JmsConnection(org.apache.qpid.jms.JmsConnection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 2 with JmsDefaultPrefetchPolicy

use of org.apache.qpid.jms.policy.JmsDefaultPrefetchPolicy in project activemq-artemis by apache.

the class JMSQueueBrowserTest method testBrowseAllInQueueZeroPrefetch.

@Test(timeout = 60000)
public void testBrowseAllInQueueZeroPrefetch() throws Exception {
    final int MSG_COUNT = 5;
    JmsConnection connection = (JmsConnection) createConnection();
    ((JmsDefaultPrefetchPolicy) connection.getPrefetchPolicy()).setAll(0);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    javax.jms.Queue queue = session.createQueue(getQueueName());
    sendMessages(name.getMethodName(), MSG_COUNT, false);
    Queue queueView = getProxyToQueue(getQueueName());
    Wait.assertEquals(MSG_COUNT, queueView::getMessageCount);
    QueueBrowser browser = session.createBrowser(queue);
    assertNotNull(browser);
    Enumeration<?> enumeration = browser.getEnumeration();
    int count = 0;
    while (count < MSG_COUNT && enumeration.hasMoreElements()) {
        Message msg = (Message) enumeration.nextElement();
        assertNotNull(msg);
        LOG.debug("Recv: {}", msg);
        count++;
    }
    LOG.debug("Received all expected message, checking that hasMoreElements returns false");
    assertFalse(enumeration.hasMoreElements());
    assertEquals(5, count);
}
Also used : JmsDefaultPrefetchPolicy(org.apache.qpid.jms.policy.JmsDefaultPrefetchPolicy) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) JmsConnection(org.apache.qpid.jms.JmsConnection) Queue(org.apache.activemq.artemis.core.server.Queue) QueueBrowser(javax.jms.QueueBrowser) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

Session (javax.jms.Session)2 TextMessage (javax.jms.TextMessage)2 JmsConnection (org.apache.qpid.jms.JmsConnection)2 JmsDefaultPrefetchPolicy (org.apache.qpid.jms.policy.JmsDefaultPrefetchPolicy)2 Test (org.junit.Test)2 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageProducer (javax.jms.MessageProducer)1 QueueBrowser (javax.jms.QueueBrowser)1 Queue (org.apache.activemq.artemis.core.server.Queue)1