KickJava   Java API By Example, From Geeks To Geeks.

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


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
29 import org.objectweb.cjdbc.scenario.templates.Raidb1RecoveryWithRequestSenderTemplate;
30 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
31
32 /**
33  * This class defines a HotRecoveryScenario
34  *
35  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
36  * @version 1.0
37  */

38 public class HotRecoveryScenario
39     extends Raidb1RecoveryWithRequestSenderTemplate
40 {
41   private static final String JavaDoc BACKUP_LOGIN = "user";
42   private static final String JavaDoc BACKUP_PASSWORD = "";
43   private static final String JavaDoc BACKUPER = "Octopus";
44   private static final String JavaDoc BACKUP_PATH = "../backup";
45
46   /**
47    * A thread is sending requests in the background and we perform recovery on
48    * spare backends. Also we want to add a backend
49    *
50    * @throws Exception if fails
51    */

52   public void testHotDisableEnableWithCheckpoint() throws Exception JavaDoc
53   {
54     // Disable a backend
55
String JavaDoc checkpoint = "check";
56     String JavaDoc backend = "localhost2";
57     mainVdb.disableBackendWithCheckpoint(backend);
58
59     // Enable backend
60
mainVdb.enableBackendFromCheckpoint(backend);
61
62     if (sender.getExceptions().size() != 0)
63       fail("Got exceptions during run:" + sender.getExceptions());
64   }
65
66   /**
67    * A thread is sending requests in the background and we perform recovery on
68    * spare backends. Also we want to add a backend
69    *
70    * @throws Exception if fails
71    */

72   public void testHotRecovery() throws Exception JavaDoc
73   {
74     // Create a checkpoint and a backup from a backend
75
String JavaDoc dumpName = "check" + System.currentTimeMillis();
76     String JavaDoc backend = "localhost";
77     mainVdb.backupBackend(backend, BACKUP_LOGIN, BACKUP_PASSWORD, dumpName,
78         BACKUPER, BACKUP_PATH, null);
79
80     Connection JavaDoc recoveryC = getHypersonicConnection(9003);
81     ScenarioUtility.displayResultOnScreen(ScenarioUtility.getSingleQueryResult(
82         "select * from recovery", recoveryC));
83
84     // Disable other backend
85
backend = "localhost2";
86     String JavaDoc checkpoint2 = dumpName + "2";
87     mainVdb.disableBackendWithCheckpoint(backend);
88
89     // Restore the backend with the backup
90
mainVdb.restoreDumpOnBackend(backend, BACKUP_LOGIN, BACKUP_PASSWORD,
91         dumpName, null);
92
93     // Enable the newly restored backend from the checkpoint and make it active
94
mainVdb.enableBackendFromCheckpoint(backend, dumpName);
95
96     if (sender.getExceptions().size() != 0)
97       fail("Got exceptions during run:" + sender.getExceptions());
98   }
99 }
Popular Tags