From a3120987856adf04fb15e4ff8ededeca1c5657d0 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 17 Apr 2015 21:09:53 -0400 Subject: [PATCH] nuke duplicate methods --- .../OldIndexBackwardsCompatibilityTests.java | 4 +- .../transport/TransportClientTests.java | 2 +- .../RoutingBackwardCompatibilityTests.java | 2 +- .../BalanceUnbalancedClusterTest.java | 2 +- .../elasticsearch/common/ChannelsTests.java | 2 +- .../elasticsearch/common/PidFileTests.java | 4 +- .../common/blobstore/BlobStoreTest.java | 2 +- .../common/bytes/PagedBytesReferenceTest.java | 4 +- .../common/io/FileSystemUtilsTests.java | 8 +-- .../log4j/LoggingConfigurationTests.java | 8 +-- .../elasticsearch/env/EnvironmentTests.java | 2 +- .../env/NodeEnvironmentTests.java | 6 +- .../gateway/MetaDataStateFormatTest.java | 18 +++--- .../gateway/RecoveryFromGatewayTests.java | 4 +- .../index/IndexWithShadowReplicasTests.java | 16 ++--- .../index/analysis/AnalysisModuleTests.java | 2 +- .../index/mapper/FileBasedMappingsTests.java | 4 +- .../index/store/CorruptedFileTest.java | 2 +- .../store/distributor/DistributorTests.java | 2 +- .../translog/AbstractSimpleTranslogTests.java | 2 +- .../indices/IndicesCustomDataPathTests.java | 4 +- .../IndexTemplateFileLoadingTests.java | 2 +- .../plugins/PluginManagerTests.java | 2 +- .../plugins/PluginManagerUnitTests.java | 4 +- .../script/ScriptServiceTests.java | 2 +- .../DedicatedClusterSnapshotRestoreTests.java | 18 +++--- .../snapshots/RepositoriesTests.java | 16 ++--- .../SharedClusterSnapshotRestoreTests.java | 60 +++++++++---------- .../SnapshotBackwardsCompatibilityTest.java | 4 +- .../test/ElasticsearchIntegrationTest.java | 12 +--- .../test/ElasticsearchTestCase.java | 43 +------------ .../test/rest/test/FileUtilsTests.java | 2 +- .../test/test/InternalTestClusterTests.java | 4 +- .../watcher/FileWatcherTest.java | 14 ++--- 34 files changed, 119 insertions(+), 164 deletions(-) diff --git a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java index 8e563877207..ca997266250 100644 --- a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java @@ -112,7 +112,7 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio void setupCluster() throws Exception { ListenableFuture> replicas = internalCluster().startNodesAsync(1); // for replicas - Path baseTempDir = newTempDirPath(); + Path baseTempDir = createTempDir(); // start single data path node ImmutableSettings.Builder nodeSettings = ImmutableSettings.builder() .put("path.data", baseTempDir.resolve("single-path").toAbsolutePath()) @@ -148,7 +148,7 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio } String loadIndex(String indexFile) throws Exception { - Path unzipDir = newTempDirPath(); + Path unzipDir = createTempDir(); Path unzipDataDir = unzipDir.resolve("data"); String indexName = indexFile.replace(".zip", "").toLowerCase(Locale.ROOT); diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java index d94d351d34b..dcf35d2dff6 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java @@ -54,7 +54,7 @@ public class TransportClientTests extends ElasticsearchIntegrationTest { TransportClientNodesService nodeService = client.nodeService(); Node node = nodeBuilder().data(false).settings(ImmutableSettings.builder() .put(internalCluster().getDefaultSettings()) - .put("path.home", newTempDirPath()) + .put("path.home", createTempDir()) .put("node.name", "testNodeVersionIsUpdated") .put("http.enabled", false) .put("index.store.type", "ram") diff --git a/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java b/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java index fb1ac5922eb..247ef928d19 100644 --- a/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java +++ b/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java @@ -38,7 +38,7 @@ import java.util.Arrays; public class RoutingBackwardCompatibilityTests extends ElasticsearchTestCase { public void testBackwardCompatibility() throws Exception { - Path baseDir = newTempDirPath(); + Path baseDir = createTempDir(); Node node = new Node(ImmutableSettings.builder().put("path.home", baseDir.toString()).build(), false); try { try (BufferedReader reader = new BufferedReader(new InputStreamReader(RoutingBackwardCompatibilityTests.class.getResourceAsStream("/org/elasticsearch/cluster/routing/shard_routes.txt"), "UTF-8"))) { diff --git a/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTest.java b/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTest.java index 0185a7c0204..1c472a920f6 100644 --- a/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTest.java +++ b/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTest.java @@ -44,7 +44,7 @@ public class BalanceUnbalancedClusterTest extends CatAllocationTestBase { @Override protected Path getCatPath() throws IOException { - Path tmp = newTempDirPath(); + Path tmp = createTempDir(); try (InputStream stream = Files.newInputStream(getDataPath("/org/elasticsearch/cluster/routing/issue_9023.zip"))) { TestUtil.unzip(stream, tmp); } diff --git a/src/test/java/org/elasticsearch/common/ChannelsTests.java b/src/test/java/org/elasticsearch/common/ChannelsTests.java index e1061ea3073..2fae109a6aa 100644 --- a/src/test/java/org/elasticsearch/common/ChannelsTests.java +++ b/src/test/java/org/elasticsearch/common/ChannelsTests.java @@ -53,7 +53,7 @@ public class ChannelsTests extends ElasticsearchTestCase { @Before public void setUp() throws Exception { super.setUp(); - Path tmpFile = newTempFilePath(); + Path tmpFile = createTempFile(); FileChannel randomAccessFile = FileChannel.open(tmpFile, StandardOpenOption.READ, StandardOpenOption.WRITE); fileChannel = new MockFileChannel(randomAccessFile); randomBytes = randomUnicodeOfLength(scaledRandomIntBetween(10, 100000)).getBytes("UTF-8"); diff --git a/src/test/java/org/elasticsearch/common/PidFileTests.java b/src/test/java/org/elasticsearch/common/PidFileTests.java index d022ab2177a..0c66b411c60 100644 --- a/src/test/java/org/elasticsearch/common/PidFileTests.java +++ b/src/test/java/org/elasticsearch/common/PidFileTests.java @@ -37,7 +37,7 @@ public class PidFileTests extends ElasticsearchTestCase { @Test(expected = ElasticsearchIllegalArgumentException.class) public void testParentIsFile() throws IOException { - Path dir = newTempDirPath(); + Path dir = createTempDir(); Path parent = dir.resolve("foo"); try(BufferedWriter stream = Files.newBufferedWriter(parent, Charsets.UTF_8, StandardOpenOption.CREATE_NEW)) { stream.write("foo"); @@ -48,7 +48,7 @@ public class PidFileTests extends ElasticsearchTestCase { @Test public void testPidFile() throws IOException { - Path dir = newTempDirPath(); + Path dir = createTempDir(); Path parent = dir.resolve("foo"); if (randomBoolean()) { Files.createDirectories(parent); diff --git a/src/test/java/org/elasticsearch/common/blobstore/BlobStoreTest.java b/src/test/java/org/elasticsearch/common/blobstore/BlobStoreTest.java index 5facbf0a045..10fd9ef1405 100644 --- a/src/test/java/org/elasticsearch/common/blobstore/BlobStoreTest.java +++ b/src/test/java/org/elasticsearch/common/blobstore/BlobStoreTest.java @@ -141,7 +141,7 @@ public class BlobStoreTest extends ElasticsearchTestCase { } protected BlobStore newBlobStore() throws IOException { - Path tempDir = newTempDirPath(); + Path tempDir = createTempDir(); Settings settings = randomBoolean() ? ImmutableSettings.EMPTY : ImmutableSettings.builder().put("buffer_size", new ByteSizeValue(randomIntBetween(1, 100), ByteSizeUnit.KB)).build(); FsBlobStore store = new FsBlobStore(settings, tempDir); return store; diff --git a/src/test/java/org/elasticsearch/common/bytes/PagedBytesReferenceTest.java b/src/test/java/org/elasticsearch/common/bytes/PagedBytesReferenceTest.java index 6ae5696f804..586d78ce538 100644 --- a/src/test/java/org/elasticsearch/common/bytes/PagedBytesReferenceTest.java +++ b/src/test/java/org/elasticsearch/common/bytes/PagedBytesReferenceTest.java @@ -263,7 +263,7 @@ public class PagedBytesReferenceTest extends ElasticsearchTestCase { public void testWriteToChannel() throws IOException { int length = randomIntBetween(10, PAGE_SIZE * 4); BytesReference pbr = getRandomizedPagedBytesReference(length); - Path tFile = newTempFilePath(); + Path tFile = createTempFile(); try (FileChannel channel = FileChannel.open(tFile, StandardOpenOption.WRITE)) { pbr.writeTo(channel); assertEquals(pbr.length(), channel.position()); @@ -290,7 +290,7 @@ public class PagedBytesReferenceTest extends ElasticsearchTestCase { int sliceOffset = randomIntBetween(1, length / 2); int sliceLength = length - sliceOffset; BytesReference slice = pbr.slice(sliceOffset, sliceLength); - Path tFile = newTempFilePath(); + Path tFile = createTempFile(); try (FileChannel channel = FileChannel.open(tFile, StandardOpenOption.WRITE)) { slice.writeTo(channel); assertEquals(slice.length(), channel.position()); diff --git a/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java b/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java index 6d3d0c20389..aa8c56cc97a 100644 --- a/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java +++ b/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java @@ -49,8 +49,8 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { @Before public void copySourceFilesToTarget() throws IOException, URISyntaxException { - src = newTempDirPath(); - dst = newTempDirPath(); + src = createTempDir(); + dst = createTempDir(); Files.createDirectories(src); Files.createDirectories(dst); @@ -89,7 +89,7 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { @Test public void testMoveOverExistingFileAndIgnore() throws IOException { - Path dest = newTempDirPath(); + Path dest = createTempDir(); FileSystemUtils.moveFilesWithoutOverwriting(src.resolve("v1"), dest, null); assertFileContent(dest, "file1.txt", "version1"); @@ -117,7 +117,7 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { @Test public void testMoveFilesDoesNotCreateSameFileWithSuffix() throws Exception { - Path[] dirs = new Path[] { newTempDirPath(), newTempDirPath(), newTempDirPath()}; + Path[] dirs = new Path[] { createTempDir(), createTempDir(), createTempDir()}; for (Path dir : dirs) { Files.write(dir.resolve("file1.txt"), "file1".getBytes(Charsets.UTF_8)); Files.createDirectory(dir.resolve("dir")); diff --git a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java index 50bc90b6dbf..b53b434a492 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java @@ -83,7 +83,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { @Test public void testResolveJsonLoggingConfig() throws Exception { - Path tmpDir = newTempDirPath(); + Path tmpDir = createTempDir(); Path loggingConf = tmpDir.resolve(loggingConfiguration("json")); Files.write(loggingConf, "{\"json\": \"foo\"}".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( @@ -98,7 +98,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { @Test public void testResolvePropertiesLoggingConfig() throws Exception { - Path tmpDir = newTempDirPath(); + Path tmpDir = createTempDir(); Path loggingConf = tmpDir.resolve(loggingConfiguration("properties")); Files.write(loggingConf, "key: value".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( @@ -113,7 +113,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { @Test public void testResolveYamlLoggingConfig() throws Exception { - Path tmpDir = newTempDirPath(); + Path tmpDir = createTempDir(); Path loggingConf1 = tmpDir.resolve(loggingConfiguration("yml")); Path loggingConf2 = tmpDir.resolve(loggingConfiguration("yaml")); Files.write(loggingConf1, "yml: bar".getBytes(StandardCharsets.UTF_8)); @@ -131,7 +131,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { @Test public void testResolveConfigInvalidFilename() throws Exception { - Path tmpDir = newTempDirPath(); + Path tmpDir = createTempDir(); Path invalidSuffix = tmpDir.resolve(loggingConfiguration(randomFrom(LogConfigurator.ALLOWED_SUFFIXES)) + randomInvalidSuffix()); Files.write(invalidSuffix, "yml: bar".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( diff --git a/src/test/java/org/elasticsearch/env/EnvironmentTests.java b/src/test/java/org/elasticsearch/env/EnvironmentTests.java index ebbaeab3dac..31785e6f7ea 100644 --- a/src/test/java/org/elasticsearch/env/EnvironmentTests.java +++ b/src/test/java/org/elasticsearch/env/EnvironmentTests.java @@ -42,7 +42,7 @@ public class EnvironmentTests extends ElasticsearchTestCase { public Environment newEnvironment(Settings settings) throws IOException { Settings build = ImmutableSettings.builder() .put(settings) - .put("path.home", newTempDirPath().toAbsolutePath()) + .put("path.home", createTempDir().toAbsolutePath()) .putArray("path.data", tmpPaths()).build(); return new Environment(build); } diff --git a/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java b/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java index 68fb6aa0e18..cee1f2e9fd6 100644 --- a/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java +++ b/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java @@ -355,7 +355,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { final int numPaths = randomIntBetween(1, 3); final String[] absPaths = new String[numPaths]; for (int i = 0; i < numPaths; i++) { - absPaths[i] = newTempDirPath().toAbsolutePath().toString(); + absPaths[i] = createTempDir().toAbsolutePath().toString(); } return absPaths; } @@ -369,7 +369,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { public NodeEnvironment newNodeEnvironment(Settings settings) throws IOException { Settings build = ImmutableSettings.builder() .put(settings) - .put("path.home", newTempDirPath().toAbsolutePath().toString()) + .put("path.home", createTempDir().toAbsolutePath().toString()) .put(NodeEnvironment.SETTING_CUSTOM_DATA_PATH_ENABLED, true) .putArray("path.data", tmpPaths()).build(); return new NodeEnvironment(build, new Environment(build)); @@ -378,7 +378,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { public NodeEnvironment newNodeEnvironment(String[] dataPaths, Settings settings) throws IOException { Settings build = ImmutableSettings.builder() .put(settings) - .put("path.home", newTempDirPath().toAbsolutePath().toString()) + .put("path.home", createTempDir().toAbsolutePath().toString()) .put(NodeEnvironment.SETTING_CUSTOM_DATA_PATH_ENABLED, true) .putArray("path.data", dataPaths).build(); return new NodeEnvironment(build, new Environment(build)); diff --git a/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTest.java b/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTest.java index 91ebe99eeb8..5581290d0e5 100644 --- a/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTest.java +++ b/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTest.java @@ -92,7 +92,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { return MetaData.Builder.fromXContent(parser); } }; - Path tmp = newTempDirPath(); + Path tmp = createTempDir(); final InputStream resource = this.getClass().getResourceAsStream("global-3.st"); assertThat(resource, notNullValue()); Path dst = tmp.resolve("global-3.st"); @@ -106,7 +106,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { public void testReadWriteState() throws IOException { Path[] dirs = new Path[randomIntBetween(1, 5)]; for (int i = 0; i < dirs.length; i++) { - dirs[i] = newTempDirPath(); + dirs[i] = createTempDir(); } final long id = addDummyFiles("foo-", dirs); Format format = new Format(randomFrom(XContentType.values()), "foo-"); @@ -148,7 +148,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { public void testVersionMismatch() throws IOException { Path[] dirs = new Path[randomIntBetween(1, 5)]; for (int i = 0; i < dirs.length; i++) { - dirs[i] = newTempDirPath(); + dirs[i] = createTempDir(); } final long id = addDummyFiles("foo-", dirs); @@ -173,7 +173,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { public void testCorruption() throws IOException { Path[] dirs = new Path[randomIntBetween(1, 5)]; for (int i = 0; i < dirs.length; i++) { - dirs[i] = newTempDirPath(); + dirs[i] = createTempDir(); } final long id = addDummyFiles("foo-", dirs); Format format = new Format(randomFrom(XContentType.values()), "foo-"); @@ -247,8 +247,8 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { final ToXContent.Params params = ToXContent.EMPTY_PARAMS; MetaDataStateFormat format = MetaStateService.globalStateFormat(randomFrom(XContentType.values()), params); final Path[] dirs = new Path[2]; - dirs[0] = newTempDirPath(); - dirs[1] = newTempDirPath(); + dirs[0] = createTempDir(); + dirs[1] = createTempDir(); for (Path dir : dirs) { Files.createDirectories(dir.resolve(MetaDataStateFormat.STATE_DIR_NAME)); } @@ -292,8 +292,8 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { final ToXContent.Params params = ToXContent.EMPTY_PARAMS; MetaDataStateFormat format = MetaStateService.globalStateFormat(randomFrom(XContentType.values()), params); final Path[] dirs = new Path[2]; - dirs[0] = newTempDirPath(); - dirs[1] = newTempDirPath(); + dirs[0] = createTempDir(); + dirs[1] = createTempDir(); for (Path dir : dirs) { Files.createDirectories(dir.resolve(MetaDataStateFormat.STATE_DIR_NAME)); } @@ -334,7 +334,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { Set corruptedFiles = new HashSet<>(); MetaDataStateFormat format = MetaStateService.globalStateFormat(randomFrom(XContentType.values()), params); for (int i = 0; i < dirs.length; i++) { - dirs[i] = newTempDirPath(); + dirs[i] = createTempDir(); Files.createDirectories(dirs[i].resolve(MetaDataStateFormat.STATE_DIR_NAME)); for (int j = 0; j < numLegacy; j++) { XContentType type = format.format(); diff --git a/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayTests.java b/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayTests.java index 9efd4c8b8e8..42b8822a980 100644 --- a/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayTests.java +++ b/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayTests.java @@ -438,11 +438,11 @@ public class RecoveryFromGatewayTests extends ElasticsearchIntegrationTest { public void testRecoveryDifferentNodeOrderStartup() throws Exception { // we need different data paths so we make sure we start the second node fresh - final String node_1 = internalCluster().startNode(settingsBuilder().put("path.data", newTempDirPath()).build()); + final String node_1 = internalCluster().startNode(settingsBuilder().put("path.data", createTempDir()).build()); client().prepareIndex("test", "type1", "1").setSource("field", "value").execute().actionGet(); - internalCluster().startNode(settingsBuilder().put("path.data", newTempDirPath()).build()); + internalCluster().startNode(settingsBuilder().put("path.data", createTempDir()).build()); ensureGreen(); diff --git a/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java b/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java index ec07e3b6cc6..a825b65309b 100644 --- a/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java +++ b/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java @@ -68,7 +68,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { .build(); internalCluster().startNodesAsync(3, nodeSettings).get(); - final Path dataPath = newTempDirPath(); + final Path dataPath = createTempDir(); Settings idxSettings = ImmutableSettings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build(); @@ -82,7 +82,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { assertAcked(client().admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()))); + .put("location", createTempDir()))); CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("foo").get(); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); @@ -128,7 +128,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { internalCluster().startNodesAsync(3, nodeSettings).get(); final String IDX = "test"; - final Path dataPath = newTempDirPath(); + final Path dataPath = createTempDir(); Settings idxSettings = ImmutableSettings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) @@ -193,7 +193,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { .build(); String node1 = internalCluster().startNode(nodeSettings); - Path dataPath = newTempDirPath(); + Path dataPath = createTempDir(); String IDX = "test"; Settings idxSettings = ImmutableSettings.builder() @@ -255,7 +255,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { .build(); String node1 = internalCluster().startNode(nodeSettings); - Path dataPath = newTempDirPath(); + Path dataPath = createTempDir(); String IDX = "test"; Settings idxSettings = ImmutableSettings.builder() @@ -320,7 +320,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { int nodeCount = randomIntBetween(2, 5); internalCluster().startNodesAsync(nodeCount, nodeSettings).get(); - Path dataPath = newTempDirPath(); + Path dataPath = createTempDir(); String IDX = "test"; Settings idxSettings = ImmutableSettings.builder() @@ -364,7 +364,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { .build(); internalCluster().startNodesAsync(2, nodeSettings).get(); - Path dataPath = newTempDirPath(); + Path dataPath = createTempDir(); String IDX = "test"; Settings idxSettings = ImmutableSettings.builder() @@ -421,7 +421,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { .build(); internalCluster().startNodesAsync(3, nodeSettings).get(); - Path dataPath = newTempDirPath(); + Path dataPath = createTempDir(); String IDX = "test"; Settings idxSettings = ImmutableSettings.builder() diff --git a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index 01c65c38a45..81f06ad79d7 100644 --- a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -212,7 +212,7 @@ public class AnalysisModuleTests extends ElasticsearchTestCase { } private Path generateWordList(String[] words) throws Exception { - Path wordListFile = newTempDirPath().resolve("wordlist.txt"); + Path wordListFile = createTempDir().resolve("wordlist.txt"); try (BufferedWriter writer = Files.newBufferedWriter(wordListFile, StandardCharsets.UTF_8)) { for (String word : words) { writer.write(word); diff --git a/src/test/java/org/elasticsearch/index/mapper/FileBasedMappingsTests.java b/src/test/java/org/elasticsearch/index/mapper/FileBasedMappingsTests.java index 6c28e50d3ad..6772a5dfcd4 100644 --- a/src/test/java/org/elasticsearch/index/mapper/FileBasedMappingsTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/FileBasedMappingsTests.java @@ -45,7 +45,7 @@ public class FileBasedMappingsTests extends ElasticsearchTestCase { private static final String NAME = FileBasedMappingsTests.class.getSimpleName(); public void testFileBasedMappings() throws Exception { - Path configDir = newTempDirPath(); + Path configDir = createTempDir(); Path mappingsDir = configDir.resolve("mappings"); Path indexMappings = mappingsDir.resolve("index").resolve("type.json"); Path defaultMappings = mappingsDir.resolve("_default").resolve("type.json"); @@ -82,7 +82,7 @@ public class FileBasedMappingsTests extends ElasticsearchTestCase { Settings settings = ImmutableSettings.builder() .put(ClusterName.SETTING, NAME) .put("node.name", NAME) - .put("path.home", newTempDirPath()) + .put("path.home", createTempDir()) .put("path.conf", configDir.toAbsolutePath()) .put("http.enabled", false) .build(); diff --git a/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java b/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java index bec43e38360..7ad4feabaa3 100644 --- a/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java +++ b/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java @@ -486,7 +486,7 @@ public class CorruptedFileTest extends ElasticsearchIntegrationTest { logger.info("--> creating repository"); assertAcked(client().admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(settingsBuilder() - .put("location", newTempDirPath().toAbsolutePath()) + .put("location", createTempDir().toAbsolutePath()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); logger.info("--> snapshot"); diff --git a/src/test/java/org/elasticsearch/index/store/distributor/DistributorTests.java b/src/test/java/org/elasticsearch/index/store/distributor/DistributorTests.java index 028ead0b178..61cd41fe7e7 100644 --- a/src/test/java/org/elasticsearch/index/store/distributor/DistributorTests.java +++ b/src/test/java/org/elasticsearch/index/store/distributor/DistributorTests.java @@ -165,7 +165,7 @@ public class DistributorTests extends ElasticsearchTestCase { public FakeFsDirectory(String path, long usableSpace) throws IOException { - super(newTempDirPath().resolve(path), NoLockFactory.INSTANCE); + super(createTempDir().resolve(path), NoLockFactory.INSTANCE); allocationCount = 0; this.useableSpace = usableSpace; } diff --git a/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java b/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java index 307546e2b07..8913d7a9527 100644 --- a/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java +++ b/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java @@ -67,7 +67,7 @@ public abstract class AbstractSimpleTranslogTests extends ElasticsearchTestCase @Before public void setUp() throws Exception { super.setUp(); - translogDir = newTempDirPath(); + translogDir = createTempDir(); translog = create(translogDir); translog.newTranslog(1); } diff --git a/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java b/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java index 6ad174d6c6b..4369b3aa7e4 100644 --- a/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java +++ b/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java @@ -51,7 +51,7 @@ public class IndicesCustomDataPathTests extends ElasticsearchIntegrationTest { @Before public void setup() { - path = newTempDirPath().toAbsolutePath().toString(); + path = createTempDir().toAbsolutePath().toString(); } @After @@ -63,7 +63,7 @@ public class IndicesCustomDataPathTests extends ElasticsearchIntegrationTest { @TestLogging("_root:DEBUG,index:TRACE") public void testDataPathCanBeChanged() throws Exception { final String INDEX = "idx"; - Path root = newTempDirPath(); + Path root = createTempDir(); Path startDir = root.resolve("start"); Path endDir = root.resolve("end"); logger.info("--> start dir: [{}]", startDir.toAbsolutePath().toString()); diff --git a/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java b/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java index 2c55d55ec28..86b8c3e8d1e 100644 --- a/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java +++ b/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java @@ -49,7 +49,7 @@ public class IndexTemplateFileLoadingTests extends ElasticsearchIntegrationTest settingsBuilder.put(super.nodeSettings(nodeOrdinal)); try { - Path directory = newTempDirPath(); + Path directory = createTempDir(); settingsBuilder.put("path.conf", directory.toAbsolutePath()); Path templatesDir = directory.resolve("templates"); diff --git a/src/test/java/org/elasticsearch/plugins/PluginManagerTests.java b/src/test/java/org/elasticsearch/plugins/PluginManagerTests.java index fe7dd1fb174..2489fec6b3a 100644 --- a/src/test/java/org/elasticsearch/plugins/PluginManagerTests.java +++ b/src/test/java/org/elasticsearch/plugins/PluginManagerTests.java @@ -287,7 +287,7 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest { Settings settings = ImmutableSettings.settingsBuilder() .put("discovery.zen.ping.multicast.enabled", false) .put("http.enabled", true) - .put("path.home", newTempDirPath()).build(); + .put("path.home", createTempDir()).build(); return InternalSettingsPreparer.prepareSettings(settings, false); } diff --git a/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java b/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java index 97024b48913..4208075ccf7 100644 --- a/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java +++ b/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java @@ -40,8 +40,8 @@ public class PluginManagerUnitTests extends ElasticsearchTestCase { @Test public void testThatConfigDirectoryCanBeOutsideOfElasticsearchHomeDirectory() throws IOException { String pluginName = randomAsciiOfLength(10); - Path homeFolder = newTempDirPath(); - Path genericConfigFolder = newTempDirPath(); + Path homeFolder = createTempDir(); + Path genericConfigFolder = createTempDir(); Settings settings = settingsBuilder() .put("path.conf", genericConfigFolder) diff --git a/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index f435e53f092..0187d22c5d4 100644 --- a/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -69,7 +69,7 @@ public class ScriptServiceTests extends ElasticsearchTestCase { @Before public void setup() throws IOException { - Path genericConfigFolder = newTempDirPath(); + Path genericConfigFolder = createTempDir(); baseSettings = settingsBuilder() .put("path.conf", genericConfigFolder) .build(); diff --git a/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java b/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java index f8606656ffe..e87fa1821af 100644 --- a/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java +++ b/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java @@ -113,7 +113,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests logger.info("--> create repository"); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDirPath())).execute().actionGet(); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir())).execute().actionGet(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); logger.info("--> start snapshot"); @@ -146,7 +146,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests @Test public void restoreCustomMetadata() throws Exception { - Path tempDir = newTempDirPath(); + Path tempDir = createTempDir(); logger.info("--> start node"); internalCluster().startNode(); @@ -293,7 +293,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("random", randomAsciiOfLength(10)) .put("wait_after_unblock", 200) ).get(); @@ -338,7 +338,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L)); logger.info("--> creating repository"); - Path repo = newTempDirPath(); + Path repo = createTempDir(); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( ImmutableSettings.settingsBuilder() @@ -427,7 +427,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests logger.info("--> create repository"); logger.info("--> creating repository"); PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDirPath())).execute().actionGet(); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir())).execute().actionGet(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); logger.info("--> start snapshot with default settings - should fail"); @@ -530,7 +530,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests logger.info("--> create repository"); PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDirPath())).execute().actionGet(); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir())).execute().actionGet(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); int numberOfShards = 6; logger.info("--> create an index that will have some unallocated shards"); @@ -589,12 +589,12 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests for (int i = 0; i < 5; i++) { client().admin().cluster().preparePutRepository("test-repo" + i) .setType("mock").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath())).setVerify(false).get(); + .put("location", createTempDir())).setVerify(false).get(); } logger.info("--> make sure that properly setup repository can be registered on all nodes"); client().admin().cluster().preparePutRepository("test-repo-0") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath())).get(); + .put("location", createTempDir())).get(); } @@ -612,7 +612,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests logger.info("--> creating repository"); assertAcked(client().admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); diff --git a/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java b/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java index 25e2193b1cc..8f86ec572a0 100644 --- a/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java +++ b/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java @@ -54,7 +54,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { public void testRepositoryCreation() throws Exception { Client client = client(); - Path location = newTempDirPath(); + Path location = createTempDir(); logger.info("--> creating repository"); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-1") @@ -82,7 +82,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { logger.info("--> creating another repository"); putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-2") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) ).get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); @@ -142,7 +142,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { logger.info("--> creating repository test-repo-1 with 0s timeout - shouldn't ack"); PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo-1") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(5, 100)) ) @@ -152,7 +152,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { logger.info("--> creating repository test-repo-2 with standard timeout - should ack"); putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo-2") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(5, 100)) ).get(); @@ -173,7 +173,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { Client client = client(); Settings settings = ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("random_control_io_exception_rate", 1.0).build(); logger.info("--> creating repository that cannot write any files - should fail"); assertThrows(client.admin().cluster().preparePutRepository("test-repo-1") @@ -187,7 +187,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { logger.info("--> verifying repository"); assertThrows(client.admin().cluster().prepareVerifyRepository("test-repo-1"), RepositoryVerificationException.class); - Path location = newTempDirPath(); + Path location = createTempDir(); logger.info("--> creating repository"); try { @@ -208,7 +208,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { Client client = client(); Settings settings = ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("random_control_io_exception_rate", 1.0).build(); logger.info("--> creating repository that cannot write any files - should fail"); assertThrows(client.admin().cluster().preparePutRepository("test-repo-1") @@ -222,7 +222,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { logger.info("--> verifying repository"); assertThrows(client.admin().cluster().prepareVerifyRepository("test-repo-1"), RepositoryVerificationException.class); - Path location = newTempDirPath(); + Path location = createTempDir(); logger.info("--> creating repository"); try { diff --git a/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java b/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java index c7687478aeb..f6a730c5491 100644 --- a/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java +++ b/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java @@ -87,7 +87,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -182,7 +182,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { String indexName = "testindex"; String repoName = "test-restore-snapshot-repo"; String snapshotName = "test-restore-snapshot"; - String absolutePath = newTempDirPath().toAbsolutePath().toString(); + String absolutePath = createTempDir().toAbsolutePath().toString(); logger.info("Path [{}]", absolutePath); String restoredIndexName = indexName + "-restored"; String typeName = "actions"; @@ -228,7 +228,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -277,7 +277,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -325,7 +325,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDirPath())).get(); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir())).get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); logger.info("--> snapshot"); @@ -342,7 +342,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDirPath()))); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir()))); logger.info("--> create test indices"); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); @@ -398,7 +398,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDirPath()))); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir()))); logger.info("--> creating test template"); assertThat(client.admin().indices().preparePutTemplate("test-template").setTemplate("te*").addMapping("test-mapping", "{}").get().isAcknowledged(), equalTo(true)); @@ -430,7 +430,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { Client client = client(); logger.info("--> creating repository"); - Path location = newTempDirPath(); + Path location = createTempDir(); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", location))); @@ -512,7 +512,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("random", randomAsciiOfLength(10)) .put("random_control_io_exception_rate", 0.2)) .setVerify(false)); @@ -562,7 +562,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("random", randomAsciiOfLength(10)) .put("random_data_file_io_exception_rate", 0.3))); @@ -624,7 +624,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { @Test public void dataFileFailureDuringRestoreTest() throws Exception { - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); Client client = client(); logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") @@ -666,7 +666,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { @Test public void deletionOfFailingToRecoverIndexShouldStopRestore() throws Exception { - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); Client client = client(); logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") @@ -735,7 +735,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()))); + .put("location", createTempDir()))); logger.info("--> creating index that cannot be allocated"); prepareCreate("test-idx", 2, ImmutableSettings.builder().put(FilterAllocationDecider.INDEX_ROUTING_INCLUDE_GROUP + ".tag", "nowhere").put("index.number_of_shards", 3)).get(); @@ -753,7 +753,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { final int numberOfSnapshots = between(5, 15); Client client = client(); - Path repo = newTempDirPath(); + Path repo = createTempDir(); logger.info("--> creating repository at " + repo.toAbsolutePath()); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() @@ -810,7 +810,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { public void deleteSnapshotWithMissingIndexAndShardMetadataTest() throws Exception { Client client = client(); - Path repo = newTempDirPath(); + Path repo = createTempDir(); logger.info("--> creating repository at " + repo.toAbsolutePath()); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() @@ -849,7 +849,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { public void deleteSnapshotWithMissingMetadataTest() throws Exception { Client client = client(); - Path repo = newTempDirPath(); + Path repo = createTempDir(); logger.info("--> creating repository at " + repo.toAbsolutePath()); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() @@ -884,7 +884,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { public void deleteSnapshotWithCorruptedSnapshotFileTest() throws Exception { Client client = client(); - Path repo = newTempDirPath(); + Path repo = createTempDir(); logger.info("--> creating repository at " + repo.toAbsolutePath()); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() @@ -929,7 +929,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()))); + .put("location", createTempDir()))); createIndex("test-idx", "test-idx-closed"); ensureGreen(); @@ -955,7 +955,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()))); + .put("location", createTempDir()))); createIndex("test-idx"); ensureGreen(); @@ -976,7 +976,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()))); + .put("location", createTempDir()))); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); ensureGreen(); @@ -1092,7 +1092,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { @Test public void moveShardWhileSnapshottingTest() throws Exception { Client client = client(); - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( @@ -1154,7 +1154,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { @Test public void deleteRepositoryWhileSnapshottingTest() throws Exception { Client client = client(); - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); logger.info("--> creating repository"); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( @@ -1239,7 +1239,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { Client client = client(); logger.info("--> creating repository"); - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() .put("location", repositoryLocation) @@ -1297,7 +1297,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { Client client = client(); logger.info("--> creating repository"); - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); boolean throttleSnapshot = randomBoolean(); boolean throttleRestore = randomBoolean(); assertAcked(client.admin().cluster().preparePutRepository("test-repo") @@ -1355,7 +1355,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { @Test public void snapshotStatusTest() throws Exception { Client client = client(); - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); logger.info("--> creating repository"); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( @@ -1458,7 +1458,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -1506,7 +1506,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -1569,7 +1569,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -1675,7 +1675,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)) .put("block_on_init", true) @@ -1727,7 +1727,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)) )); diff --git a/src/test/java/org/elasticsearch/snapshots/SnapshotBackwardsCompatibilityTest.java b/src/test/java/org/elasticsearch/snapshots/SnapshotBackwardsCompatibilityTest.java index e1340c52276..5d79fc8a6f8 100644 --- a/src/test/java/org/elasticsearch/snapshots/SnapshotBackwardsCompatibilityTest.java +++ b/src/test/java/org/elasticsearch/snapshots/SnapshotBackwardsCompatibilityTest.java @@ -59,7 +59,7 @@ public class SnapshotBackwardsCompatibilityTest extends ElasticsearchBackwardsCo logger.info("--> creating repository"); assertAcked(client().admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath().toAbsolutePath()) + .put("location", createTempDir().toAbsolutePath()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); String[] indicesBefore = new String[randomIntBetween(2,5)]; @@ -165,7 +165,7 @@ public class SnapshotBackwardsCompatibilityTest extends ElasticsearchBackwardsCo public void testSnapshotMoreThanOnce() throws ExecutionException, InterruptedException, IOException { Client client = client(); - final Path tempDir = newTempDirPath().toAbsolutePath(); + final Path tempDir = createTempDir().toAbsolutePath(); logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index 4083b1502dd..ba4dfb44ba7 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -22,7 +22,6 @@ import com.carrotsearch.randomizedtesting.LifecycleScope; import com.carrotsearch.randomizedtesting.RandomizedContext; import com.carrotsearch.randomizedtesting.RandomizedTest; import com.carrotsearch.randomizedtesting.Randomness; -import com.carrotsearch.randomizedtesting.SysGlobals; import com.carrotsearch.randomizedtesting.generators.RandomInts; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.google.common.base.Joiner; @@ -281,11 +280,6 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase * Default maximum number of shards for an index */ protected static final int DEFAULT_MAX_NUM_SHARDS = 10; - - /** - * The child JVM ordinal of this JVM. Default is 0 - */ - public static final int CHILD_JVM_ID = Integer.parseInt(System.getProperty(SysGlobals.CHILDVM_SYSPROP_JVM_ID, "0")); /** * The current cluster depending on the configured {@link Scope}. @@ -770,7 +764,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase } // 30% of the time if (randomInt(9) < 3) { - final Path dataPath = newTempDirPath(); + final Path dataPath = createTempDir(); logger.info("using custom data_path for index: [{}]", dataPath); builder.put(IndexMetaData.SETTING_DATA_PATH, dataPath); } @@ -1704,7 +1698,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase maxNumDataNodes = getMaxNumDataNodes(); } - return new InternalTestCluster(seed, newTempDirPath(), minNumDataNodes, maxNumDataNodes, + return new InternalTestCluster(seed, createTempDir(), minNumDataNodes, maxNumDataNodes, clusterName(scope.name(), Integer.toString(CHILD_JVM_ID), seed), settingsSource, getNumClientNodes(), InternalTestCluster.DEFAULT_ENABLE_HTTP_PIPELINING, CHILD_JVM_ID, nodePrefix); } @@ -1923,7 +1917,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase * Return settings that could be used to start a node that has the given zipped home directory. */ protected Settings prepareBackwardsDataDir(Path backwardsIndex, Object... settings) throws IOException { - Path indexDir = newTempDirPath(); + Path indexDir = createTempDir(); Path dataDir = indexDir.resolve("data"); try (InputStream stream = Files.newInputStream(backwardsIndex)) { TestUtil.unzip(stream, indexDir); diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java index 93c9084e2b2..334829f32ef 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java @@ -271,27 +271,6 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase { // ----------------------------------------------------------------- // Test facilities and facades for subclasses. // ----------------------------------------------------------------- - - /** - * Registers a {@link Closeable} resource that should be closed after the test - * completes. - * - * @return resource (for call chaining). - */ - @Override - public T closeAfterTest(T resource) { - return RandomizedContext.current().closeAtEnd(resource, LifecycleScope.TEST); - } - - /** - * Registers a {@link Closeable} resource that should be closed after the suite - * completes. - * - * @return resource (for call chaining). - */ - public static T closeAfterSuite(T resource) { - return RandomizedContext.current().closeAtEnd(resource, LifecycleScope.SUITE); - } // old helper stuff, a lot of it is bad news and we should see if its all used @@ -900,24 +879,6 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase { return ThreadPool.terminate(service, 10, TimeUnit.SECONDS); } - // TODO: these method names stink, but are a temporary solution. - // see https://github.com/carrotsearch/randomizedtesting/pull/178 - - /** - * Returns a temporary file - * @throws IOException - */ - public Path newTempFilePath() throws IOException { - return createTempFile(); - } - - /** - * Returns a temporary directory - */ - public Path newTempDirPath() { - return createTempDir(); - } - /** * Returns a random number of temporary paths. */ @@ -925,7 +886,7 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase { final int numPaths = TestUtil.nextInt(random(), 1, 3); final String[] absPaths = new String[numPaths]; for (int i = 0; i < numPaths; i++) { - absPaths[i] = newTempDirPath().toAbsolutePath().toString(); + absPaths[i] = createTempDir().toAbsolutePath().toString(); } return absPaths; } @@ -937,7 +898,7 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase { public NodeEnvironment newNodeEnvironment(Settings settings) throws IOException { Settings build = ImmutableSettings.builder() .put(settings) - .put("path.home", newTempDirPath().toAbsolutePath()) + .put("path.home", createTempDir().toAbsolutePath()) .putArray("path.data", tmpPaths()).build(); return new NodeEnvironment(build, new Environment(build)); } diff --git a/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java b/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java index 39ad622ae00..f35daa926a1 100644 --- a/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java +++ b/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java @@ -76,7 +76,7 @@ public class FileUtilsTests extends ElasticsearchTestCase { assertThat(yamlSuites.get("index").size(), greaterThan(1)); //files can be loaded from classpath and from file system too - Path dir = newTempDirPath(); + Path dir = createTempDir(); Path file = dir.resolve("test_loading.yaml"); Files.createFile(file); diff --git a/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java b/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java index 215023b9ce4..8a95dfeda2b 100644 --- a/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java +++ b/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java @@ -55,7 +55,7 @@ public class InternalTestClusterTests extends ElasticsearchTestCase { int jvmOrdinal = randomIntBetween(0, 10); String nodePrefix = randomRealisticUnicodeOfCodepointLengthBetween(1, 10); - Path baseDir = newTempDirPath(); + Path baseDir = createTempDir(); InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix); InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix); assertClusters(cluster0, cluster1, true); @@ -99,7 +99,7 @@ public class InternalTestClusterTests extends ElasticsearchTestCase { int jvmOrdinal = randomIntBetween(0, 10); String nodePrefix = "foobar"; - Path baseDir = newTempDirPath(); + Path baseDir = createTempDir(); InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix); InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName1, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix); diff --git a/src/test/java/org/elasticsearch/watcher/FileWatcherTest.java b/src/test/java/org/elasticsearch/watcher/FileWatcherTest.java index 4b12fc7c6f9..37fa1540c92 100644 --- a/src/test/java/org/elasticsearch/watcher/FileWatcherTest.java +++ b/src/test/java/org/elasticsearch/watcher/FileWatcherTest.java @@ -98,7 +98,7 @@ public class FileWatcherTest extends ElasticsearchTestCase { @Test public void testSimpleFileOperations() throws IOException { - Path tempDir = newTempDirPath(); + Path tempDir = createTempDir(); RecordingChangeListener changes = new RecordingChangeListener(tempDir); Path testFile = tempDir.resolve("test.txt"); touch(testFile); @@ -127,7 +127,7 @@ public class FileWatcherTest extends ElasticsearchTestCase { @Test public void testSimpleDirectoryOperations() throws IOException { - Path tempDir = newTempDirPath(); + Path tempDir = createTempDir(); RecordingChangeListener changes = new RecordingChangeListener(tempDir); Path testDir = tempDir.resolve("test-dir"); Files.createDirectories(testDir); @@ -217,7 +217,7 @@ public class FileWatcherTest extends ElasticsearchTestCase { @Test public void testNestedDirectoryOperations() throws IOException { - Path tempDir = newTempDirPath(); + Path tempDir = createTempDir(); RecordingChangeListener changes = new RecordingChangeListener(tempDir); Path testDir = tempDir.resolve("test-dir"); Files.createDirectories(testDir); @@ -283,7 +283,7 @@ public class FileWatcherTest extends ElasticsearchTestCase { @Test public void testFileReplacingDirectory() throws IOException { - Path tempDir = newTempDirPath(); + Path tempDir = createTempDir(); RecordingChangeListener changes = new RecordingChangeListener(tempDir); Path testDir = tempDir.resolve("test-dir"); Files.createDirectories(testDir); @@ -330,7 +330,7 @@ public class FileWatcherTest extends ElasticsearchTestCase { @Test public void testEmptyDirectory() throws IOException { - Path tempDir = newTempDirPath(); + Path tempDir = createTempDir(); RecordingChangeListener changes = new RecordingChangeListener(tempDir); Path testDir = tempDir.resolve("test-dir"); Files.createDirectories(testDir); @@ -353,7 +353,7 @@ public class FileWatcherTest extends ElasticsearchTestCase { @Test public void testNoDirectoryOnInit() throws IOException { - Path tempDir = newTempDirPath(); + Path tempDir = createTempDir(); RecordingChangeListener changes = new RecordingChangeListener(tempDir); Path testDir = tempDir.resolve("test-dir"); @@ -377,7 +377,7 @@ public class FileWatcherTest extends ElasticsearchTestCase { @Test public void testNoFileOnInit() throws IOException { - Path tempDir = newTempDirPath(); + Path tempDir = createTempDir(); RecordingChangeListener changes = new RecordingChangeListener(tempDir); Path testFile = tempDir.resolve("testfile.txt");