You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2015/02/25 08:54:24 UTC
svn commit: r1662176 - in /lucene/dev/branches/branch_5x: ./ solr/
solr/CHANGES.txt solr/core/
solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
Author: shalin
Date: Wed Feb 25 07:54:23 2015
New Revision: 1662176
URL: http://svn.apache.org/r1662176
Log:
SOLR-7156: Fix test failures due to resource leaks on windows
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/solr/core/ (props changed)
lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1662176&r1=1662175&r2=1662176&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Wed Feb 25 07:54:23 2015
@@ -140,6 +140,9 @@ Other Changes
* SOLR-7142: Fix TestFaceting.testFacets. (Michal Kroliczek via shalin)
+* SOLR-7156: Fix test failures due to resource leaks on windows.
+ (Ishan Chattopadhyaya via shalin)
+
================== 5.0.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java?rev=1662176&r1=1662175&r2=1662176&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java Wed Feb 25 07:54:23 2015
@@ -18,12 +18,14 @@ package org.apache.solr.cloud;
*/
import java.io.IOException;
+import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import com.google.common.collect.Lists;
+
import org.apache.lucene.mockfile.FilterPath;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrClient;
@@ -417,9 +419,10 @@ public class BasicDistributedZk2Test ext
checkBackupStatus.fetchStatus();
Thread.sleep(1000);
}
- ArrayList<Path> files = Lists.newArrayList(Files.newDirectoryStream(location, "snapshot*").iterator());
-
- assertEquals(Arrays.asList(files).toString(), 1, files.size());
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(location, "snapshot*")) {
+ ArrayList<Path> files = Lists.newArrayList(stream.iterator());
+ assertEquals(Arrays.asList(files).toString(), 1, files.size());
+ }
}
Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java?rev=1662176&r1=1662175&r2=1662176&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java Wed Feb 25 07:54:23 2015
@@ -21,6 +21,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -130,18 +131,18 @@ public class TestReplicationHandlerBacku
}
//Validate
- Path snapDir = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*").iterator().next();
- verify(snapDir, nDocs);
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*")) {
+ Path snapDir = stream.iterator().next();
+ verify(snapDir, nDocs);
+ }
}
private void verify(Path backup, int nDocs) throws IOException {
- try (Directory dir = new SimpleFSDirectory(backup)) {
- IndexReader reader = DirectoryReader.open(dir);
+ try (Directory dir = new SimpleFSDirectory(backup);
+ IndexReader reader = DirectoryReader.open(dir)) {
IndexSearcher searcher = new IndexSearcher(reader);
TopDocs hits = searcher.search(new MatchAllDocsQuery(), 1);
assertEquals(nDocs, hits.totalHits);
- reader.close();
- dir.close();
}
}
@@ -167,7 +168,10 @@ public class TestReplicationHandlerBacku
Path[] snapDir = new Path[5]; //One extra for the backup on commit
//First snapshot location
- snapDir[0] = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*").iterator().next();
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*")) {
+ snapDir[0] = stream.iterator().next();
+ }
+
boolean namedBackup = random().nextBoolean();
String firstBackupTimestamp = null;
@@ -199,14 +203,19 @@ public class TestReplicationHandlerBacku
}
if (!namedBackup) {
- snapDir[i+1] = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*").iterator().next();
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*")) {
+ snapDir[i+1] = stream.iterator().next();
+ }
} else {
- snapDir[i+1] = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot." + backupName).iterator().next();
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot." + backupName)) {
+ snapDir[i+1] = stream.iterator().next();
+ }
}
verify(snapDir[i+1], nDocs);
}
+
//Test Deletion of named backup
if (namedBackup) {
testDeleteNamedBackup(backupNames);
@@ -214,10 +223,12 @@ public class TestReplicationHandlerBacku
//5 backups got created. 4 explicitly and one because a commit was called.
// Only the last two should still exist.
int count =0;
- Iterator<Path> iter = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*").iterator();
- while (iter.hasNext()) {
- iter.next();
- count ++;
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*")) {
+ Iterator<Path> iter = stream.iterator();
+ while (iter.hasNext()) {
+ iter.next();
+ count ++;
+ }
}
//There will be 2 backups, otherwise 1