From b646ed9cd8ab021e694135963a037c6843c58886 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Fri, 28 Aug 2015 04:13:21 -0400 Subject: [PATCH] try to work on Windows too --- .../index/shard/NewPathForShardTest.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTest.java b/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTest.java index 5cb618ad084..61e4924c32f 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTest.java +++ b/core/src/test/java/org/elasticsearch/index/shard/NewPathForShardTest.java @@ -18,6 +18,24 @@ */ package org.elasticsearch.index.shard; +import com.carrotsearch.randomizedtesting.annotations.Repeat; + +import org.apache.lucene.mockfile.FilterFileSystem; +import org.apache.lucene.mockfile.FilterFileSystemProvider; +import org.apache.lucene.mockfile.FilterPath; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.SuppressForbidden; +import org.elasticsearch.common.io.PathUtils; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.env.NodeEnvironment.NodePath; +import org.elasticsearch.env.NodeEnvironment; +import org.elasticsearch.test.ESTestCase; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.nio.file.FileStore; @@ -35,23 +53,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.lucene.mockfile.FilterFileSystem; -import org.apache.lucene.mockfile.FilterFileSystemProvider; -import org.apache.lucene.mockfile.FilterPath; -import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.SuppressForbidden; -import org.elasticsearch.common.io.PathUtils; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.Environment; -import org.elasticsearch.env.NodeEnvironment.NodePath; -import org.elasticsearch.env.NodeEnvironment; -import org.elasticsearch.test.ESTestCase; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.carrotsearch.randomizedtesting.annotations.Repeat; - import static org.elasticsearch.common.settings.Settings.settingsBuilder; /** Separate test class from ShardPathTests because we need static (BeforeClass) setup to install mock filesystems... */ @@ -62,6 +63,8 @@ public class NewPathForShardTest extends ESTestCase { private static MockFileStore aFileStore = new MockFileStore("mocka"); private static MockFileStore bFileStore = new MockFileStore("mockb"); private static FileSystem origFileSystem; + private static String aPathPart = File.separator + 'a' + File.separator; + private static String bPathPart = File.separator + 'b' + File.separator; @BeforeClass public static void installMockUsableSpaceFS() throws Exception { @@ -104,7 +107,7 @@ public class NewPathForShardTest extends ESTestCase { @Override public FileStore getFileStore(Path path) throws IOException { - if (path.toString().contains("/a/")) { + if (path.toString().contains(aPathPart)) { return aFileStore; } else { return bFileStore; @@ -203,7 +206,7 @@ public class NewPathForShardTest extends ESTestCase { ShardId shardId = new ShardId("index", 0); ShardPath result = ShardPath.selectNewPathForShard(nodeEnv, shardId, Settings.EMPTY, 100, Collections.emptyMap()); - assertTrue(result.getDataPath().toString().contains("/a/")); + assertTrue(result.getDataPath().toString().contains(aPathPart)); // Test the reverse: b has lots of free space, but a has little, so new shard should go to b: aFileStore.usableSpace = 1000; @@ -211,7 +214,7 @@ public class NewPathForShardTest extends ESTestCase { shardId = new ShardId("index", 0); result = ShardPath.selectNewPathForShard(nodeEnv, shardId, Settings.EMPTY, 100, Collections.emptyMap()); - assertTrue(result.getDataPath().toString().contains("/b/")); + assertTrue(result.getDataPath().toString().contains(bPathPart)); // Now a and be have equal usable space; we allocate two shards to the node, and each should go to different paths: aFileStore.usableSpace = 100000;