Search in sources :

Example 21 with QueueSession

use of org.mule.runtime.core.api.util.queue.QueueSession in project mule by mulesoft.

the class AbstractTransactionQueueManagerTestCase method testPutTakeUntake.

@Test
public void testPutTakeUntake() throws Exception {
    final QueueManager mgr = createQueueManager();
    mgr.start();
    final Latch latch = new Latch();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                latch.countDown();
                Thread.sleep(200);
                QueueSession s = mgr.getQueueSession();
                Queue q = s.getQueue("queue1");
                assertEquals("Queue size", 0, q.size());
                q.put("String1");
                q.put("String2");
            } catch (Exception e) {
            // ignore, let test fail
            }
        }
    };
    t.start();
    latch.await();
    long t0 = System.currentTimeMillis();
    QueueSession s = mgr.getQueueSession();
    Queue q = s.getQueue("queue1");
    assertEquals("Queue size", 0, q.size());
    Serializable o = q.take();
    long t1 = System.currentTimeMillis();
    t.join();
    assertNotNull(o);
    assertEquals("Queue content", "String1", o);
    assertEquals("Queue size", 1, q.size());
    assertTrue(t1 - t0 > 100);
    // Same as put/take until now, but now we do an untake
    q.untake(o);
    // Ensure queue size is now 2
    assertEquals("Queue size", 2, q.size());
    // Take to ensure order is correct
    Object o2 = q.take();
    assertEquals("Queue content", "String1", o2);
    assertEquals("Queue size", 1, q.size());
    mgr.stop();
}
Also used : Serializable(java.io.Serializable) Latch(org.mule.runtime.api.util.concurrent.Latch) Queue(org.mule.runtime.core.api.util.queue.Queue) QueueSession(org.mule.runtime.core.api.util.queue.QueueSession) QueueManager(org.mule.runtime.core.api.util.queue.QueueManager) AbstractQueueManager(org.mule.runtime.core.internal.util.queue.AbstractQueueManager) Test(org.junit.Test)

Example 22 with QueueSession

use of org.mule.runtime.core.api.util.queue.QueueSession in project mule by mulesoft.

the class QueueTestComponent method testDisposal.

public void testDisposal(QueueManager mgr, boolean transactional) throws Exception {
    final String queueName = "myQueue";
    mgr.start();
    QueueSession session = mgr.getQueueSession();
    if (transactional) {
        session.begin();
    }
    Queue queue = mgr.getQueueSession().getQueue(queueName);
    this.assertQueueDisposal(mgr, queue, transactional ? session : null, queueName);
}
Also used : Queue(org.mule.runtime.core.api.util.queue.Queue) QueueSession(org.mule.runtime.core.api.util.queue.QueueSession)

Aggregations

QueueSession (org.mule.runtime.core.api.util.queue.QueueSession)22 Test (org.junit.Test)20 Queue (org.mule.runtime.core.api.util.queue.Queue)20 AbstractQueueManager (org.mule.runtime.core.internal.util.queue.AbstractQueueManager)18 QueueManager (org.mule.runtime.core.api.util.queue.QueueManager)16 Latch (org.mule.runtime.api.util.concurrent.Latch)7 DefaultQueueConfiguration (org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration)5 Serializable (java.io.Serializable)2 Random (java.util.Random)2