Java Code Examples for javax.jms.JMSContext#AUTO_ACKNOWLEDGE

The following examples show how to use javax.jms.JMSContext#AUTO_ACKNOWLEDGE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateConsumer() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createConsumer(any(Destination.class));

    try {
        context.createConsumer(context.createTemporaryQueue());
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createConsumer(any(Destination.class));
}
 
Example 2
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoStartOffDoesNotStartTheConnectionSharedDurableMessageConsumer() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer consumer = Mockito.mock(JmsMessageConsumer.class);

    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    Mockito.when(session.createSharedDurableConsumer(any(Topic.class), anyString())).thenReturn(consumer);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());

    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);
    context.setAutoStart(false);

    try {
        context.createSharedDurableConsumer(context.createTemporaryTopic(), "name");
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createSharedDurableConsumer(any(Topic.class), anyString());
    Mockito.verify(connection, Mockito.times(0)).start();
}
 
Example 3
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoStartOffDoesNotStartTheConnectionSharedDurableMessageConsumerSelector() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer consumer = Mockito.mock(JmsMessageConsumer.class);

    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    Mockito.when(session.createSharedDurableConsumer(any(Topic.class), anyString(), anyString())).thenReturn(consumer);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());

    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);
    context.setAutoStart(false);

    try {
        context.createSharedDurableConsumer(context.createTemporaryTopic(), "name", "a = b");
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createSharedDurableConsumer(any(Topic.class), anyString(), anyString());
    Mockito.verify(connection, Mockito.times(0)).start();
}
 
Example 4
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoStartOnDoesStartTheConnectionSharedMessageConsumer() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer consumer = Mockito.mock(JmsMessageConsumer.class);

    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    Mockito.when(session.createSharedConsumer(any(Topic.class), anyString())).thenReturn(consumer);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());

    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);
    context.setAutoStart(true);

    try {
        context.createSharedConsumer(context.createTemporaryTopic(), "name");
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createSharedConsumer(any(Topic.class), anyString());
    Mockito.verify(connection, Mockito.times(1)).start();
}
 
Example 5
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoStartOffDoesNotStartTheConnectionDurableMessageConsumerSelectorNoLocal() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer consumer = Mockito.mock(JmsMessageConsumer.class);

    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    Mockito.when(session.createDurableConsumer(any(Topic.class), anyString(), anyString(), anyBoolean())).thenReturn(consumer);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());

    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);
    context.setAutoStart(false);

    try {
        context.createDurableConsumer(context.createTemporaryTopic(), "name", "a = b", true);
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createDurableConsumer(any(Topic.class), anyString(), anyString(), anyBoolean());
    Mockito.verify(connection, Mockito.times(0)).start();
}
 
Example 6
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateQueueBrowser() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createBrowser(any(Queue.class));

    try {
        context.createBrowser(context.createTemporaryQueue());
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createBrowser(any(Queue.class));
}
 
Example 7
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateConsumerWithSelector() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createConsumer(any(Destination.class), anyString());

    try {
        context.createConsumer(context.createTemporaryQueue(), "a = b");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createConsumer(any(Destination.class), anyString());
}
 
Example 8
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoStartOffDoesNotStartTheConnectionMessageConsumerSelectorNoLocal() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer consumer = Mockito.mock(JmsMessageConsumer.class);

    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());
    Mockito.when(session.createConsumer(any(Destination.class), anyString(), anyBoolean())).thenReturn(consumer);

    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);
    context.setAutoStart(false);

    try {
        context.createConsumer(context.createTemporaryTopic(), "a = b", true);
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createConsumer(any(Topic.class), anyString(), anyBoolean());
    Mockito.verify(connection, Mockito.times(0)).start();
}
 
Example 9
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateSharedConsumer() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createSharedConsumer(any(Topic.class), anyString());

    try {
        context.createSharedConsumer(context.createTemporaryTopic(), "name");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createSharedConsumer(any(Topic.class), anyString());
}
 
Example 10
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoStartOnDoesStartTheConnectionQueueBrowser() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsQueueBrowser browser = Mockito.mock(JmsQueueBrowser.class);

    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(session.createBrowser(any(Queue.class))).thenReturn(browser);

    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);
    context.setAutoStart(true);

    try {
        context.createBrowser(context.createTemporaryQueue());
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createBrowser(any(Queue.class));
    Mockito.verify(connection, Mockito.times(1)).start();
}
 
Example 11
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateDurableConsumerSelectorNoLocal() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).
        createDurableConsumer(any(Topic.class), anyString(), anyString(), anyBoolean());

    try {
        context.createDurableConsumer(context.createTemporaryTopic(), "name", "a = b", true);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createDurableConsumer(any(Topic.class), anyString(), anyString(), anyBoolean());
}
 
Example 12
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoStartOnDoesStartTheConnectionSharedDurableMessageConsumer() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer consumer = Mockito.mock(JmsMessageConsumer.class);

    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    Mockito.when(session.createSharedDurableConsumer(any(Topic.class), anyString())).thenReturn(consumer);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());

    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);
    context.setAutoStart(true);

    try {
        context.createSharedDurableConsumer(context.createTemporaryTopic(), "name");
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createSharedDurableConsumer(any(Topic.class), anyString());
    Mockito.verify(connection, Mockito.times(1)).start();
}
 
Example 13
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateQueueBrowserWithSelector() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createBrowser(any(Queue.class), anyString());

    try {
        context.createBrowser(context.createTemporaryQueue(), "a == b");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createBrowser(any(Queue.class), anyString());
}
 
Example 14
Source File: TomEEConnectionFactory.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public JMSContext createContext() {
    boolean inTx = JMS2.inTx();
    int mode;
    if (inTx) {
        mode = -1;
    } else {
        mode = JMSContext.AUTO_ACKNOWLEDGE;
    }
    return new JMSContextImpl(this, mode, null, null, inTx);
}
 
Example 15
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetClientIDPassthrough() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    try {
        context.setClientID("test");
    } finally {
        context.close();
    }

    Mockito.verify(connection, Mockito.times(1)).setClientID("test");
}
 
Example 16
Source File: JmsSession.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
static void validateSessionMode(int mode) {
    switch (mode) {
        case JMSContext.AUTO_ACKNOWLEDGE:
        case JMSContext.CLIENT_ACKNOWLEDGE:
        case JMSContext.DUPS_OK_ACKNOWLEDGE:
        case JMSContext.SESSION_TRANSACTED:
        case INDIVIDUAL_ACKNOWLEDGE:
        case ARTEMIS_PRE_ACKNOWLEDGE:
        case NO_ACKNOWLEDGE:
            return;
        default:
            throw new JMSRuntimeException("Invalid Session Mode: " + mode);
    }
}
 
Example 17
Source File: TomEERAConnectionFactory.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public JMSContext createContext() {
    // See notes here. We _do_ allow the user to override session mode at the
    // connectionFactory level, otherwise we follow the spec.
    // https://docs.oracle.com/javaee/7/api/javax/jms/ConnectionFactory.html#createContext-int-
    int mode;
    boolean xa;
    switch (transactionSupportLevel) {
        case XATransaction:
            if (JMS2.inTx()) {
                mode = -1;
                xa = true;
                break;
            }
        case NoTransaction:
            mode = JMSContext.AUTO_ACKNOWLEDGE;
            xa = false;
            break;
        case LocalTransaction:
            mode = JMSContext.SESSION_TRANSACTED;
            xa = false;
            break;
        default:
            throw new IllegalStateException("transactionSupportLevel mode not supported:" + transactionSupportLevel);
    }
    return new JMSContextImpl(this, mode, null, null, xa);
}
 
Example 18
Source File: JmsPoolJMSContext.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
private void validateSessionMode(int mode) {
    switch (mode) {
        case JMSContext.SESSION_TRANSACTED:
        case JMSContext.AUTO_ACKNOWLEDGE:
        case JMSContext.CLIENT_ACKNOWLEDGE:
        case JMSContext.DUPS_OK_ACKNOWLEDGE:
            return;
        default:
            throw new JMSRuntimeException("Invalid Session Mode: " + mode);
    }
}
 
Example 19
Source File: JmsConnectionTestSupport.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
protected JmsContext createJMSContextToMockProvider() throws Exception {
    JmsConnection connection = new JmsConnection(connectionInfo, createMockProvider());
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    return context;
}
 
Example 20
Source File: JMSConsumerIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public void doTestReceiveBodyFailsThenCalledWithCorrectType(int sessionMode) throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JMSContext context = testFixture.createJMSContext(testPeer);

        testPeer.expectBegin();

        final String content = "Message-Content";
        Queue queue = context.createQueue("myQueue");

        DescribedType amqpValueContent = new AmqpValueDescribedType(content);

        testPeer.expectReceiverAttach();
        testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueContent);

        JMSConsumer messageConsumer = context.createConsumer(queue);
        try {
            messageConsumer.receiveBody(Boolean.class, 3000);
            fail("Should not read as Boolean type");
        } catch (MessageFormatRuntimeException mfre) {
        }

        testPeer.waitForAllHandlersToComplete(3000);

        if (sessionMode == JMSContext.AUTO_ACKNOWLEDGE ||
            sessionMode == JMSContext.DUPS_OK_ACKNOWLEDGE) {

            testPeer.expectDispositionThatIsAcceptedAndSettled();
        }

        String received = messageConsumer.receiveBody(String.class, 3000);

        if (sessionMode == JMSContext.AUTO_ACKNOWLEDGE ||
            sessionMode == JMSContext.DUPS_OK_ACKNOWLEDGE) {

            assertNotNull(received);
            assertEquals(content, received);
        } else {
            assertNull(received);
        }

        testPeer.expectEnd();
        testPeer.expectClose();

        context.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}