类javax.jms.IllegalStateRuntimeException源码实例Demo

下面列出了怎么用javax.jms.IllegalStateRuntimeException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: smallrye-reactive-messaging   文件: JmsSource.java
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();
            }

        });
    }
}
 
源代码2 项目: pooled-jms   文件: JmsPoolJMSContext.java
@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 = (JmsPoolMessageProducer) getSession().createProducer(null);
                }
            }
        }

        return new JmsPoolJMSProducer(getSession(), sharedProducer);
    } catch (JMSException jmse) {
        throw JMSExceptionSupport.createRuntimeException(jmse);
    }
}
 
源代码3 项目: qpid-jms   文件: JmsContextTest.java
@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();
    }
}
 
源代码4 项目: pooled-jms   文件: JmsPoolJMSProducerTest.java
@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) {}
}
 
源代码5 项目: pooled-jms   文件: JmsPoolJMSProducerTest.java
@Test
public void testRuntimeExceptionFromSendMapBody() 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(), Collections.<String, Object>emptyMap());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
 
源代码6 项目: pooled-jms   文件: JmsPoolJMSProducerTest.java
@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) {}
}
 
源代码7 项目: pooled-jms   文件: JmsPoolJMSProducerTest.java
@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) {}
}
 
源代码8 项目: pooled-jms   文件: MockJMSContext.java
@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);
    }
}
 
源代码9 项目: qpid-jms   文件: JmsContextTest.java
@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());
}
 
源代码10 项目: qpid-jms   文件: JmsContextTest.java
@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();
    }
}
 
源代码11 项目: qpid-jms   文件: JmsContextTest.java
@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();
    }
}
 
源代码12 项目: qpid-jms   文件: JmsContextTest.java
@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();
    }
}
 
源代码13 项目: qpid-jms   文件: JmsContextTest.java
@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());
}
 
源代码14 项目: qpid-jms   文件: JmsContextTest.java
@Test
public void testRuntimeExceptionOnCreateSharedDurableConsumerSelectorNoLocal() 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(), anyString());

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

    Mockito.verify(session, Mockito.times(1)).createSharedDurableConsumer(any(Topic.class), anyString(), anyString());
}
 
源代码15 项目: qpid-jms   文件: JmsContextTest.java
@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();
    }
}
 
源代码16 项目: qpid-jms   文件: JmsContextTest.java
@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();
    }
}
 
源代码17 项目: qpid-jms   文件: JmsContextTest.java
@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();
    }
}
 
源代码18 项目: pooled-jms   文件: JmsPoolJMSContextTest.java
@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.");
}
 
源代码19 项目: pooled-jms   文件: JmsPoolJMSContextTest.java
@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.");
}
 
源代码20 项目: pooled-jms   文件: JmsPoolJMSContextTest.java
@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.");
}
 
源代码21 项目: qpid-jms   文件: JmsContextTest.java
@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();
    }
}
 
源代码22 项目: qpid-jms   文件: JmsProducerTest.java
@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) {}
}
 
源代码23 项目: qpid-jms   文件: JmsProducerTest.java
@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) {}
}
 
源代码24 项目: qpid-jms   文件: JmsProducerTest.java
@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) {}
}
 
源代码25 项目: qpid-jms   文件: JmsProducerTest.java
@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) {}
}
 
源代码26 项目: qpid-jms   文件: JmsContextTest.java
@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());
}
 
源代码27 项目: qpid-jms   文件: JmsContextTest.java
@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();
    }
}
 
源代码28 项目: qpid-jms   文件: JmsConsumerTest.java
@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();
    }
}
 
源代码29 项目: qpid-jms   文件: JmsConsumerTest.java
@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();
    }
}
 
源代码30 项目: qpid-jms   文件: JmsContextTest.java
@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));
}
 
 类所在包
 同包方法