KickJava   Java API By Example, From Geeks To Geeks.

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


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.JMSException JavaDoc;
22 import javax.jms.Message JavaDoc;
23 import javax.jms.MessageConsumer 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 JmsAutoAckTest extends TestSupport {
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 JMSException 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         Message msg = consumer.receive(1000);
66         assertNotNull(msg);
67         
68         // Reset the session.
69
session.close();
70         session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
71         
72         // Attempt to Consume the message...
73
consumer = session.createConsumer(queue);
74         msg = consumer.receive(1000);
75         assertNull(msg);
76
77         session.close();
78     }
79     
80
81 }
82
Popular Tags