KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > transaction > manager > ProtocolTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package org.apache.geronimo.transaction.manager;
19
20 import javax.transaction.Transaction JavaDoc;
21 import javax.transaction.xa.XAResource JavaDoc;
22
23 import junit.framework.TestCase;
24
25 /**
26  */

27 public class ProtocolTest extends TestCase {
28
29     private TransactionManagerImpl tm;
30     private MockResourceManager mrm1, mrm2;
31     private MockResource mr11, mr12, mr21, mr22;
32
33     protected void setUp() throws Exception JavaDoc {
34         tm = new TransactionManagerImpl();
35         mrm1 = new MockResourceManager(true);
36         mrm2 = new MockResourceManager(true);
37         mr11 = new MockResource(mrm1, "mr11");
38         mr12 = new MockResource(mrm1, "mr12");
39         mr21 = new MockResource(mrm2, "mr21");
40         mr22 = new MockResource(mrm2, "mr22");
41     }
42
43     public void testOnePhaseCommit() throws Exception JavaDoc {
44         tm.begin();
45         Transaction JavaDoc tx = tm.getTransaction();
46         tx.enlistResource(mr11);
47         tx.delistResource(mr11, XAResource.TMSUSPEND);
48         tm.commit();
49     }
50
51     public void testOnePhaseCommiTwoResources() throws Exception JavaDoc {
52         tm.begin();
53         Transaction JavaDoc tx = tm.getTransaction();
54         tx.enlistResource(mr11);
55         tx.delistResource(mr11, XAResource.TMSUSPEND);
56         tx.enlistResource(mr12);
57         tx.delistResource(mr12, XAResource.TMSUSPEND);
58         tm.commit();
59     }
60     public void testTwoPhaseCommit() throws Exception JavaDoc {
61         tm.begin();
62         Transaction JavaDoc tx = tm.getTransaction();
63         tx.enlistResource(mr11);
64         tx.delistResource(mr11, XAResource.TMSUSPEND);
65         tx.enlistResource(mr21);
66         tx.delistResource(mr21, XAResource.TMSUSPEND);
67         tm.commit();
68     }
69     public void testTwoPhaseCommit4Resources() throws Exception JavaDoc {
70         tm.begin();
71         Transaction JavaDoc tx = tm.getTransaction();
72         tx.enlistResource(mr11);
73         tx.delistResource(mr11, XAResource.TMSUSPEND);
74         tx.enlistResource(mr12);
75         tx.delistResource(mr12, XAResource.TMSUSPEND);
76         tx.enlistResource(mr21);
77         tx.delistResource(mr21, XAResource.TMSUSPEND);
78         tx.enlistResource(mr22);
79         tx.delistResource(mr22, XAResource.TMSUSPEND);
80         tm.commit();
81     }
82
83 }
84
Popular Tags