Search in sources :

Example 11 with QueueManager

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

the class TransactionalQueueManagerTestCase method clearRecoveryQueuesAfterRecovery.

@Test
public void clearRecoveryQueuesAfterRecovery() throws Exception {
    createDanglingTx();
    QueueManager queueManager = muleContext.getQueueManager();
    QueueSession queueSession = queueManager.getQueueSession();
    queueSession.getQueue(TEST_QUEUE_NAME).dispose();
    queueManager.setQueueConfiguration(TEST_QUEUE_NAME, new DefaultQueueConfiguration());
    queueManager.start();
}
Also used : DefaultQueueConfiguration(org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration) QueueSession(org.mule.runtime.core.api.util.queue.QueueSession) QueueManager(org.mule.runtime.core.api.util.queue.QueueManager) Test(org.junit.Test)

Example 12 with QueueManager

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

the class DefaultsConfigurationBuilder method configureQueueManager.

protected void configureQueueManager(MuleContext muleContext) throws RegistrationException {
    QueueManager queueManager = new TransactionalQueueManager();
    registerObject(OBJECT_QUEUE_MANAGER, queueManager, muleContext);
    registerObject(LOCAL_QUEUE_MANAGER_KEY, queueManager, muleContext);
}
Also used : TransactionalQueueManager(org.mule.runtime.core.internal.util.queue.TransactionalQueueManager) TransactionalQueueManager(org.mule.runtime.core.internal.util.queue.TransactionalQueueManager) QueueManager(org.mule.runtime.core.api.util.queue.QueueManager)

Example 13 with QueueManager

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

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

Example 15 with QueueManager

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

the class AbstractTransactionQueueManagerTestCase method testRecoverWarmRestart.

@Test
public void testRecoverWarmRestart() throws Exception {
    QueueManager mgr = createQueueManager();
    mgr.start();
    QueueSession s = mgr.getQueueSession();
    Queue q = s.getQueue("warmRecoverQueue");
    int toPopulate = 50;
    // Populate queue
    Random rnd = new Random();
    for (int j = 0; j < toPopulate; j++) {
        byte[] o = new byte[2048];
        rnd.nextBytes(o);
        q.put(o);
    }
    assertEquals(q.size(), toPopulate);
    // Stop and start TransactionalQueueManager
    mgr.stop();
    mgr.start();
    assertEquals(toPopulate, q.size());
}
Also used : Random(java.util.Random) 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

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