KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb1 > recovery > Raidb1BackupScenario


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): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.raidb1.recovery;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.ResultSet JavaDoc;
29 import java.util.ArrayList JavaDoc;
30
31 import org.objectweb.cjdbc.scenario.templates.Raidb1RecoveryTemplate;
32 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
33
34 /**
35  * This class defines a Raidb1BackupScenario We had a problem where some tasks
36  * were left on the backend pending requests and thus we could not start the
37  * backup process.
38  *
39  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modryzk </a>
40  * @version 1.0
41  */

42 public class Raidb1BackupScenario extends Raidb1RecoveryTemplate
43 {
44   private static final String JavaDoc BACKUP_LOGIN = "user";
45   private static final String JavaDoc BACKUP_PASSWORD = "";
46   private static final String JavaDoc BACKUPER = "Octopus";
47   private static final String JavaDoc BACKUP_PATH = "../backup";
48
49   /**
50    * Test recovery scenario
51    *
52    * @throws Exception if fails
53    */

54   public void testBasicRecoveryScenario() throws Exception JavaDoc
55   {
56     Connection JavaDoc con = getCJDBCConnection();
57     ResultSet JavaDoc rs = con.createStatement().executeQuery("select * from document");
58     ArrayList JavaDoc list1 = ScenarioUtility.convertResultSet(rs);
59     System.out.println(list1);
60     rs.close();
61     String JavaDoc dump = "dump" + System.currentTimeMillis();
62     mainVdb.backupBackend("localhost", BACKUP_LOGIN, BACKUP_PASSWORD, dump,
63         BACKUPER, BACKUP_PATH, null);
64
65     rs = con.createStatement().executeQuery("select * from document");
66     ArrayList JavaDoc list2 = ScenarioUtility.convertResultSet(rs);
67     rs.close();
68
69     assertEquals("ResultSets are different", list1, list2);
70     // mainVdb.enableBackendFromCheckpoint("localhost", checkpoint);
71
}
72
73   /**
74    * Test complete recovery scenario, dropping a backend and putting it back
75    * online
76    *
77    * @throws Exception if fails
78    */

79   public void testCompleteRecoveryScenario() throws Exception JavaDoc
80   {
81     String JavaDoc dump = "dump" + System.currentTimeMillis();
82     mainVdb.backupBackend("localhost", BACKUP_LOGIN, BACKUP_PASSWORD, dump,
83         BACKUPER, BACKUP_PATH, null);
84     hm.stop(hm1);
85     Connection JavaDoc con = getCJDBCConnection();
86     con.createStatement().executeQuery("select * from document");
87     ArrayList JavaDoc current = null;
88     ArrayList JavaDoc previous = null;
89     for (int i = 0; i < 50; i++)
90     {
91       // con = getCJDBCConnection();
92
current = ScenarioUtility.convertResultSet(con.createStatement()
93           .executeQuery("select * from document"));
94       if (previous != null)
95         assertEquals("Result sets are different before recovery", previous,
96             current);
97       previous = current;
98     }
99     mainVdb.forceDisableBackend("localhost2");
100     hm1 = hm.start("9001");
101     hm1.loadDatabase("database-useronly.template");
102     mainVdb.restoreDumpOnBackend("localhost", BACKUP_LOGIN, BACKUP_PASSWORD,
103         dump, null);
104     mainVdb.enableBackendFromCheckpoint("localhost");
105
106     for (int i = 0; i < 50; i++)
107     {
108       // con = getCJDBCConnection();
109
current = ScenarioUtility.convertResultSet(con.createStatement()
110           .executeQuery("select * from document"));
111       assertEquals("Results sets are different after recovery", previous,
112           current);
113       previous = current;
114     }
115   }
116
117 }
Popular Tags