KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > JmsAutoAckListenerTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq;
19
20 import javax.jms.Connection JavaDoc;
21 import javax.jms.Message JavaDoc;
22 import javax.jms.MessageConsumer JavaDoc;
23 import javax.jms.MessageListener JavaDoc;
24 import javax.jms.MessageProducer JavaDoc;
25 import javax.jms.Queue JavaDoc;
26 import javax.jms.Session JavaDoc;
27
28 /**
29  * @version $Revision: 1.2 $
30  */

31 public class JmsAutoAckListenerTest extends TestSupport implements MessageListener JavaDoc{
32
33     private Connection JavaDoc connection;
34
35     protected void setUp() throws Exception JavaDoc {
36         super.setUp();
37         connection = createConnection();
38     }
39
40     /**
41      * @see junit.framework.TestCase#tearDown()
42      */

43     protected void tearDown() throws Exception JavaDoc {
44         if (connection != null) {
45             connection.close();
46             connection = null;
47         }
48         super.tearDown();
49     }
50     
51     /**
52      * Tests if acknowleged messages are being consumed.
53      *
54      * @throws javax.jms.JMSException
55      */

56     public void testAckedMessageAreConsumed() throws Exception JavaDoc {
57         connection.start();
58         Session JavaDoc session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
59         Queue JavaDoc queue = session.createQueue("test");
60         MessageProducer JavaDoc producer = session.createProducer(queue);
61         producer.send(session.createTextMessage("Hello"));
62
63         // Consume the message...
64
MessageConsumer JavaDoc consumer = session.createConsumer(queue);
65         consumer.setMessageListener(this);
66
67         Thread.sleep(10000);
68         session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
69         // Attempt to Consume the message...check if message was acknowledge
70
consumer = session.createConsumer(queue);
71         Message msg = consumer.receive(1000);
72         assertNull(msg);
73
74
75         session.close();
76      }
77
78
79    public void onMessage(Message message){
80         assertNotNull(message);
81
82
83    }
84 }
85
Popular Tags