KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb1 > Raidb1WaitForAllCompletionPolicyScenario


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Frederic Laugier
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.raidb1;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.Statement JavaDoc;
29
30 import org.objectweb.cjdbc.scenario.templates.SimpleRaidb1Template;
31
32 /**
33  * This class defines a Raidb1WaitForAllCompletionPolicyScenario. Test the
34  * 'wait for all' completion policy when databases are failing
35  *
36  * @author <a HREF="mailto:flaugier@micropole-univers.com">Frederic Laugier</a>
37  * @version 1.0
38  */

39 public class Raidb1WaitForAllCompletionPolicyScenario extends SimpleRaidb1Template
40 {
41
42   /**
43    * Test CJDBC write transaction failover in raidb1 with variable pool
44    */

45   public void testWriteTransactionFailOverWithVariablePool()
46   {
47     try
48     {
49       // Load database
50
cm.loadVirtualDatabases(controller, "myDB",
51           "hsqldb-raidb1-variablepool-waitforall.xml");
52       mainVdb = controller.getVirtualDatabase("myDB");
53       mainVdb.enableAllBackends();
54
55       // Drop a backend
56
hm.stop(hm1);
57
58       // Get a connection
59
Connection JavaDoc con = getCJDBCConnection();
60       assertNotNull("Connection is null", con);
61       
62       // Starts a transaction
63
con.setAutoCommit(false);
64
65       // Executes an update with only one backend enabled
66
Statement JavaDoc stmt1 = con.createStatement();
67       stmt1.executeUpdate("update product set name='horizontalTest1'");
68       stmt1.close();
69
70       // Executes an second update in a row
71
Statement JavaDoc stmt2 = con.createStatement();
72       stmt2.executeUpdate("update product set name='horizontalTest2'");
73       stmt2.close();
74
75       // Closes the transaction, and the connection
76
con.rollback();
77       con.close();
78     }
79     catch (Exception JavaDoc e)
80     {
81       e.printStackTrace();
82       fail("failed to test c-jdbc transaction failover in variable pool connection manager");
83     }
84   }
85
86   /**
87    * Test CJDBC write failover in raidb1 with variable pool
88    */

89   public void testWriteFailOverWithVariablePool()
90   {
91     try
92     {
93       // Load database
94
cm.loadVirtualDatabases(controller, "myDB",
95           "hsqldb-raidb1-variablepool-waitforall.xml");
96       mainVdb = controller.getVirtualDatabase("myDB");
97       mainVdb.enableAllBackends();
98
99       // Drop a backend
100
hm.stop(hm1);
101
102       // Get a connection
103
Connection JavaDoc con = getCJDBCConnection();
104       assertNotNull("Connection is null", con);
105
106       // Executes an update with only one backend enabled
107
Statement JavaDoc stmt1 = con.createStatement();
108       stmt1.executeUpdate("update product set name='horizontalTest1'");
109       stmt1.close();
110
111       // Executes an second update in a row
112
Statement JavaDoc stmt2 = con.createStatement();
113       stmt2.executeUpdate("update product set name='horizontalTest2'");
114       stmt2.close();
115
116       // Closes the connection
117
con.close();
118     }
119     catch (Exception JavaDoc e)
120     {
121       e.printStackTrace();
122       fail("failed to test c-jdbc transaction failover in variable pool connection manager");
123     }
124   }
125
126   /**
127    * Test CJDBC write transaction failover in raidb1 with simple connection manager
128    */

129   public void testWriteTransactionFailOverWithNoPool()
130   {
131     try
132     {
133       // Load database
134
cm.loadVirtualDatabases(controller, "myDB",
135           "hsqldb-raidb1-nopool-waitforall.xml");
136       mainVdb = controller.getVirtualDatabase("myDB");
137       mainVdb.enableAllBackends();
138
139       // Drop a backend
140
hm.stop(hm1);
141
142       // Get a connection
143
Connection JavaDoc con = getCJDBCConnection();
144       assertNotNull("Connection is null", con);
145
146       // Starts a transaction
147
con.setAutoCommit(false);
148
149       // Executes an update with only one backend enabled
150
Statement JavaDoc stmt1 = con.createStatement();
151       stmt1.executeUpdate("update product set name='horizontalTest1'");
152       stmt1.close();
153
154       // Executes an second update in a row
155
Statement JavaDoc stmt2 = con.createStatement();
156       stmt2.executeUpdate("update product set name='horizontalTest2'");
157       stmt2.close();
158
159       // Closes the transaction, and the connection
160
con.rollback();
161       con.close();
162     }
163     catch (Exception JavaDoc e)
164     {
165       e.printStackTrace();
166       fail("failed to test c-jdbc transaction failover in simple connection manager");
167     }
168   }
169
170   /**
171    * Test CJDBC write failover in raidb1 with simple connection manager
172    */

173   public void testWriteFailOverWithNoPool()
174   {
175     try
176     {
177       // Load database
178
cm.loadVirtualDatabases(controller, "myDB",
179           "hsqldb-raidb1-nopool-waitforall.xml");
180       mainVdb = controller.getVirtualDatabase("myDB");
181       mainVdb.enableAllBackends();
182
183       // Drop a backend
184
hm.stop(hm1);
185
186       // Get a connection
187
Connection JavaDoc con = getCJDBCConnection();
188       assertNotNull("Connection is null", con);
189
190       // Executes an update with only one backend enabled
191
Statement JavaDoc stmt1 = con.createStatement();
192       stmt1.executeUpdate("update product set name='horizontalTest1'");
193       stmt1.close();
194
195       // Executes an second update in a row
196
Statement JavaDoc stmt2 = con.createStatement();
197       stmt2.executeUpdate("update product set name='horizontalTest2'");
198       stmt2.close();
199
200       // Closes the connection
201
con.close();
202     }
203     catch (Exception JavaDoc e)
204     {
205       e.printStackTrace();
206       fail("failed to test c-jdbc transaction failover in simple connection manager");
207     }
208   }
209
210
211 }
212
Popular Tags