try to work on Windows too

This commit is contained in:
Michael McCandless 2015-08-28 04:13:21 -04:00 committed by mikemccand
parent 8dbc1fbdbd
commit b646ed9cd8
1 changed files with 23 additions and 20 deletions

View File

@ -18,6 +18,24 @@
*/ */
package org.elasticsearch.index.shard; 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.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.nio.file.FileStore; import java.nio.file.FileStore;
@ -35,23 +53,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; 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; import static org.elasticsearch.common.settings.Settings.settingsBuilder;
/** Separate test class from ShardPathTests because we need static (BeforeClass) setup to install mock filesystems... */ /** 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 aFileStore = new MockFileStore("mocka");
private static MockFileStore bFileStore = new MockFileStore("mockb"); private static MockFileStore bFileStore = new MockFileStore("mockb");
private static FileSystem origFileSystem; private static FileSystem origFileSystem;
private static String aPathPart = File.separator + 'a' + File.separator;
private static String bPathPart = File.separator + 'b' + File.separator;
@BeforeClass @BeforeClass
public static void installMockUsableSpaceFS() throws Exception { public static void installMockUsableSpaceFS() throws Exception {
@ -104,7 +107,7 @@ public class NewPathForShardTest extends ESTestCase {
@Override @Override
public FileStore getFileStore(Path path) throws IOException { public FileStore getFileStore(Path path) throws IOException {
if (path.toString().contains("/a/")) { if (path.toString().contains(aPathPart)) {
return aFileStore; return aFileStore;
} else { } else {
return bFileStore; return bFileStore;
@ -203,7 +206,7 @@ public class NewPathForShardTest extends ESTestCase {
ShardId shardId = new ShardId("index", 0); ShardId shardId = new ShardId("index", 0);
ShardPath result = ShardPath.selectNewPathForShard(nodeEnv, shardId, Settings.EMPTY, 100, Collections.<Path,Integer>emptyMap()); ShardPath result = ShardPath.selectNewPathForShard(nodeEnv, shardId, Settings.EMPTY, 100, Collections.<Path,Integer>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: // Test the reverse: b has lots of free space, but a has little, so new shard should go to b:
aFileStore.usableSpace = 1000; aFileStore.usableSpace = 1000;
@ -211,7 +214,7 @@ public class NewPathForShardTest extends ESTestCase {
shardId = new ShardId("index", 0); shardId = new ShardId("index", 0);
result = ShardPath.selectNewPathForShard(nodeEnv, shardId, Settings.EMPTY, 100, Collections.<Path,Integer>emptyMap()); result = ShardPath.selectNewPathForShard(nodeEnv, shardId, Settings.EMPTY, 100, Collections.<Path,Integer>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: // 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; aFileStore.usableSpace = 100000;