Search in sources :

Example 11 with Queue

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

the class QueueTestComponent method assertQueueDisposal.

private void assertQueueDisposal(QueueManager mgr, Queue queue, QueueSession session, String queueName) throws Exception {
    queue.put("some value");
    assertEquals(1, queue.size());
    if (session != null) {
        session.commit();
    }
    queue.dispose();
    Queue queue2 = mgr.getQueueSession().getQueue(queueName);
    assertNotSame(queue, queue2);
    assertEquals(0, queue2.size());
}
Also used : Queue(org.mule.runtime.core.api.util.queue.Queue)

Example 12 with Queue

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

the class TransactionalQueueManagerTestCase method allowChangingConfigurationOnDisposedQueue.

@Test
public void allowChangingConfigurationOnDisposedQueue() throws Exception {
    QueueManager queueManager = muleContext.getQueueManager();
    queueManager.setQueueConfiguration(TEST_QUEUE_NAME, new DefaultQueueConfiguration(0, true));
    QueueSession queueSession = queueManager.getQueueSession();
    Queue queue = queueSession.getQueue(TEST_QUEUE_NAME);
    queue.dispose();
    queueManager.setQueueConfiguration(TEST_QUEUE_NAME, new DefaultQueueConfiguration(0, false));
}
Also used : DefaultQueueConfiguration(org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration) 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) Test(org.junit.Test)

Example 13 with Queue

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

the class AbstractTransactionQueueManagerTestCase method testPutWithPersistence.

@Test
public void testPutWithPersistence() throws Exception {
    if (isPersistent()) {
        AbstractQueueManager mgr = createQueueManager();
        try {
            QueueSession s = mgr.getQueueSession();
            mgr.start();
            Queue q = s.getQueue("queue1");
            q.put("String1");
            assertEquals("Queue size", 1, q.size());
            q = s.getQueue("queue1");
            assertEquals("Queue size", 1, q.size());
        } finally {
            mgr.stop();
            mgr.dispose();
        }
        mgr = createQueueManager();
        try {
            QueueSession s = mgr.getQueueSession();
            mgr.start();
            Queue q = s.getQueue("queue1");
            assertEquals("Queue size", 1, q.size());
        } finally {
            mgr.stop();
            mgr.dispose();
        }
    } else {
        logger.info("Ignoring test because queue manager is not persistent");
    }
}
Also used : Queue(org.mule.runtime.core.api.util.queue.Queue) QueueSession(org.mule.runtime.core.api.util.queue.QueueSession) AbstractQueueManager(org.mule.runtime.core.internal.util.queue.AbstractQueueManager) Test(org.junit.Test)

Example 14 with Queue

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

the class AbstractTransactionQueueManagerTestCase method testTakePutRollbackPut.

@Test
public void testTakePutRollbackPut() 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());
                s.begin();
                q.put("String1");
                s.rollback();
                s.begin();
                q.put("String2");
                s.commit();
            } 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());
    Object o = q.take();
    long t1 = System.currentTimeMillis();
    t.join();
    assertNotNull(o);
    assertEquals("Queue content", "String2", o);
    assertEquals("Queue size", 0, q.size());
    assertTrue(t1 - t0 > 100);
    mgr.stop();
}
Also used : 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 15 with Queue

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

the class AbstractTransactionQueueManagerTestCase method testPutTakeUntakeRollbackUntake.

@Test
public void testPutTakeUntakeRollbackUntake() throws Exception {
    final QueueManager mgr = createQueueManager();
    mgr.start();
    final Latch latch = new Latch();
    final Serializable object1 = "string1";
    final Serializable object2 = "string2";
    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());
                s.begin();
                q.untake(object1);
                s.commit();
                s.begin();
                q.untake(object2);
                s.rollback();
            } 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());
    Object o = q.take();
    long t1 = System.currentTimeMillis();
    t.join();
    assertNotNull(o);
    assertEquals("Queue content", object1, o);
    assertEquals("Queue size", 0, q.size());
    assertTrue(t1 - t0 > 100);
    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)

Aggregations

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