javax.jms.IllegalStateRuntimeException Java Examples

The following examples show how to use javax.jms.IllegalStateRuntimeException. 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 testRuntimeExceptionOnCreateObjectMessage() 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).createObjectMessage();

    try {
        context.createObjectMessage();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
 
Example #2
Source File: JmsPoolJMSProducerTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionFromSendByteBody() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), new byte[0]);
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
Example #3
Source File: JmsPoolJMSProducerTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionFromSendStringBody() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), "test");
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
Example #4
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateDurableConsumer() 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());

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

    Mockito.verify(session, Mockito.times(1)).createDurableConsumer(any(Topic.class), anyString());
}
 
Example #5
Source File: MockJMSContext.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Override
public JMSProducer createProducer() {
    if (connectionRefCount.get() == 0) {
        throw new IllegalStateRuntimeException("The Connection is closed");
    }

    try {
        if (sharedProducer == null) {
            synchronized (this) {
                if (sharedProducer == null) {
                    sharedProducer = (MockJMSMessageProducer) getSession().createProducer(null);
                }
            }
        }

        return new MockJMSProducer(getSession(), sharedProducer);
    } catch (JMSException jmse) {
        throw JMSExceptionSupport.createRuntimeException(jmse);
    }
}
 
Example #6
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateSharedConsumerSelectorNoLocal() 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(), anyString());

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

    Mockito.verify(session, Mockito.times(1)).createSharedConsumer(any(Topic.class), anyString(), anyString());
}
 
Example #7
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateConsumerWithSelectorNoLocal() 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(), anyBoolean());

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

    Mockito.verify(session, Mockito.times(1)).createConsumer(any(Destination.class), anyString(), anyBoolean());
}
 
Example #8
Source File: JmsPoolJMSProducerTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionFromSendSerializableBody() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), UUID.randomUUID());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
Example #9
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 #10
Source File: JmsConsumerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnReceiveBodyNoWait() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveBody(Map.class, 0);

    try {
        consumer.receiveBodyNoWait(Map.class);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
 
Example #11
Source File: JmsConsumerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnTimedReceiveBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveBody(Map.class, 100);

    try {
        consumer.receiveBody(Map.class, 100);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
 
Example #12
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 #13
Source File: JmsConsumerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnReceiveBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveBody(Map.class, -1);

    try {
        consumer.receiveBody(Map.class);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
 
Example #14
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 #15
Source File: JmsConsumerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnTimedReceive() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receive(anyLong());

    try {
        consumer.receive(100);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
 
Example #16
Source File: JmsSource.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
private void enqueue(long n) {
    for (int i = 0; i < n; i++) {
        executor.execute(() -> {
            try {
                Message message = consumer.receive();
                if (message != null) { // null means closed.
                    requests.decrementAndGet();
                    downstream.get().onNext(message);
                }
            } catch (IllegalStateRuntimeException e) {
                log.clientClosed();
            }

        });
    }
}
 
Example #17
Source File: JmsConsumerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnReceive() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receive();

    try {
        consumer.receive();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
 
Example #18
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 #19
Source File: JmsConsumerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnSetMessageListener() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).setMessageListener(null);

    try {
        consumer.setMessageListener(null);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
 
Example #20
Source File: JmsConsumerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnGetMessageListener() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).getMessageListener();

    try {
        consumer.getMessageListener();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
 
Example #21
Source File: JmsPoolJMSContextTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testSetClientIDTwiceWithSameID() throws Exception {
    JMSContext context = cf.createContext();

    // test: call setClientID("newID") twice
    // this should be tolerated and not result in an exception
    context.setClientID("newID");

    try {
        context.setClientID("newID");
        context.start();
        context.close();
    } catch (IllegalStateRuntimeException ise) {
        LOG.error("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage());
        fail("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage());
    } finally {
        cf.stop();
    }

    LOG.debug("Test finished.");
}
 
Example #22
Source File: JmsPoolJMSContextTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testSetClientIDTwiceWithDifferentID() throws Exception {
    JMSContext context = cf.createContext();

    // test: call setClientID() twice with different IDs
    // this should result in an IllegalStateException
    context.setClientID("newID1");
    try {
        context.setClientID("newID2");
        fail("calling Connection.setClientID() twice with different clientID must raise an IllegalStateException");
    } catch (IllegalStateRuntimeException ise) {
        LOG.debug("Correctly received " + ise);
    } finally {
        context.close();
        cf.stop();
    }

    LOG.debug("Test finished.");
}
 
Example #23
Source File: JmsPoolJMSContextTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testSetClientIDAfterConnectionStart() throws Exception {
    JMSContext context = cf.createContext();

    // test: try to call setClientID() after start()
    // should result in an exception
    try {
        context.start();
        context.setClientID("newID3");
        fail("Calling setClientID() after start() mut raise a JMSException.");
    } catch (IllegalStateRuntimeException ise) {
        LOG.debug("Correctly received " + ise);
    } finally {
        context.close();
        cf.stop();
    }

    LOG.debug("Test finished.");
}
 
Example #24
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 #25
Source File: JmsContextTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionOnCreateSharedDurableConsumer() 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).createSharedDurableConsumer(any(Topic.class), anyString());

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

    Mockito.verify(session, Mockito.times(1)).createSharedDurableConsumer(any(Topic.class), anyString());
}
 
Example #26
Source File: JmsProducerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionFromSendStringBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);

    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));

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

    JmsProducer producer = new JmsProducer(session, messageProducer);

    try {
        producer.send(session.createTemporaryQueue(), "test");
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
Example #27
Source File: JmsProducerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionFromSendMapBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);

    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));

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

    JmsProducer producer = new JmsProducer(session, messageProducer);

    try {
        producer.send(session.createTemporaryQueue(), Collections.<String, Object>emptyMap());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
Example #28
Source File: JmsProducerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionFromSendByteBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);

    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));

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

    JmsProducer producer = new JmsProducer(session, messageProducer);

    try {
        producer.send(session.createTemporaryQueue(), new byte[0]);
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
Example #29
Source File: JmsProducerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuntimeExceptionFromSendMessage() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);
    Message message = Mockito.mock(Message.class);

    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(session.createMessage()).thenReturn(message);

    Mockito.doThrow(IllegalStateException.class).when(message).setJMSCorrelationID(anyString());

    JmsProducer producer = new JmsProducer(session, messageProducer);

    producer.setJMSCorrelationID("id");

    try {
        producer.send(session.createTemporaryQueue(), session.createMessage());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
Example #30
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();
    }
}