KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import org.objectweb.cjdbc.common.util.Constants;
33 import org.objectweb.cjdbc.scenario.templates.HorizontalWithRecoveryTemplate;
34 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
35 import org.objectweb.cjdbc.scenario.tools.testlet.UpdateTestLet;
36
37 /**
38  * This class defines a TransferBackendAfterFailureScenario
39  *
40  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
41  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
42  * </a>
43  * @version 1.0
44  */

45 public class TransferBackendAfterFailureScenario
46     extends HorizontalWithRecoveryTemplate
47 {
48   private static final String JavaDoc DUMP_NAME = "dump1";
49   private static final String JavaDoc BACKUP_LOGIN = "user";
50   private static final String JavaDoc BACKUP_PASSWORD = "";
51   private static final String JavaDoc BACKUPER = "Octopus";
52   private static final String JavaDoc BACKUP_PATH = "../backup";
53
54   /**
55    * Is this feasible ?
56    *
57    * @throws Exception if fails
58    */

59   public void testDataIntegrity() throws Exception JavaDoc
60   {
61     // get Connection
62
Connection JavaDoc con = getCJDBCConnection("25323");
63     ScenarioUtility.displaySingleQueryResult("select * from PRODUCT", con);
64
65     // Disable and backup backend localhost and enable backend
66
mainVdb1.backupBackend("localhost", BACKUP_LOGIN, BACKUP_PASSWORD,
67         DUMP_NAME, BACKUPER, BACKUP_PATH, null);
68
69     // Simulate a failure on controller 2
70
controller2.shutdown(Constants.SHUTDOWN_WAIT);
71
72     // Execute some queries so the group communication figures out a controller
73
// died
74
for (int i = 0; i < 10; i++)
75     {
76       Thread.sleep(100);
77       con.createStatement().execute("update PRODUCT set name='loose'");
78     }
79
80     // Replicate the backend to the remaining controller
81
Map JavaDoc map1 = new HashMap JavaDoc();
82     map1.put("url", "jdbc:hsqldb:hsql://localhost:9003");
83     mainVdb1.replicateBackend("localhost", "localhost3", map1);
84     Map JavaDoc map2 = new HashMap JavaDoc();
85     map2.put("url", "jdbc:hsqldb:hsql://localhost:9004");
86     mainVdb1.replicateBackend("localhost", "localhost4", map2);
87
88     // Restore the backends
89
mainVdb1.restoreDumpOnBackend("localhost3", BACKUP_LOGIN, BACKUP_PASSWORD,
90         DUMP_NAME, null);
91     mainVdb1.restoreDumpOnBackend("localhost4", BACKUP_LOGIN, BACKUP_PASSWORD,
92         DUMP_NAME, null);
93
94     // Enable the newly restored backends
95
mainVdb1.enableBackendFromCheckpoint("localhost3");
96     mainVdb1.enableBackendFromCheckpoint("localhost4");
97
98     // Execute some writes
99
UpdateTestLet let = new UpdateTestLet(con);
100     let.execute();
101
102     // Query each backend independently
103
Connection JavaDoc con1 = getHypersonicConnection(9001);
104     Connection JavaDoc con2 = getHypersonicConnection(9002);
105     Connection JavaDoc con3 = getHypersonicConnection(9003);
106     Connection JavaDoc con4 = getHypersonicConnection(9004);
107     ArrayList JavaDoc list1 = ScenarioUtility.getSingleQueryResult(
108         "select * from PRODUCT", con1);
109     ArrayList JavaDoc list2 = ScenarioUtility.getSingleQueryResult(
110         "select * from PRODUCT", con2);
111     ArrayList JavaDoc list3 = ScenarioUtility.getSingleQueryResult(
112         "select * from PRODUCT", con3);
113     ArrayList JavaDoc list4 = ScenarioUtility.getSingleQueryResult(
114         "select * from PRODUCT", con4);
115
116     // Check results
117
assertEquals(list1, list2);
118     assertEquals(list1, list3);
119     assertEquals(list1, list4);
120   }
121 }
Popular Tags