Apache Lucene open-source search software
SOLR-6119: TestReplicationHandler attempts to remove open folders (and other fixes).
Dawid Weissbb9116c48543
diff --git a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java b/solr/core/src/java/org/apache/solr/handler/SnapShooter.javaindex 83bec1d0c86..48213ceace9 100644--- a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java+++ b/solr/core/src/java/org/apache/solr/handler/SnapShooter.java@@ -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);}}--}diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.javaindex 61d5bcfc341..aec754ce1e2 100644--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java@@ -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() {@Overridepublic 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.");- }}- 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);+ 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++;}- waitCnt++;- }- if (deleteBackupThread.fail != null) {- fail(deleteBackupThread.fail);+ 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);+ }}/**