KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmq > test > NackWithRollbackUnitTestCase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jbossmq.test;
23
24 import javax.jms.DeliveryMode JavaDoc;
25
26 import org.jboss.mq.AcknowledgementRequest;
27 import org.jboss.mq.ConnectionToken;
28 import org.jboss.mq.SpyMessage;
29 import org.jboss.mq.SpyQueue;
30 import org.jboss.mq.Subscription;
31 import org.jboss.mq.TransactionRequest;
32 import org.jboss.mq.server.JMSDestinationManager;
33 import org.jboss.test.jbossmq.JBossMQMicrocontainerTest;
34 import org.jboss.test.jbossmq.support.MockClientIL;
35
36 /**
37  * NackWithRollbackUnitTestCase.
38  *
39  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
40  * @version $Revision: 1.1 $
41  */

42 public class NackWithRollbackUnitTestCase extends JBossMQMicrocontainerTest
43 {
44    public NackWithRollbackUnitTestCase(String JavaDoc name)
45    {
46       super(name);
47    }
48    
49    public void testNackWithRollback() throws Exception JavaDoc
50    {
51       SpyQueue queue = createQueue("testQueue");
52       
53       JMSDestinationManager server = getJMSServer();
54       MockClientIL client = new MockClientIL();
55       ConnectionToken dc = new ConnectionToken("test", client, "session");
56       server.setEnabled(dc, true);
57       
58       // Add a message
59
SpyMessage send = new SpyMessage();
60       send.setJMSDestination(queue);
61       send.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
62       long ts = System.currentTimeMillis();
63       send.setJMSTimestamp(ts);
64       send.setJMSPriority(5);
65       send.setJMSMessageID("Message1");
66       server.addMessage(dc, send);
67
68       // Subscribe to the queue
69
Subscription sub = new Subscription();
70       sub.connectionToken = dc;
71       sub.subscriptionId = 1;
72       sub.destination = queue;
73       sub.noLocal = false;
74       server.subscribe(dc, sub);
75       
76       // Get the message
77
SpyMessage received = server.receive(dc, sub.subscriptionId, -1);
78       assertNotNull(received);
79       
80       // Prepare a nack
81
TransactionRequest t = new TransactionRequest();
82       t.xid = new Long JavaDoc(1);
83       t.requestType = TransactionRequest.TWO_PHASE_COMMIT_PREPARE_REQUEST;
84       received.createAcknowledgementRequest(sub.subscriptionId);
85       AcknowledgementRequest nack = received.getAcknowledgementRequest(false);
86       t.acks = new AcknowledgementRequest[] { nack };
87       server.transact(dc, t);
88
89       // Rollback
90
t = new TransactionRequest();
91       t.xid = new Long JavaDoc(1);
92       t.requestType = TransactionRequest.TWO_PHASE_COMMIT_ROLLBACK_REQUEST;
93       server.transact(dc, t);
94
95       // Should re-receive
96
received = server.receive(dc, sub.subscriptionId, -1);
97       assertNotNull(received);
98    }
99 }
100
Popular Tags