Skip to content

Commit

Permalink
SolrTestCaseJ4 getFile() returns Path instead
Browse files Browse the repository at this point in the history
  • Loading branch information
mlbiscoc committed Dec 12, 2024
1 parent ac5f63e commit 58d52b7
Show file tree
Hide file tree
Showing 62 changed files with 114 additions and 166 deletions.
2 changes: 1 addition & 1 deletion solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void beforeClass() throws Exception {
FileUtils.touch(new File(tmpSolrHome, "core0/core.properties"));
FileUtils.touch(new File(tmpSolrHome, "core1/core.properties"));

Files.copy(getFile("solr/solr.xml").toPath(), Path.of(tmpSolrHome, "solr.xml"));
Files.copy(getFile("solr/solr.xml"), Path.of(tmpSolrHome, "solr.xml"));

initCore("solrconfig-minimal.xml", "schema-tiny.xml", tmpSolrHome, "core1");
}
Expand Down
6 changes: 3 additions & 3 deletions solr/core/src/test/org/apache/solr/cli/PostToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void testDoFilesMode() throws IOException {
postTool.recursive = 0;
postTool.dryRun = true;
postTool.solrUpdateUrl = URI.create("http://localhost:8983/solr/fake/update");
File dir = getFile("exampledocs");
File dir = getFile("exampledocs").toFile();
int num = postTool.postFiles(new String[] {dir.toString()}, 0, null, null);
assertEquals(2, num);
}
Expand All @@ -303,7 +303,7 @@ public void testDoFilesMode() throws IOException {
public void testDetectingIfRecursionPossibleInFilesMode() throws IOException {
PostTool postTool = new PostTool();
postTool.recursive = 1; // This is the default
File dir = getFile("exampledocs");
File dir = getFile("exampledocs").toFile();
File doc = File.createTempFile("temp", ".json");
assertTrue(postTool.recursionPossible(new String[] {dir.toString()}));
assertFalse(postTool.recursionPossible(new String[] {doc.toString()}));
Expand All @@ -316,7 +316,7 @@ public void testRecursionAppliesToFilesMode() throws IOException {
postTool.recursive = 1; // This is the default
postTool.dryRun = true;
postTool.solrUpdateUrl = URI.create("http://localhost:8983/solr/fake/update");
File dir = getFile("exampledocs");
File dir = getFile("exampledocs").toFile();
int num = postTool.postFiles(new String[] {dir.toString()}, 0, null, null);
assertEquals(2, num);
}
Expand Down
16 changes: 8 additions & 8 deletions solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void testCreateWithTrust() throws Exception {

private void setupBaseConfigSet(String baseConfigSetName, Map<String, String> oldProps)
throws Exception {
final Path configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf");
final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");
final Path tmpConfigDir = createTempDir();
tmpConfigDir.toFile().deleteOnExit();
PathUtils.copyDirectory(configDir, tmpConfigDir);
Expand Down Expand Up @@ -1518,7 +1518,7 @@ private long uploadBadConfigSet(String configSetName, String suffix, String user

// Read single file from sample configs. This should fail the unzipping
return uploadGivenConfigSet(
SolrTestCaseJ4.getFile("solr/configsets/upload/regular/solrconfig.xml"),
SolrTestCaseJ4.getFile("solr/configsets/upload/regular/solrconfig.xml").toFile(),
configSetName,
suffix,
username,
Expand Down Expand Up @@ -1587,7 +1587,7 @@ private long uploadSingleConfigSetFile(
boolean v2)
throws IOException {
// Read single file from sample configs
final File file = SolrTestCaseJ4.getFile(localFilePath);
final File file = SolrTestCaseJ4.getFile(localFilePath).toFile();

if (v2) {
// TODO: switch to use V2Request
Expand Down Expand Up @@ -1640,7 +1640,7 @@ private long uploadSingleConfigSetFile(
private File createTempZipFile(String directoryPath) {
try {
final File zipFile = createTempFile("configset", "zip").toFile();
final File directory = SolrTestCaseJ4.getFile(directoryPath);
final File directory = SolrTestCaseJ4.getFile(directoryPath).toFile();
if (log.isInfoEnabled()) {
log.info("Directory: {}", directory.getAbsolutePath());
}
Expand All @@ -1661,7 +1661,7 @@ private File createTempZipFile(String directoryPath) {
private File createTempZipFileWithForbiddenTypes(String file) {
try {
final File zipFile = createTempFile("configset", "zip").toFile();
final File directory = SolrTestCaseJ4.getFile(file);
final File directory = SolrTestCaseJ4.getFile(file).toFile();
if (log.isInfoEnabled()) {
log.info("Directory: {}", directory.getAbsolutePath());
}
Expand All @@ -1679,7 +1679,7 @@ private File createTempZipFileWithForbiddenTypes(String file) {
private File createTempZipFileWithForbiddenContent(String resourcePath) {
try {
final File zipFile = createTempFile("configset", "zip").toFile();
final File directory = SolrTestCaseJ4.getFile(resourcePath);
final File directory = SolrTestCaseJ4.getFile(resourcePath).toFile();
if (log.isInfoEnabled()) {
log.info("Directory: {}", directory.getAbsolutePath());
}
Expand Down Expand Up @@ -1850,7 +1850,7 @@ private static Object getObjectByPath(Map<?, ?> root, List<String> hierarchy) {

private byte[] readFile(String fname) throws IOException {
byte[] buf = null;
try (FileInputStream fis = new FileInputStream(getFile(fname))) {
try (FileInputStream fis = new FileInputStream(getFile(fname).toFile())) {
buf = new byte[fis.available()];
fis.read(buf);
}
Expand All @@ -1861,7 +1861,7 @@ private byte[] readFile(String fname) throws IOException {
public void testDeleteErrors() throws Exception {
final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
final Path configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf");
final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");
final Path tmpConfigDir = createTempDir();
tmpConfigDir.toFile().deleteOnExit();
// Ensure ConfigSet is immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testCreateZkFailure() throws Exception {

private void setupBaseConfigSet(String baseConfigSetName, Map<String, String> oldProps)
throws Exception {
final Path configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf");
final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");
final Path tmpConfigDir = createTempDir();
tmpConfigDir.toFile().deleteOnExit();
PathUtils.copyDirectory(configDir, tmpConfigDir);
Expand Down
7 changes: 4 additions & 3 deletions solr/core/src/test/org/apache/solr/core/TestConfigSets.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public void testConfigSetServiceFindsConfigSets() {

@Test
public void testNonExistentConfigSetThrowsException() {
final CoreContainer container = setupContainer(getFile("solr/configsets").getAbsolutePath());
final CoreContainer container =
setupContainer(getFile("solr/configsets").toAbsolutePath().toString());
try {
Exception thrown =
expectThrows(
Expand All @@ -112,7 +113,7 @@ public void testConfigSetOnCoreReload() throws IOException {
Path testDirectory = createTempDir("core-reload");
Path configSetsDir = testDirectory.resolve("configsets");

PathUtils.copyDirectory(getFile("solr/configsets").toPath(), configSetsDir);
PathUtils.copyDirectory(getFile("solr/configsets"), configSetsDir);

String csd = configSetsDir.toAbsolutePath().toString();
System.setProperty("configsets", csd);
Expand All @@ -129,7 +130,7 @@ public void testConfigSetOnCoreReload() throws IOException {

// Now copy in a config with a /dump handler and reload
Files.copy(
getFile("solr/collection1/conf/solrconfig-withgethandler.xml").toPath(),
getFile("solr/collection1/conf/solrconfig-withgethandler.xml"),
configSetsDir.resolve("configset-2/conf").resolve("solrconfig.xml"),
StandardCopyOption.REPLACE_EXISTING);
container.reload("core1");
Expand Down
12 changes: 6 additions & 6 deletions solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() {
oldSolrHome = System.getProperty(SOLR_HOME_PROP);
System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
System.setProperty("configsets", getFile("solr/configsets").toAbsolutePath().toString());
}

@AfterClass
Expand Down Expand Up @@ -320,7 +320,7 @@ public void testDeleteBadCores() {
MockCoresLocator cl = new MockCoresLocator();

Path solrHome = createTempDir();
System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
System.setProperty("configsets", getFile("solr/configsets").toAbsolutePath().toString());

final CoreContainer cc =
new CoreContainer(SolrXmlConfig.fromString(solrHome, CONFIGSETS_SOLR_XML), cl);
Expand Down Expand Up @@ -939,7 +939,7 @@ public void testCoreInitFailuresOnReload() throws Exception {

Path solrHome = createTempDir();

System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
System.setProperty("configsets", getFile("solr/configsets").toAbsolutePath().toString());

final CoreContainer cc =
new CoreContainer(SolrXmlConfig.fromString(solrHome, CONFIGSETS_SOLR_XML), cl);
Expand Down Expand Up @@ -986,11 +986,11 @@ public void testCoreInitFailuresOnReload() throws Exception {
Path confDir = Path.of(cc.getSolrHome(), "col_bad", "conf");
Files.createDirectories(confDir);
Files.copy(
getFile("solr/collection1/conf/solrconfig-defaults.xml").toPath(),
getFile("solr/collection1/conf/solrconfig-defaults.xml"),
confDir.resolve("solrconfig.xml"),
StandardCopyOption.REPLACE_EXISTING);
Files.copy(
getFile("solr/collection1/conf/schema-minimal.xml").toPath(),
getFile("solr/collection1/conf/schema-minimal.xml"),
confDir.resolve("schema.xml"),
StandardCopyOption.REPLACE_EXISTING);
cc.create("col_bad", Map.of());
Expand Down Expand Up @@ -1107,7 +1107,7 @@ public void testCoreInitFailuresOnReload() throws Exception {
// ----
// fix col_bad's config (again) and RELOAD to fix failure
Files.copy(
getFile("solr/collection1/conf/solrconfig-defaults.xml").toPath(),
getFile("solr/collection1/conf/solrconfig-defaults.xml"),
confDir.resolve("solrconfig.xml"),
StandardCopyOption.REPLACE_EXISTING);
cc.reload("col_bad");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static ByteBuffer getFileContent(String f) throws IOException {
*/
public static ByteBuffer getFileContent(String f, boolean loadFromClassPath) throws IOException {
ByteBuffer jar;
File file = loadFromClassPath ? getFile(f) : new File(f);
File file = loadFromClassPath ? getFile(f).toFile() : new File(f);
try (FileInputStream fis = new FileInputStream(file)) {
byte[] buf = new byte[fis.available()];
// TODO: This should check that we read the entire stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public static int index(SolrClient s, Object... fields) throws Exception {
* character copy of file using UTF-8. If port is non-null, will be substituted any time
* "TEST_PORT" is found.
*/
private static void copyFile(File src, File dst, Integer port, boolean internalCompression)
private static void copyFile(Path src, File dst, Integer port, boolean internalCompression)
throws IOException {
try (BufferedReader in = Files.newBufferedReader(src.toPath(), StandardCharsets.UTF_8);
try (BufferedReader in = Files.newBufferedReader(src, StandardCharsets.UTF_8);
Writer out = Files.newBufferedWriter(dst.toPath(), StandardCharsets.UTF_8)) {
for (String line = in.readLine(); null != line; line = in.readLine()) {
if (null != port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testRequestParams() throws Exception {

@Test
public void testExternalEntities() throws Exception {
String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
String file = getFile("mailing_lists.pdf").toUri().toASCIIString();
String xml =
"<?xml version=\"1.0\"?>"
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void testAddedMBeanDiff() throws Exception {

@Test
public void testXMLDiffWithExternalEntity() {
String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
String file = getFile("mailing_lists.pdf").toUri().toASCIIString();
String xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE foo [<!ENTITY bar SYSTEM \""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,7 @@ public void testBasicUserWorkflow() throws Exception {

req = mock(SolrQueryRequest.class);
when(req.getParams()).thenReturn(reqParams);
stream =
new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json").toPath());
stream = new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json"));
stream.setContentType(JSON_MIME);
when(req.getContentStreams()).thenReturn(Collections.singletonList(stream));
rsp = new SolrQueryResponse();
Expand All @@ -575,9 +574,7 @@ public void testBasicUserWorkflow() throws Exception {
when(req.getParams()).thenReturn(reqParams);
// switch a single-valued field to a multi-valued field, which triggers a full rebuild of the
// "temp" collection
stream =
new ContentStreamBase.FileStream(
getFile("schema-designer/update-author-field.json").toPath());
stream = new ContentStreamBase.FileStream(getFile("schema-designer/update-author-field.json"));
stream.setContentType(JSON_MIME);
when(req.getContentStreams()).thenReturn(Collections.singletonList(stream));

Expand All @@ -595,8 +592,7 @@ public void testBasicUserWorkflow() throws Exception {

req = mock(SolrQueryRequest.class);
when(req.getParams()).thenReturn(reqParams);
stream =
new ContentStreamBase.FileStream(getFile("schema-designer/add-new-type.json").toPath());
stream = new ContentStreamBase.FileStream(getFile("schema-designer/add-new-type.json"));
stream.setContentType(JSON_MIME);
when(req.getContentStreams()).thenReturn(Collections.singletonList(stream));
rsp = new SolrQueryResponse();
Expand All @@ -622,7 +618,7 @@ public void testBasicUserWorkflow() throws Exception {

req = mock(SolrQueryRequest.class);
when(req.getParams()).thenReturn(reqParams);
stream = new ContentStreamBase.FileStream(getFile("schema-designer/update-type.json").toPath());
stream = new ContentStreamBase.FileStream(getFile("schema-designer/update-type.json"));
stream.setContentType(JSON_MIME);
when(req.getContentStreams()).thenReturn(Collections.singletonList(stream));
rsp = new SolrQueryResponse();
Expand Down Expand Up @@ -718,7 +714,7 @@ public void testFieldUpdates() throws Exception {
req = mock(SolrQueryRequest.class);
when(req.getParams()).thenReturn(reqParams);
ContentStreamBase.FileStream stream =
new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json").toPath());
new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json"));
stream.setContentType(JSON_MIME);
when(req.getContentStreams()).thenReturn(Collections.singletonList(stream));
rsp = new SolrQueryResponse();
Expand Down Expand Up @@ -864,7 +860,7 @@ public void testSchemaDiffEndpoint() throws Exception {
Integer schemaVersion = rsp.getValues().toSolrParams().getInt(SCHEMA_VERSION_PARAM);
reqParams.set(SCHEMA_VERSION_PARAM, schemaVersion);
ContentStreamBase.FileStream fileStream =
new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json").toPath());
new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json"));
fileStream.setContentType(JSON_MIME);
when(req.getContentStreams()).thenReturn(Collections.singletonList(fileStream));
rsp = new SolrQueryResponse();
Expand All @@ -875,8 +871,7 @@ public void testSchemaDiffEndpoint() throws Exception {
// Add a new field type
schemaVersion = rsp.getValues().toSolrParams().getInt(SCHEMA_VERSION_PARAM);
reqParams.set(SCHEMA_VERSION_PARAM, schemaVersion);
fileStream =
new ContentStreamBase.FileStream(getFile("schema-designer/add-new-type.json").toPath());
fileStream = new ContentStreamBase.FileStream(getFile("schema-designer/add-new-type.json"));
fileStream.setContentType(JSON_MIME);
when(req.getContentStreams()).thenReturn(Collections.singletonList(fileStream));
rsp = new SolrQueryResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class PackageStoreSchemaPluginsTest extends SolrCloudTestCase {
}
}

private final Path pluginJarPath = getFile("runtimecode/schema-plugins.jar.bin").toPath();
private final Path bogusJarPath = getFile("runtimecode/runtimelibs.jar.bin").toPath();
private final Path pluginJarPath = getFile("runtimecode/schema-plugins.jar.bin");
private final Path bogusJarPath = getFile("runtimecode/runtimelibs.jar.bin");

private SolrClient client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class ExternalFileFieldSortTest extends SolrTestCaseJ4 {

static void updateExternalFile() throws IOException {
final String testHome = SolrTestCaseJ4.getFile("solr/collection1").getParent();
final String testHome = SolrTestCaseJ4.getFile("solr/collection1").getParent().toString();
String filename = "external_eff";
Files.copy(Path.of(testHome, filename), Path.of(h.getCore().getDataDir(), filename));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,11 @@ public static String setupSolrHome() throws Exception {

// copy over configuration files
Files.copy(
getFile("solr/collection1/conf/solrconfig-basic.xml").toPath(),
confDir.resolve("solrconfig.xml"));
getFile("solr/collection1/conf/solrconfig-basic.xml"), confDir.resolve("solrconfig.xml"));
Files.copy(
getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml").toPath(),
getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml"),
confDir.resolve("solrconfig.snippet.randomindexconfig.xml"));
Files.copy(
getFile("solr/collection1/conf/schema-collate.xml").toPath(),
confDir.resolve("schema.xml"));
Files.copy(getFile("solr/collection1/conf/schema-collate.xml"), confDir.resolve("schema.xml"));

// generate custom collation rules (DIN 5007-2), saving to customrules.dat
RuleBasedCollator baseCollator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ public static String setupSolrHome() throws Exception {

// copy over configuration files
Files.copy(
getFile("solr/collection1/conf/solrconfig-basic.xml").toPath(),
confDir.resolve("solrconfig.xml"));
getFile("solr/collection1/conf/solrconfig-basic.xml"), confDir.resolve("solrconfig.xml"));
Files.copy(
getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml").toPath(),
getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml"),
confDir.resolve("solrconfig.snippet.randomindexconfig.xml"));
Files.copy(
getFile("solr/collection1/conf/schema-collate-dv.xml").toPath(),
confDir.resolve("schema.xml"));
getFile("solr/collection1/conf/schema-collate-dv.xml"), confDir.resolve("schema.xml"));

// generate custom collation rules (DIN 5007-2), saving to customrules.dat
RuleBasedCollator baseCollator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void testStreamURL() throws Exception {
@Test
@SuppressWarnings({"try"})
public void testStreamFile() throws Exception {
Path file = getFile("README").toPath();
Path file = getFile("README");

byte[] bytes = Files.readAllBytes(file);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void assertEntityResolving(
}

public void testResolving() throws Exception {
final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParentFile().toPath();
final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParent();
final ResourceLoader loader =
new SolrResourceLoader(testHome.resolve("collection1"), this.getClass().getClassLoader());
final SystemIdResolver resolver = new SystemIdResolver(loader);
Expand Down Expand Up @@ -131,7 +131,7 @@ public void testResolving() throws Exception {
public void testUnsafeResolving() throws Exception {
System.setProperty(SolrResourceLoader.SOLR_ALLOW_UNSAFE_RESOURCELOADING_PARAM, "true");

final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParentFile().toPath();
final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParent();
final ResourceLoader loader =
new SolrResourceLoader(testHome.resolve("collection1"), this.getClass().getClassLoader());
final SystemIdResolver resolver = new SystemIdResolver(loader);
Expand Down
Loading

0 comments on commit 58d52b7

Please sign in to comment.