Apache Solr open-source search software
SOLR-16903: Path: fixes for tests (#3300)
Matthew Biscochob832db750aab
diff --git a/solr/core/src/test/org/apache/solr/cli/ZkSubcommandsTest.java b/solr/core/src/test/org/apache/solr/cli/ZkSubcommandsTest.javaindex 4dc8a159b7a..6fce5e80127 100644--- a/solr/core/src/test/org/apache/solr/cli/ZkSubcommandsTest.java+++ b/solr/core/src/test/org/apache/solr/cli/ZkSubcommandsTest.java@@ -26,6 +26,7 @@ import java.nio.file.Path;import java.util.List;import java.util.concurrent.TimeUnit;import java.util.stream.Stream;+import org.apache.lucene.tests.mockfile.FilterPath;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.cloud.AbstractDistribZkTestBase;import org.apache.solr.cloud.AbstractZkTestCase;@@ -376,10 +377,11 @@ public class ZkSubcommandsTest extends SolrTestCaseJ4 {assertEquals(confsetname, collectionProps.getStr("configName"));// test down config- Path configSetDir =- tmpDir.resolve(- "solrtest-confdropspot-" + this.getClass().getName() + "-" + System.nanoTime());- assertFalse(Files.exists(configSetDir));+ Path destDir =+ FilterPath.unwrap(+ tmpDir.resolve(+ "solrtest-confdropspot-" + this.getClass().getName() + "-" + System.nanoTime()));+ assertFalse(Files.exists(destDir));args =new String[] {@@ -387,15 +389,14 @@ public class ZkSubcommandsTest extends SolrTestCaseJ4 {"--conf-name",confsetname,"--conf-dir",- configSetDir.toString(),+ destDir.toString(),"-z",zkServer.getZkAddress()};assertEquals(0, CLITestHelper.runTool(args, ConfigSetDownloadTool.class));- Path confSetDir = configSetDir.resolve("conf");- try (Stream<Path> filesStream = Files.list(confSetDir)) {+ try (Stream<Path> filesStream = Files.list(destDir.resolve("conf"))) {List<Path> files = filesStream.toList();zkFiles =zkClient.getChildren(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname, null, true);@@ -406,45 +407,35 @@ public class ZkSubcommandsTest extends SolrTestCaseJ4 {assertEquals("Comparing downloaded files to what is in ZK", files.size(), zkFiles.size());}- Path sourceConfDir = ExternalPaths.TECHPRODUCTS_CONFIGSET;- // filter out all directories starting with . (e.g. .svn)- try (Stream<Path> stream = Files.walk(sourceConfDir)) {- List<Path> files =- stream- .filter(Files::isRegularFile)- .filter(path -> path.getFileName().startsWith("."))- .toList();- files.forEach(- (sourceFile) -> {- int indexOfRelativePath =- sourceFile- .toString()- .lastIndexOf(- "sample_techproducts_configs"- + sourceFile.getFileSystem().getSeparator()- + "conf");- String relativePathofFile = sourceFile.toString().substring(indexOfRelativePath + 33);- Path downloadedFile = confDir.resolve(relativePathofFile);- if (ConfigSetService.UPLOAD_FILENAME_EXCLUDE_PATTERN- .matcher(relativePathofFile)- .matches()) {- assertFalse(- sourceFile + " exists in ZK, downloaded:" + downloadedFile,- Files.exists(downloadedFile));- } else {- assertTrue(- downloadedFile + " does not exist source:" + sourceFile,- Files.exists(downloadedFile));- try {- assertEquals(- relativePathofFile + " content changed",- -1,- Files.mismatch(sourceFile, downloadedFile));- } catch (IOException e) {- throw new RuntimeException(e);- }- }- });+ // compare the original source with the downloaded destination+ try (Stream<Path> stream = Files.walk(ExternalPaths.TECHPRODUCTS_CONFIGSET)) {+ stream+ .filter(Files::isRegularFile)+ .forEach(+ (sourceFile) -> {+ Path sourceFileRelative =+ ExternalPaths.TECHPRODUCTS_CONFIGSET.relativize(sourceFile);+ Path downloadedFile = destDir.resolve("conf").resolve(sourceFileRelative);+ if (ConfigSetService.UPLOAD_FILENAME_EXCLUDE_PATTERN+ .matcher(sourceFileRelative.toString())+ .matches()) {+ assertFalse(+ sourceFile + " exists in ZK, downloaded:" + downloadedFile,+ Files.exists(downloadedFile));+ } else {+ assertTrue(+ downloadedFile + " does not exist source:" + sourceFile,+ Files.exists(downloadedFile));+ try {+ assertEquals(+ sourceFileRelative + " content changed",+ -1,+ Files.mismatch(sourceFile, downloadedFile));+ } catch (IOException e) {+ throw new RuntimeException(e);+ }+ }+ });}// test reset zkdiff --git a/solr/core/src/test/org/apache/solr/cloud/MissingSegmentRecoveryTest.java b/solr/core/src/test/org/apache/solr/cloud/MissingSegmentRecoveryTest.javaindex 084bf5a254e..93610a7cff1 100644--- a/solr/core/src/test/org/apache/solr/cloud/MissingSegmentRecoveryTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/MissingSegmentRecoveryTest.java@@ -114,7 +114,9 @@ public class MissingSegmentRecoveryTest extends SolrCloudTestCase {cluster.getReplicaJetty(replica).getCoreContainer().getCore(replica.getCoreName())) {Path indexDir = Path.of(core.getDataDir(), "index");try (Stream<Path> files = Files.list(indexDir)) {- return files.filter((file) -> file.getFileName().startsWith("segments_")).toList();+ return files+ .filter((file) -> file.getFileName().toString().startsWith("segments_"))+ .toList();}}}diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.javaindex 29abe10f3e7..1a1d0ac3265 100644--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java@@ -1038,7 +1038,9 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {return (int)files.filter(- (file) -> Files.isDirectory(file) && !file.getFileName().startsWith("snapshot"))+ (file) ->+ Files.isDirectory(file)+ && !file.getFileName().toString().startsWith("snapshot")).count();}}diff --git a/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java b/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.javaindex e8ee01898d3..5357fc45e82 100644--- a/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java+++ b/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java@@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean;import java.util.concurrent.atomic.AtomicReference;import java.util.regex.Matcher;import java.util.regex.Pattern;+import java.util.stream.Collectors;import java.util.stream.Stream;import org.apache.lucene.index.DirectoryReader;import org.apache.lucene.index.Term;@@ -288,7 +289,7 @@ public class TestStressThreadBackup extends SolrCloudTestCase {numBackupsToCheck);try (Stream<Path> files = Files.list(backupDir)) {// insure consistent (arbitrary) ordering before shuffling- final List<Path> allBackups = files.sorted().toList();+ final List<Path> allBackups = files.sorted().collect(Collectors.toList());Collections.shuffle(allBackups, random());for (int i = 0; i < numBackupsToCheck; i++) {final Path backup = allBackups.get(i);diff --git a/solr/core/src/test/org/apache/solr/update/CustomTLogDirTest.java b/solr/core/src/test/org/apache/solr/update/CustomTLogDirTest.javaindex 1f575cc5406..c796c8356de 100644--- a/solr/core/src/test/org/apache/solr/update/CustomTLogDirTest.java+++ b/solr/core/src/test/org/apache/solr/update/CustomTLogDirTest.java@@ -53,7 +53,7 @@ public class CustomTLogDirTest extends SolrTestCaseJ4 {Path instanceDir = FilterPath.unwrap(coreRootDir.resolve(collectionName));- Path ulogDir = LuceneTestCase.createTempDir();+ Path ulogDir = FilterPath.unwrap(LuceneTestCase.createTempDir());// absolute path spec that falls outside of the instance and data dirs for the// associated core, is assumed to already by namespaced by purpose (tlog). We// expect it to be further namespaced by core name.diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.javaindex 0e156982941..991cd178f89 100644--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java@@ -1172,7 +1172,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {* is in place.*/protected void seedSolrHome(Path jettyHome) throws IOException {- PathUtils.copyDirectory(getSolrHome(), jettyHome);+ PathUtils.copyDirectory(getSolrHome(), jettyHome, StandardCopyOption.REPLACE_EXISTING);String solrxml = getSolrXml();if (solrxml != null) {Files.copy(