mirror of https://github.com/apache/lucene.git
SOLR-7156: Fix test failures due to resource leaks on windows
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1662174 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7e060ae688
commit
caf9037242
|
@ -188,6 +188,9 @@ Other Changes
|
||||||
|
|
||||||
* SOLR-7142: Fix TestFaceting.testFacets. (Michal Kroliczek via shalin)
|
* 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 ==================
|
================== 5.0.0 ==================
|
||||||
|
|
||||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||||
|
|
|
@ -18,12 +18,14 @@ package org.apache.solr.cloud;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import org.apache.lucene.mockfile.FilterPath;
|
import org.apache.lucene.mockfile.FilterPath;
|
||||||
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
|
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
|
||||||
import org.apache.solr.client.solrj.SolrClient;
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
|
@ -417,9 +419,10 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase {
|
||||||
checkBackupStatus.fetchStatus();
|
checkBackupStatus.fetchStatus();
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
ArrayList<Path> files = Lists.newArrayList(Files.newDirectoryStream(location, "snapshot*").iterator());
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(location, "snapshot*")) {
|
||||||
|
ArrayList<Path> files = Lists.newArrayList(stream.iterator());
|
||||||
assertEquals(Arrays.asList(files).toString(), 1, files.size());
|
assertEquals(Arrays.asList(files).toString(), 1, files.size());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
@ -130,18 +131,18 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Validate
|
//Validate
|
||||||
Path snapDir = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*").iterator().next();
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*")) {
|
||||||
verify(snapDir, nDocs);
|
Path snapDir = stream.iterator().next();
|
||||||
|
verify(snapDir, nDocs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verify(Path backup, int nDocs) throws IOException {
|
private void verify(Path backup, int nDocs) throws IOException {
|
||||||
try (Directory dir = new SimpleFSDirectory(backup)) {
|
try (Directory dir = new SimpleFSDirectory(backup);
|
||||||
IndexReader reader = DirectoryReader.open(dir);
|
IndexReader reader = DirectoryReader.open(dir)) {
|
||||||
IndexSearcher searcher = new IndexSearcher(reader);
|
IndexSearcher searcher = new IndexSearcher(reader);
|
||||||
TopDocs hits = searcher.search(new MatchAllDocsQuery(), 1);
|
TopDocs hits = searcher.search(new MatchAllDocsQuery(), 1);
|
||||||
assertEquals(nDocs, hits.totalHits);
|
assertEquals(nDocs, hits.totalHits);
|
||||||
reader.close();
|
|
||||||
dir.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +168,10 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
|
||||||
|
|
||||||
Path[] snapDir = new Path[5]; //One extra for the backup on commit
|
Path[] snapDir = new Path[5]; //One extra for the backup on commit
|
||||||
//First snapshot location
|
//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();
|
boolean namedBackup = random().nextBoolean();
|
||||||
String firstBackupTimestamp = null;
|
String firstBackupTimestamp = null;
|
||||||
|
|
||||||
|
@ -199,14 +203,19 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!namedBackup) {
|
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 {
|
} 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);
|
verify(snapDir[i+1], nDocs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Test Deletion of named backup
|
//Test Deletion of named backup
|
||||||
if (namedBackup) {
|
if (namedBackup) {
|
||||||
testDeleteNamedBackup(backupNames);
|
testDeleteNamedBackup(backupNames);
|
||||||
|
@ -214,10 +223,12 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
|
||||||
//5 backups got created. 4 explicitly and one because a commit was called.
|
//5 backups got created. 4 explicitly and one because a commit was called.
|
||||||
// Only the last two should still exist.
|
// Only the last two should still exist.
|
||||||
int count =0;
|
int count =0;
|
||||||
Iterator<Path> iter = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*").iterator();
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*")) {
|
||||||
while (iter.hasNext()) {
|
Iterator<Path> iter = stream.iterator();
|
||||||
iter.next();
|
while (iter.hasNext()) {
|
||||||
count ++;
|
iter.next();
|
||||||
|
count ++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//There will be 2 backups, otherwise 1
|
//There will be 2 backups, otherwise 1
|
||||||
|
|
Loading…
Reference in New Issue