KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > horizontal > ControllerHasLostAllBackendsFailoverScenario


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 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): Nicolas Modrzyk.
22  * Contributor(s): Emmanuel Cecchet.
23  */

24
25 package org.objectweb.cjdbc.scenario.horizontal;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.PreparedStatement JavaDoc;
29
30 import org.objectweb.cjdbc.driver.ControllerInfo;
31 import org.objectweb.cjdbc.scenario.templates.HorizontalTemplate;
32 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
33
34 /**
35  * We want to test on a read request, that if a controller has lost all its
36  * backends, the driver should send the request on the other controller.
37  *
38  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
39  * @version 1.0
40  */

41 public class ControllerHasLostAllBackendsFailoverScenario
42     extends HorizontalTemplate
43 {
44   /**
45    * We send a read request on a controller that has no more backend, and we
46    * want the other controller to send the result with its backends
47    *
48    * @throws Exception if fails
49    */

50   public void testReadFailover() throws Exception JavaDoc
51   {
52     Connection JavaDoc con = getCJDBCConnection(new ControllerInfo[]{
53         new ControllerInfo("localhost", 25322),
54         new ControllerInfo("localhost", 25323)});
55     hm.stop(hm1);
56     hm.stop(hm2);
57     String JavaDoc query = "Select * from document";
58     ScenarioUtility.displaySingleQueryResult(query, con);
59   }
60
61   /**
62    * We send a write request on a controller that has no more backend, and we
63    * want the other controller to send the result with its backends
64    *
65    * @throws Exception if fails
66    */

67   public void testWriteFailover() throws Exception JavaDoc
68   {
69     Connection JavaDoc con = getCJDBCConnection(new ControllerInfo[]{
70         new ControllerInfo("localhost", 25322),
71         new ControllerInfo("localhost", 25323)});
72     hm.stop(hm1);
73     hm.stop(hm2);
74     String JavaDoc query = "update document set total=?";
75     PreparedStatement JavaDoc ps = con.prepareStatement(query);
76     ps.setDouble(1, 0.0);
77     int updateC = ps.executeUpdate();
78     logger.warn("Number of updates:" + updateC);
79     assertTrue(updateC > 1);
80   }
81 }
Popular Tags