Search in sources :

Example 16 with QueueManager

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

the class AbstractTransactionQueueManagerTestCase method testClearInTransaction.

@Test
public void testClearInTransaction() throws Exception {
    final QueueManager mgr = createQueueManager();
    mgr.start();
    QueueSession s = mgr.getQueueSession();
    // insert item in transaction
    s.begin();
    Queue q = s.getQueue("queue1");
    assertEquals("Queue size", 0, q.size());
    q.put("String1");
    s.commit();
    assertEquals("Queue size", 1, q.size());
    // clear queue but rollback
    s.begin();
    assertEquals("Queue size", 1, q.size());
    q.clear();
    s.rollback();
    assertEquals("Queue size", 1, q.size());
    // do clear in transaction
    s.begin();
    assertEquals("Queue size", 1, q.size());
    q.clear();
    s.commit();
    assertEquals("Queue size", 0, q.size());
    mgr.stop();
}
Also used : 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 17 with QueueManager

use of org.mule.runtime.core.api.util.queue.QueueManager 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 18 with QueueManager

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

the class MuleContextLifecycleTestCase method buildStartedMuleContext.

private MuleContext buildStartedMuleContext() throws Exception {
    ctx.initialise();
    // DefaultMuleContext refuses to start without these objects in place
    SecurityManager securityManager = mock(SecurityManager.class);
    ((MuleContextWithRegistries) ctx).getRegistry().registerObject(UUID.getUUID(), securityManager);
    QueueManager queueManager = mock(QueueManager.class);
    ((MuleContextWithRegistries) ctx).getRegistry().registerObject(UUID.getUUID(), queueManager);
    ctx.start();
    return ctx;
}
Also used : SecurityManager(org.mule.runtime.core.api.security.SecurityManager) QueueManager(org.mule.runtime.core.api.util.queue.QueueManager)

Aggregations

QueueManager (org.mule.runtime.core.api.util.queue.QueueManager)18 QueueSession (org.mule.runtime.core.api.util.queue.QueueSession)16 Test (org.junit.Test)15 Queue (org.mule.runtime.core.api.util.queue.Queue)14 AbstractQueueManager (org.mule.runtime.core.internal.util.queue.AbstractQueueManager)13 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 SecurityManager (org.mule.runtime.core.api.security.SecurityManager)1 TransactionalQueueManager (org.mule.runtime.core.internal.util.queue.TransactionalQueueManager)1