コード例 #1
0
  /** Test that close() hierarchically closes all child objects */
  public void testCloseHierarchy() throws Exception {
    Connection conn = cf.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = sess.createConsumer(topic1);
    MessageProducer producer = sess.createProducer(topic1);
    sess.createBrowser(queue1);
    Message m = sess.createMessage();

    conn.close();

    // Session

    /* If the session is closed then any method invocation apart from close()
     * will throw an IllegalStateException
     */
    try {
      sess.createMessage();
      fail("Session is not closed");
    } catch (javax.jms.IllegalStateException e) {
    }

    try {
      sess.getAcknowledgeMode();
      fail("should throw IllegalStateException");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    try {
      sess.getTransacted();
      fail("should throw IllegalStateException");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    try {
      sess.getMessageListener();
      fail("should throw IllegalStateException");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    try {
      sess.createProducer(queue1);
      fail("should throw IllegalStateException");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    try {
      sess.createConsumer(queue1);
      fail("should throw IllegalStateException");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    // Producer

    /* If the producer is closed then any method invocation apart from close()
     * will throw an IllegalStateException
     */
    try {
      producer.send(m);
      fail("Producer is not closed");
    } catch (javax.jms.IllegalStateException e) {
    }

    try {
      producer.getDisableMessageID();
      fail("should throw IllegalStateException");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    try {
      producer.getPriority();
      fail("should throw IllegalStateException");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    try {
      producer.getDestination();
      fail("should throw IllegalStateException");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    try {
      producer.getTimeToLive();
      fail("should throw IllegalStateException");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    // ClientConsumer

    try {
      consumer.getMessageSelector();
      fail("should throw exception");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    try {
      consumer.getMessageListener();
      fail("should throw exception");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    try {
      consumer.receive();
      fail("should throw exception");
    } catch (javax.jms.IllegalStateException e) {
      // OK
    }

    // Browser

  }
コード例 #2
0
 public String getMessageSelector() throws JMSException {
   return consumer.getMessageSelector();
 }