Skip to content

Apache Lucene open-source search software

SOLR-7358: TestRestoreCore fails in Windows

Varun Thackerfe0ab10d4e73
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 9365a3562fb..9757f4e7ca4 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -104,6 +104,8 @@ Other Changes
* SOLR-6865: Upgrade HttpClient to 4.4.1 (Shawn Heisey)
+* SOLR-7358: TestRestoreCore fails in Windows (Ishan Chattopadhyaya via Varun Thacker)
+
================== 5.1.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release
diff --git a/solr/core/src/java/org/apache/solr/handler/RestoreCore.java b/solr/core/src/java/org/apache/solr/handler/RestoreCore.java
index 25ff24ee5d1..37d7172d28c 100644
--- a/solr/core/src/java/org/apache/solr/handler/RestoreCore.java
+++ b/solr/core/src/java/org/apache/solr/handler/RestoreCore.java
@@ -105,7 +105,7 @@ public class RestoreCore implements Callable<Boolean> {
log.info("Successfully restored to the backup index");
} catch (Exception e) {
//Rollback to the old index directory. Delete the restore index directory and mark the restore as failed.
- log.info("Could not switch to restored index. Rolling back to the current index");
+ log.warn("Could not switch to restored index. Rolling back to the current index");
Directory dir = null;
try {
dir = core.getDirectoryFactory().get(core.getDataDir(), DirectoryFactory.DirContext.META_DATA,
diff --git a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java
index e5d7adaa236..20f3afdb042 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLEncoder;
+import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -186,8 +187,10 @@ public class TestRestoreCore extends SolrJettyTestBase {
//Remove the segments_n file so that the backup index is corrupted.
//Restore should fail and it should automatically rollback to the original index.
Path restoreIndexPath = Paths.get(location, "snapshot." + snapshotName);
- Path segmentFileName = Files.newDirectoryStream(restoreIndexPath, IndexFileNames.SEGMENTS + "*").iterator().next();
- Files.delete(segmentFileName);
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(restoreIndexPath, IndexFileNames.SEGMENTS + "*")) {
+ Path segmentFileName = stream.iterator().next();
+ Files.delete(segmentFileName);
+ }
TestReplicationHandlerBackup.runBackupCommand(masterJetty, ReplicationHandler.CMD_RESTORE, params);