KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.cjdbc.common.log.Trace;
28 import org.objectweb.cjdbc.common.shared.BackupListener;
29 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
30 import org.objectweb.cjdbc.scenario.templates.MultipleBackendsRaidb1Template;
31
32 /**
33  * This class defines a MultipleRecoveryScenario
34  *
35  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
36  * @version 1.0
37  */

38 public class MultipleRecoveryScenario extends MultipleBackendsRaidb1Template
39 {
40   private static final String JavaDoc BACKUP_LOGIN = "user";
41   private static final String JavaDoc BACKUP_PASSWORD = "";
42   private static final String JavaDoc BACKUPER = "Octopus";
43   private static final String JavaDoc BACKUP_PATH = "../backup";
44
45   int success = 0;
46   int failures = 0;
47   static final int BACKENDS_TOTAL = 2;
48
49   Trace logger = Trace
50                                                   .getLogger(MultipleRecoveryScenario.class
51                                                       .getName());
52
53   /**
54    * Test if we can start multiple octopus threads
55    *
56    * @throws Exception if fails
57    */

58   public void testMultipleBackup() throws Exception JavaDoc
59   {
60     BackupListener listener = new BackupListener()
61     {
62
63       /**
64        * @see org.objectweb.cjdbc.common.shared.BackupListener#success(java.lang.String)
65        */

66       public void success(String JavaDoc backendName)
67       {
68         success++;
69         logger.info("LISTENER:Success for backend:" + backendName);
70       }
71
72       /**
73        * @see org.objectweb.cjdbc.common.shared.BackupListener#failure(java.lang.String,
74        * java.lang.Exception)
75        */

76       public void failure(String JavaDoc backendName, Exception JavaDoc failure)
77       {
78         logger.info("LISTENER:Failure for backend:" + backendName
79             + "because of:" + failure.getMessage());
80         failure.printStackTrace();
81         failures++;
82       }
83     };
84     for (int i = 1; i <= BACKENDS_TOTAL; i++)
85     {
86       mainVdb.getRequestManager().backupBackend(
87           mainVdb.getAndCheckBackend("localhost" + i,
88               VirtualDatabase.NO_CHECK_BACKEND), BACKUP_LOGIN, BACKUP_PASSWORD,
89           System.currentTimeMillis() + "dump" + i, BACKUPER, BACKUP_PATH, null);
90     }
91
92     for (int i = 1; i <= BACKENDS_TOTAL; i++)
93     {
94       logger.info("Waiting for backup:" + i);
95       while (success + failures < BACKENDS_TOTAL)
96       {
97         synchronized (listener)
98         {
99           listener.wait();
100         }
101       }
102       logger.info("backup " + i + " is finished");
103     }
104
105     assertEquals("Some backups have failed", BACKENDS_TOTAL, success);
106   }
107 }
Popular Tags