SOLR-6119: TestReplicationHandler attempts to remove open folders (and other fixes).

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1599422 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2014-06-03 06:21:14 +00:00
parent 151033cdc1
commit bb9116c485
2 changed files with 38 additions and 44 deletions

View File

@ -118,13 +118,12 @@ public class SnapShooter {
}
void validateCreateSnapshot() throws IOException {
Lock lock = lockFactory.makeLock(directoryName + ".lock");
snapShotDir = new File(snapDir, directoryName);
if (lock.isLocked()) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Unable to acquire lock for snapshot directory: " + snapShotDir.getAbsolutePath());
}
snapShotDir = new File(snapDir, directoryName);
if (snapShotDir.exists()) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Snapshot directory already exists: " + snapShotDir.getAbsolutePath());
@ -198,7 +197,7 @@ public class SnapShooter {
LOG.info("Deleting snapshot: " + snapshotName);
NamedList<Object> details = new NamedList<>();
boolean isSuccess = false;
boolean isSuccess;
File f = new File(snapDir, "snapshot." + snapshotName);
isSuccess = SnapPuller.delTree(f);
@ -236,7 +235,6 @@ public class SnapShooter {
}
}
public static final String SNAP_DIR = "snapDir";
public static final String DATE_FMT = "yyyyMMddHHmmssSSS";
@ -271,6 +269,4 @@ public class SnapShooter {
sourceDir.copy(destDir, indexFile, indexFile, DirectoryFactory.IOCONTEXT_NO_CACHE);
}
}
}

View File

@ -1444,9 +1444,10 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
};
File[] snapDir = new File[2];
boolean namedBackup = random().nextBoolean();
try {
String firstBackupTimestamp = null;
boolean namedBackup = true;
String[] backupNames = null;
if (namedBackup) {
backupNames = new String[2];
@ -1503,7 +1504,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
files = dataDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.startsWith("snapshot." + backupName)) {
if (name.equals("snapshot." + backupName)) {
return true;
}
return false;
@ -1520,49 +1521,46 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
reader.close();
dir.close();
if (!namedBackup && snapDir[0].exists()) {
fail("The first backup should have been cleaned up because " + backupKeepParamName + " was set to 1.");
}
if (!namedBackup && snapDir[0].exists()) {
fail("The first backup should have been cleaned up because " + backupKeepParamName + " was set to 1.");
}
//Test Deletion of named backup
if(namedBackup) {
for (int i = 0; i < 2; i++) {
BackupThread deleteBackupThread = new BackupThread(backupNames[i], ReplicationHandler.CMD_DELETE_BACKUP);
deleteBackupThread.start();
int waitCnt = 0;
CheckDeleteBackupStatus checkDeleteBackupStatus = new CheckDeleteBackupStatus();
while (true) {
checkDeleteBackupStatus.fetchStatus();
if (checkDeleteBackupStatus.fail != null) {
fail(checkDeleteBackupStatus.fail);
}
if (checkDeleteBackupStatus.success) {
break;
}
Thread.sleep(200);
if (waitCnt == 20) {
fail("Delete Backup success not detected:" + checkDeleteBackupStatus.response);
}
waitCnt++;
}
if (deleteBackupThread.fail != null) {
fail(deleteBackupThread.fail);
}
}
}
for (int i = 0; i < 2; i++) {
//Test Deletion of named backup
BackupThread deleteBackupThread = new BackupThread(backupNames[i], ReplicationHandler.CMD_DELETE_BACKUP);
deleteBackupThread.start();
int waitCnt = 0;
CheckDeleteBackupStatus checkDeleteBackupStatus = new CheckDeleteBackupStatus();
while (true) {
checkDeleteBackupStatus.fetchStatus();
if (checkDeleteBackupStatus.fail != null) {
fail(checkDeleteBackupStatus.fail);
}
if (checkDeleteBackupStatus.success) {
break;
}
Thread.sleep(200);
if (waitCnt == 20) {
fail("Delete Backup success not detected:" + checkDeleteBackupStatus.response);
}
waitCnt++;
}
if (deleteBackupThread.fail != null) {
fail(deleteBackupThread.fail);
}
}
} finally {
// FIXME: SOLR-6119 This is a test bug in that it tries to remove snapDirs that are still open.
try {
if(!namedBackup) {
TestUtil.rm(snapDir);
} catch (IOException e) {
// Ignore failures.
}
}
}
/* character copy of file using UTF-8 */
private static void copyFile(File src, File dst) throws IOException {
copyFile(src, dst, null, false);
}
}
/**