ChangeSessionDeliveryModeTest xref

    1   /***
    2    *
    3    * Copyright 2004 Protique Ltd
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18
    19  package org.codehaus.activemq.usecases;
    20  import java.util.HashMap;
    21  import javax.jms.Connection;
    22  import javax.jms.Destination;
    23  import javax.jms.IllegalStateException;
    24  import javax.jms.JMSException;
    25  import javax.jms.Message;
    26  import javax.jms.MessageConsumer;
    27  import javax.jms.MessageListener;
    28  import javax.jms.MessageProducer;
    29  import javax.jms.ObjectMessage;
    30  import javax.jms.Session;
    31  import org.codehaus.activemq.TestSupport;
    32
    33  /***
    34   * @version $Revision: 1.1 $
    35   */
    36  public class ChangeSessionDeliveryModeTest extends TestSupport implements MessageListener {
    37      private static final int COUNT = 200;
    38      private static final String VALUE_NAME = "value";
    39
    40      /***
    41       * test following condition- which are defined by JMS Spec 1.1: MessageConsumers cannot use a MessageListener and
    42       * receive() from the same session
    43       *
    44       * @throws Exception
    45       */
    46      public void testDoChangeSessionDeliveryMode() throws Exception {
    47          Destination destination = createDestination("foo.bar");
    48          Connection connection = createConnection();
    49          connection.start();
    50          Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    51          MessageConsumer consumer1 = consumerSession.createConsumer(destination);
    52          consumer1.setMessageListener(this);
    53          JMSException jmsEx = null;
    54          MessageConsumer consumer2 = consumerSession.createConsumer(destination);
    55          try {
    56              consumer2.receive(10);
    57          }
    58          catch (JMSException e) {
    59              jmsEx = e;
    60          }
    61          assertTrue(jmsEx != null && jmsEx instanceof IllegalStateException);
    62      }
    63
    64      public void onMessage(Message msg) {
    65      }
    66  }