1 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 38 public class MultipleRecoveryScenario extends MultipleBackendsRaidb1Template 39 { 40 private static final String BACKUP_LOGIN = "user"; 41 private static final String BACKUP_PASSWORD = ""; 42 private static final String BACKUPER = "Octopus"; 43 private static final String 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 58 public void testMultipleBackup() throws Exception 59 { 60 BackupListener listener = new BackupListener() 61 { 62 63 66 public void success(String backendName) 67 { 68 success++; 69 logger.info("LISTENER:Success for backend:" + backendName); 70 } 71 72 76 public void failure(String backendName, Exception 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 |