KickJava   Java API By Example, From Geeks To Geeks.

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


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.Message JavaDoc;
21 import javax.jms.Session JavaDoc;
22 import javax.jms.TextMessage JavaDoc;
23
24 /**
25  * @version $Revision: 1.4 $
26  */

27 public class JMSDurableTopicRedeliverTest extends JmsTopicRedeliverTest {
28     
29     private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
30             .getLog(JMSDurableTopicRedeliverTest.class);
31     
32     protected void setUp() throws Exception JavaDoc {
33         durable = true;
34         super.setUp();
35     }
36     
37     /**
38      * Sends and consumes the messages.
39      *
40      * @throws Exception
41      */

42     public void testRedeliverNewSession() throws Exception JavaDoc {
43         String JavaDoc text = "TEST: "+System.currentTimeMillis();
44         Message sendMessage = session.createTextMessage(text);
45
46         if (verbose) {
47             log.info("About to send a message: " + sendMessage + " with text: " + text);
48         }
49         producer.send(producerDestination, sendMessage);
50
51         //receive but don't acknowledge
52
Message unackMessage = consumer.receive(1000);
53         assertNotNull(unackMessage);
54         String JavaDoc unackId = unackMessage.getJMSMessageID();
55         assertEquals(((TextMessage JavaDoc) unackMessage).getText(), text);
56         assertFalse(unackMessage.getJMSRedelivered());
57         assertEquals(unackMessage.getIntProperty("JMSXDeliveryCount"),1);
58         consumeSession.close();
59         consumer.close();
60
61         //receive then acknowledge
62
consumeSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
63         consumer = createConsumer();
64         Message ackMessage = consumer.receive(1000);
65         assertNotNull(ackMessage);
66         ackMessage.acknowledge();
67         String JavaDoc ackId = ackMessage.getJMSMessageID();
68         assertEquals(((TextMessage JavaDoc) ackMessage).getText(), text);
69         assertTrue(ackMessage.getJMSRedelivered());
70         assertEquals(ackMessage.getIntProperty("JMSXDeliveryCount"),2);
71         assertEquals(unackId, ackId);
72         consumeSession.close();
73         consumer.close();
74
75         consumeSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
76         consumer = createConsumer();
77         assertNull(consumer.receive(1000));
78     }
79 }
80
Popular Tags