Search in sources :

Example 1 with AbstractQueueManager

use of org.mule.runtime.core.internal.util.queue.AbstractQueueManager in project mule by mulesoft.

the class AbstractTransactionQueueManagerTestCase method testTransactionsOnMultipleQueues.

@Test
public void testTransactionsOnMultipleQueues() throws Exception {
    AbstractQueueManager mgr = createQueueManager();
    try {
        mgr.start();
        QueueSession s1 = mgr.getQueueSession();
        QueueSession s2 = mgr.getQueueSession();
        Queue q1s1 = s1.getQueue("queue1");
        Queue q1s2 = s2.getQueue("queue1");
        Queue q2s1 = s1.getQueue("queue2");
        Queue q2s2 = s2.getQueue("queue2");
        q1s1.put("String1");
        assertEquals("Queue size", 1, q1s1.size());
        assertEquals("Queue size", 1, q1s2.size());
        s1.begin();
        Object o = q1s1.take();
        assertNotNull(o);
        assertEquals("String1", o);
        assertEquals("Queue size", 0, q1s1.size());
        assertEquals("Queue size", 0, q1s2.size());
        q2s1.put("String2");
        assertEquals("Queue size", 1, q2s1.size());
        assertEquals("Queue size", 0, q2s2.size());
        s1.commit();
        assertEquals("Queue size", 0, q1s1.size());
        assertEquals("Queue size", 0, q1s2.size());
        assertEquals("Queue size", 1, q2s1.size());
        assertEquals("Queue size", 1, q2s2.size());
        s1.begin();
        o = q2s1.take();
        assertNotNull(o);
        assertEquals("String2", o);
        assertEquals("Queue size", 0, q1s1.size());
        assertEquals("Queue size", 0, q1s2.size());
        assertEquals("Queue size", 0, q2s1.size());
        assertEquals("Queue size", 0, q2s2.size());
        q1s1.put("String1");
        assertEquals("Queue size", 1, q1s1.size());
        assertEquals("Queue size", 0, q1s2.size());
        assertEquals("Queue size", 0, q2s1.size());
        assertEquals("Queue size", 0, q2s2.size());
        s1.rollback();
        assertEquals("Queue size", 0, q1s1.size());
        assertEquals("Queue size", 0, q1s2.size());
        assertEquals("Queue size", 1, q2s1.size());
        assertEquals("Queue size", 1, q2s2.size());
    } finally {
        mgr.stop();
        mgr.dispose();
    }
}
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 2 with AbstractQueueManager

use of org.mule.runtime.core.internal.util.queue.AbstractQueueManager in project mule by mulesoft.

the class AbstractTransactionQueueManagerTestCase method testTransactedPutRollbackWithPersistence.

@Test
public void testTransactedPutRollbackWithPersistence() throws Exception {
    if (isPersistent()) {
        AbstractQueueManager mgr = createQueueManager();
        try {
            mgr.start();
            QueueSession s = mgr.getQueueSession();
            Queue q = s.getQueue("queue1");
            s.begin();
            q.put("String1");
            assertEquals("Queue size", 1, q.size());
            s.rollback();
            assertEquals("Queue size", 0, q.size());
            s = mgr.getQueueSession();
            q = s.getQueue("queue1");
            assertEquals("Queue size", 0, q.size());
            mgr.stop();
            mgr = createQueueManager();
            mgr.start();
            s = mgr.getQueueSession();
            q = s.getQueue("queue1");
            assertEquals("Queue size", 0, 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 3 with AbstractQueueManager

use of org.mule.runtime.core.internal.util.queue.AbstractQueueManager 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 4 with AbstractQueueManager

use of org.mule.runtime.core.internal.util.queue.AbstractQueueManager in project mule by mulesoft.

the class AbstractTransactionQueueManagerTestCase method testTransactedPutCommitWithPersistence.

@Test
public void testTransactedPutCommitWithPersistence() throws Exception {
    if (isPersistent()) {
        AbstractQueueManager mgr = createQueueManager();
        try {
            QueueSession s = mgr.getQueueSession();
            Queue q = s.getQueue("queue1");
            mgr.start();
            s.begin();
            q.put("String1");
            assertEquals("Queue size", 1, q.size());
            s.commit();
            assertEquals("Queue size", 1, q.size());
            s = mgr.getQueueSession();
            q = s.getQueue("queue1");
            assertEquals("Queue size", 1, q.size());
            mgr.stop();
            mgr = createQueueManager();
            s = mgr.getQueueSession();
            q = s.getQueue("queue1");
            mgr.start();
            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 5 with AbstractQueueManager

use of org.mule.runtime.core.internal.util.queue.AbstractQueueManager in project mule by mulesoft.

the class AbstractTransactionQueueManagerTestCase method testPutTake_RespectsOrderOnPersistence.

@Test
public void testPutTake_RespectsOrderOnPersistence() throws Exception {
    if (isPersistent()) {
        AbstractQueueManager mgr1 = createQueueManager();
        QueueSession s1 = mgr1.getQueueSession();
        Queue q1 = s1.getQueue("queue1");
        mgr1.start();
        assertEquals("Queue size", 0, q1.size());
        final int numberOfElements = 10;
        for (int i = 1; i <= numberOfElements; i++) {
            q1.put("String" + i);
            assertEquals("Queue size", i, q1.size());
        }
        mgr1.stop();
        AbstractQueueManager mgr2 = createQueueManager();
        QueueSession s2 = mgr2.getQueueSession();
        Queue q2 = s2.getQueue("queue1");
        mgr2.start();
        for (int i = 1; i <= numberOfElements; i++) {
            Object o = q2.take();
            assertNotNull(o);
            assertEquals("Queue content", "String" + i, o);
        }
        assertEquals("Queue size", 0, q2.size());
        mgr2.stop();
        mgr2.dispose();
    }
}
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)

Aggregations

Test (org.junit.Test)5 Queue (org.mule.runtime.core.api.util.queue.Queue)5 QueueSession (org.mule.runtime.core.api.util.queue.QueueSession)5 AbstractQueueManager (org.mule.runtime.core.internal.util.queue.AbstractQueueManager)5