Java Code Examples for javax.jms.JMSContext#CLIENT_ACKNOWLEDGE

The following examples show how to use javax.jms.JMSContext#CLIENT_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: JmsConnector.java    From smallrye-reactive-messaging with Apache License 2.0 7 votes vote down vote up
private JMSContext createContext(ConnectionFactory factory, String username, String password, String mode) {
    int sessionMode;
    switch (mode.toUpperCase()) {
        case "AUTO_ACKNOWLEDGE":
            sessionMode = JMSContext.AUTO_ACKNOWLEDGE;
            break;
        case "SESSION_TRANSACTED":
            sessionMode = JMSContext.SESSION_TRANSACTED;
            break;
        case "CLIENT_ACKNOWLEDGE":
            sessionMode = JMSContext.CLIENT_ACKNOWLEDGE;
            break;
        case "DUPS_OK_ACKNOWLEDGE":
            sessionMode = JMSContext.DUPS_OK_ACKNOWLEDGE;
            break;
        default:
            throw ex.illegalStateUnknowSessionMode(mode);
    }

    if (username != null) {
        return factory.createContext(username, password, sessionMode);
    } else {
        return factory.createContext(sessionMode);
    }
}
 
Example 2
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnRecoverFailure() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).recover();

    try {
        context.recover();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 3
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateStreamMessage() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createStreamMessage();

    try {
        context.createStreamMessage();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 4
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateTemporaryQueueFailure() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createTemporaryQueue();

    try {
        context.createTemporaryQueue();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 5
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateTemporaryTopicFailure() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createTemporaryTopic();

    try {
        context.createTemporaryTopic();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 6
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateQueueFailure() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createQueue(anyString());

    try {
        context.createQueue("test");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 7
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateTopicFailure() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createTopic(anyString());

    try {
        context.createTopic("test");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 8
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateTextMessage() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createTextMessage();

    try {
        context.createTextMessage();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 9
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnAcknowledgeFailure() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).acknowledge(ACK_TYPE.ACCEPTED);

    try {
        context.acknowledge();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 10
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateMessage() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createMessage();

    try {
        context.createMessage();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 11
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnsubscribePassthrough() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);

    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);

    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    try {
        context.unsubscribe("subscription");
    } finally {
        context.close();
    }

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

    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);

    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    try {
        context.recover();
    } finally {
        context.close();
    }

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

    Mockito.doThrow(IllegalStateException.class).when(session).createTextMessage(anyString());

    try {
        context.createTextMessage("test");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 14
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateBytesMessage() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createBytesMessage();

    try {
        context.createBytesMessage();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 15
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 16
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testRuntimeExceptionOnGetMetaDataFailure() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(connection).getMetaData();

    try {
        context.getMetaData();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 17
Source File: MockJMSSession.java    From pooled-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:
            return;
        default:
            throw new JMSRuntimeException("Invalid Session Mode: " + mode);
    }
}
 
Example 18
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testRuntimeExceptionOnGetClientIDFailure() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(connection).getClientID();

    try {
        context.getClientID();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 19
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testRuntimeExceptionOnSetClientIDFailure() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsContext context = new JmsContext(connection, JMSContext.CLIENT_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(connection).setClientID(anyString());

    try {
        context.setClientID("client");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example 20
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);
    }
}