From 3cc22000f1b49606ba3dd88db659cd4b68837838 Mon Sep 17 00:00:00 2001 From: Hrishikesh Gadre Date: Wed, 3 Aug 2016 11:05:57 -0700 Subject: [PATCH] [SOLR-9242] Fix unit test failure on Windows platform. The URI.getPath() invocation on Windows platform generates an invalid URI. Refer to http://stackoverflow.com/questions/9834776/java-nio-file-path-issue Since the caller may have used this method to generate the string representation for the pathComponents, We implement a work-around specifically for Windows platform to remove the leading '/' character. --- .../repository/LocalFileSystemRepository.java | 15 ++++++++++++++- .../solr/cloud/TestLocalFSCloudBackupRestore.java | 3 +-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/backup/repository/LocalFileSystemRepository.java b/solr/core/src/java/org/apache/solr/core/backup/repository/LocalFileSystemRepository.java index 4eb77908c5a3..86c411059d8c 100644 --- a/solr/core/src/java/org/apache/solr/core/backup/repository/LocalFileSystemRepository.java +++ b/solr/core/src/java/org/apache/solr/core/backup/repository/LocalFileSystemRepository.java @@ -32,6 +32,7 @@ import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.NoLockFactory; import org.apache.lucene.store.SimpleFSDirectory; +import org.apache.lucene.util.Constants; import org.apache.solr.common.util.NamedList; import org.apache.solr.core.DirectoryFactory; @@ -59,10 +60,22 @@ public T getConfigProperty(String name) { @Override public URI createURI(String... pathComponents) { Preconditions.checkArgument(pathComponents.length > 0); - Path result = Paths.get(pathComponents[0]); + + String basePath = Preconditions.checkNotNull(pathComponents[0]); + // Note the URI.getPath() invocation on Windows platform generates an invalid URI. + // Refer to http://stackoverflow.com/questions/9834776/java-nio-file-path-issue + // Since the caller may have used this method to generate the string representation + // for the pathComponents, we implement a work-around specifically for Windows platform + // to remove the leading '/' character. + if (Constants.WINDOWS) { + basePath = basePath.replaceFirst("^/(.:/)", "$1"); + } + + Path result = Paths.get(basePath); for (int i = 1; i < pathComponents.length; i++) { result = result.resolve(pathComponents[i]); } + return result.toUri(); } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestLocalFSCloudBackupRestore.java b/solr/core/src/test/org/apache/solr/cloud/TestLocalFSCloudBackupRestore.java index c6f6a04bfed2..08bca21af622 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestLocalFSCloudBackupRestore.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestLocalFSCloudBackupRestore.java @@ -16,7 +16,6 @@ */ package org.apache.solr.cloud; -import org.apache.lucene.util.Constants; import org.junit.BeforeClass; /** @@ -28,7 +27,7 @@ public class TestLocalFSCloudBackupRestore extends AbstractCloudBackupRestoreTes @BeforeClass public static void setupClass() throws Exception { - assumeFalse("Backup/Restore is currently buggy on Windows. Tracking the fix on SOLR-9242", Constants.WINDOWS); + //assumeFalse("Backup/Restore is currently buggy on Windows. Tracking the fix on SOLR-9242", Constants.WINDOWS); configureCluster(NUM_SHARDS)// nodes .addConfig("conf1", TEST_PATH().resolve("configsets").resolve("cloud-minimal").resolve("conf")) .configure();