Tests: Forbid tests from writing to CWD

Allowing tests writing to the working directory can mask problems.
For example, multiple tests running in the same jvm, and using the
same relative path, may cause issues if the first test to run
leaves data in the directory, and the second test does not remember
to cleanup the path before using it.

This change adds security manager rules to disallow tests writing
to the working directory. Instead, tests create a temp dir with
the existing test framework.

closes #10605
This commit is contained in:
Ryan Ernst 2015-04-14 23:58:46 -07:00
parent c326738193
commit a3f078985b
21 changed files with 238 additions and 214 deletions

View File

@ -30,8 +30,8 @@ grant {
permission java.io.FilePermission "${m2.repository}${/}-", "read";
// system jar resources
permission java.io.FilePermission "${java.home}${/}-", "read";
permission java.io.FilePermission "${junit4.childvm.cwd}", "read,write";
permission java.io.FilePermission "${junit4.childvm.cwd}${/}-", "read,write,delete";
permission java.io.FilePermission "${junit4.childvm.cwd}${/}temp", "read,write";
permission java.io.FilePermission "${junit4.childvm.cwd}${/}temp${/}-", "read,write,delete";
permission java.io.FilePermission "${junit4.tempDir}${/}*", "read,write,delete";
permission java.nio.file.LinkPermission "symbolic";
permission groovy.security.GroovyCodeSourcePermission "/groovy/script";

View File

@ -563,8 +563,8 @@
<haltOnFailure>${tests.failfast}</haltOnFailure>
<uniqueSuiteNames>false</uniqueSuiteNames>
<systemProperties>
<java.io.tmpdir>.</java.io.tmpdir>
<!-- we use '.' since this is different per JVM-->
<!-- we use './temp' since this is per JVM and tests are forbidden from writing to CWD -->
<java.io.tmpdir>./temp</java.io.tmpdir>
<!-- RandomizedTesting library system properties -->
<tests.bwc>${tests.bwc}</tests.bwc>
<tests.bwc.path>${tests.bwc.path}</tests.bwc.path>

View File

@ -195,7 +195,7 @@ public class HttpServer extends AbstractLifecycleComponent<HttpServer> {
return;
}
}
if (!file.toAbsolutePath().startsWith(siteFile)) {
if (!file.toAbsolutePath().startsWith(siteFile.toAbsolutePath())) {
channel.sendResponse(new BytesRestResponse(FORBIDDEN));
return;
}

View File

@ -54,6 +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("node.name", "testNodeVersionIsUpdated")
.put("http.enabled", false)
.put("index.store.type", "ram")

View File

@ -25,18 +25,21 @@ import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;
import org.elasticsearch.test.ElasticsearchTestCase;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.Arrays;
public class RoutingBackwardCompatibilityTests extends ElasticsearchTestCase {
public void testBackwardCompatibility() throws Exception {
Node node = new Node();
Path baseDir = newTempDirPath();
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"))) {
for (String line = reader.readLine(); line != null; line = reader.readLine()) {

View File

@ -48,7 +48,10 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
/**
*
@ -435,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", "data/data1").build());
final String node_1 = internalCluster().startNode(settingsBuilder().put("path.data", newTempDirPath()).build());
client().prepareIndex("test", "type1", "1").setSource("field", "value").execute().actionGet();
internalCluster().startNode(settingsBuilder().put("path.data", "data/data2").build());
internalCluster().startNode(settingsBuilder().put("path.data", newTempDirPath()).build());
ensureGreen();

View File

@ -28,7 +28,12 @@ import org.apache.lucene.codecs.Codec;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.*;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexDeletionPolicy;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LiveIndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
@ -36,8 +41,8 @@ import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Nullable;
@ -92,26 +97,27 @@ import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static com.carrotsearch.randomizedtesting.RandomizedTest.*;
import static org.apache.lucene.util.AbstractRandomizedTest.CHILD_JVM_ID;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomDouble;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.index.engine.Engine.Operation.Origin.PRIMARY;
import static org.elasticsearch.index.engine.Engine.Operation.Origin.REPLICA;
import static org.elasticsearch.test.ElasticsearchTestCase.assertBusy;
import static org.elasticsearch.test.ElasticsearchTestCase.terminate;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
@LuceneTestCase.SuppressFileSystems("*") // mock FS causes translog issues recovering sometimes because of their use of globs, see LUCENE-6424
public class InternalEngineTests extends ElasticsearchLuceneTestCase {
public static final String TRANSLOG_PRIMARY_LOCATION = "work/fs-translog/JVM_" + CHILD_JVM_ID + "/primary";
public static final String TRANSLOG_REPLICA_LOCATION = "work/fs-translog/JVM_" + CHILD_JVM_ID + "/replica";
protected final ShardId shardId = new ShardId(new Index("index"), 1);
protected ThreadPool threadPool;
@ -133,19 +139,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
@Before
public void setUp() throws Exception {
super.setUp();
// clean up shared directory
assertBusy(new Runnable() {
@Override
public void run() {
try {
IOUtils.rm(Paths.get(TRANSLOG_PRIMARY_LOCATION));
IOUtils.rm(Paths.get(TRANSLOG_REPLICA_LOCATION));
} catch (IOException e) {
fail("failed to delete translogs before tests."
+ ExceptionsHelper.detailedMessage(e) + "\n" + ExceptionsHelper.stackTrace(e));
}
}
}, 30, TimeUnit.SECONDS);
CodecService codecService = new CodecService(shardId.index());
indexConcurrency = randomIntBetween(1, 20);
String name = Codec.getDefault().getName();
@ -237,11 +231,11 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
}
protected Translog createTranslog() throws IOException {
return new FsTranslog(shardId, EMPTY_SETTINGS, Paths.get(TRANSLOG_PRIMARY_LOCATION).toAbsolutePath());
return new FsTranslog(shardId, EMPTY_SETTINGS, createTempDir("translog-primary"));
}
protected Translog createTranslogReplica() throws IOException {
return new FsTranslog(shardId, EMPTY_SETTINGS, Paths.get(TRANSLOG_REPLICA_LOCATION).toAbsolutePath());
return new FsTranslog(shardId, EMPTY_SETTINGS, createTempDir("translog-replica"));
}
protected IndexDeletionPolicy createIndexDeletionPolicy() {
@ -1856,11 +1850,11 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
}
TranslogHandler parser = (TranslogHandler) engine.config().getTranslogRecoveryPerformer();
long currentTranslogId = translog.currentId();
parser.mappingModified = randomBoolean();
long currentTranslogId = translog.currentId();
engine.close();
engine = new InternalEngine(engine.config(), false); // we need to reuse the engine config unless the parser.mappingModified won't work
engine = new InternalEngine(engine.config(), false); // we need to reuse the engine config otherwise the parser.mappingModified won't work
assertTrue(currentTranslogId + "<" + translog.currentId(), currentTranslogId < translog.currentId());
assertEquals("translog ID must be incremented by 2 after initial recovery", currentTranslogId + 2, translog.currentId());

View File

@ -24,7 +24,10 @@ import org.apache.lucene.codecs.Codec;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.*;
import org.apache.lucene.index.IndexDeletionPolicy;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LiveIndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
@ -69,15 +72,20 @@ import org.junit.Test;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import static com.carrotsearch.randomizedtesting.RandomizedTest.*;
import static com.carrotsearch.randomizedtesting.RandomizedTest.getRandom;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomDouble;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.test.ElasticsearchTestCase.newTempDirPath;
import static org.elasticsearch.test.ElasticsearchTestCase.terminate;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
/**
* TODO: document me!
@ -123,7 +131,7 @@ public class ShadowEngineTests extends ElasticsearchLuceneTestCase {
.put(EngineConfig.INDEX_CONCURRENCY_SETTING, indexConcurrency)
.build(); // TODO randomize more settings
threadPool = new ThreadPool(getClass().getName());
dirPath = newTempDirPath(LifecycleScope.TEST);
dirPath = createTempDir();
store = createStore(dirPath);
storeReplica = createStore(dirPath);
Lucene.cleanLuceneIndex(store.directory());
@ -201,11 +209,11 @@ public class ShadowEngineTests extends ElasticsearchLuceneTestCase {
}
protected Translog createTranslog() throws IOException {
return new FsTranslog(shardId, EMPTY_SETTINGS, Paths.get("work/fs-translog/"));
return new FsTranslog(shardId, EMPTY_SETTINGS, createTempDir("translog-primary"));
}
protected Translog createTranslogReplica() throws IOException {
return new FsTranslog(shardId, EMPTY_SETTINGS, Paths.get("work/fs-translog/"));
return new FsTranslog(shardId, EMPTY_SETTINGS, createTempDir("translog-replica"));
}
protected IndexDeletionPolicy createIndexDeletionPolicy() {

View File

@ -82,6 +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.conf", configDir.toAbsolutePath())
.put("http.enabled", false)
.build();

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.store.distributor;
import com.carrotsearch.randomizedtesting.LifecycleScope;
import org.apache.lucene.store.*;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.shard.ShardId;
@ -137,7 +138,7 @@ public class DistributorTests extends ElasticsearchTestCase {
}
public static class FakeDirectoryService extends DirectoryService {
public class FakeDirectoryService extends DirectoryService {
private final Directory[] directories;
@ -157,14 +158,14 @@ public class DistributorTests extends ElasticsearchTestCase {
}
}
public static class FakeFsDirectory extends FSDirectory {
public class FakeFsDirectory extends FSDirectory {
public int allocationCount;
public long useableSpace;
public FakeFsDirectory(String path, long usableSpace) throws IOException {
super(Paths.get(path), NoLockFactory.INSTANCE);
super(newTempDirPath().resolve(path), NoLockFactory.INSTANCE);
allocationCount = 0;
this.useableSpace = usableSpace;
}

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.translog;
import org.apache.lucene.index.Term;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.bytes.BytesArray;
@ -60,15 +59,15 @@ public abstract class AbstractSimpleTranslogTests extends ElasticsearchTestCase
protected final ShardId shardId = new ShardId(new Index("index"), 1);
protected Path translogDir;
protected Translog translog;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
translog = create();
// if a previous test failed we clean up things here
FileSystemUtils.deleteSubDirectories(translog.locations());
translogDir = newTempDirPath();
translog = create(translogDir);
translog.newTranslog(1);
}
@ -76,22 +75,18 @@ public abstract class AbstractSimpleTranslogTests extends ElasticsearchTestCase
@After
public void tearDown() throws Exception {
try {
final Path[] locations = translog.locations();
translog.close();
if (translog.currentId() > 1) {
// ensure all snapshots etc are closed if this fails something was not closed
assertFileDeleted(translog, translog.currentId() - 1);
}
assertFileIsPresent(translog, translog.currentId());
IOUtils.rm(locations); // delete all the locations
} finally {
super.tearDown();
}
}
protected abstract Translog create() throws IOException;
protected abstract Path translogFileDirectory();
protected abstract Translog create(Path translogDir) throws IOException;
@Test
public void testRead() throws IOException {
@ -567,7 +562,7 @@ public abstract class AbstractSimpleTranslogTests extends ElasticsearchTestCase
}
translog.sync();
corruptTranslogs(translogFileDirectory());
corruptTranslogs(translogDir);
AtomicInteger corruptionsCaught = new AtomicInteger(0);
for (Translog.Location location : locations) {
@ -591,7 +586,7 @@ public abstract class AbstractSimpleTranslogTests extends ElasticsearchTestCase
}
translog.sync();
truncateTranslogs(translogFileDirectory());
truncateTranslogs(translogDir);
AtomicInteger truncations = new AtomicInteger(0);
for (Translog.Location location : locations) {
@ -650,8 +645,7 @@ public abstract class AbstractSimpleTranslogTests extends ElasticsearchTestCase
@Test
public void testVerifyTranslogIsNotDeleted() throws IOException {
Path path = translogFileDirectory();
assertTrue(Files.exists(path.resolve("translog-1")));
assertTrue(Files.exists(translogDir.resolve("translog-1")));
translog.add(new Translog.Create("test", "1", new byte[]{1}));
Translog.Snapshot snapshot = translog.snapshot();
assertThat(snapshot, TranslogSizeMatcher.translogSize(1));
@ -664,6 +658,6 @@ public abstract class AbstractSimpleTranslogTests extends ElasticsearchTestCase
translog.close();
}
assertTrue(Files.exists(path.resolve("translog-1")));
assertTrue(Files.exists(translogDir.resolve("translog-1")));
}
}

View File

@ -19,17 +19,12 @@
package org.elasticsearch.index.translog.fs;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.translog.AbstractSimpleTranslogTests;
import org.elasticsearch.index.translog.Translog;
import org.junit.AfterClass;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
*
@ -37,23 +32,13 @@ import java.nio.file.Paths;
public class FsBufferedTranslogTests extends AbstractSimpleTranslogTests {
@Override
protected Translog create() throws IOException {
protected Translog create(Path translogDir) throws IOException {
return new FsTranslog(shardId,
ImmutableSettings.settingsBuilder()
.put("index.translog.fs.type", FsTranslogFile.Type.BUFFERED.name())
.put("index.translog.fs.buffer_size", 10 + randomInt(128 * 1024))
.build(),
translogFileDirectory()
translogDir
);
}
@Override
protected Path translogFileDirectory() {
return Paths.get("data/fs-buf-translog");
}
@AfterClass
public static void cleanup() throws IOException {
IOUtils.rm(Paths.get("data/fs-buf-translog"));
}
}

View File

@ -19,17 +19,12 @@
package org.elasticsearch.index.translog.fs;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.translog.AbstractSimpleTranslogTests;
import org.elasticsearch.index.translog.Translog;
import org.junit.AfterClass;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
*
@ -37,19 +32,10 @@ import java.nio.file.Paths;
public class FsSimpleTranslogTests extends AbstractSimpleTranslogTests {
@Override
protected Translog create() throws IOException {
protected Translog create(Path translogDir) throws IOException {
return new FsTranslog(shardId,
ImmutableSettings.settingsBuilder().put("index.translog.fs.type", FsTranslogFile.Type.SIMPLE.name()).build(),
translogFileDirectory());
}
@Override
protected Path translogFileDirectory() {
return Paths.get("data/fs-simple-translog");
}
@AfterClass
public static void cleanup() throws IOException {
IOUtils.rm(Paths.get("data/fs-simple-translog"));
translogDir);
}
}

View File

@ -54,9 +54,9 @@ public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
String storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
Path[] dataPaths = dataPaths();
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(least_used[rate_limited(niofs(" + dataPaths[0].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(least_used[rate_limited(niofs(" + dataPaths[0].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
if (dataPaths.length > 1) {
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), rate_limited(niofs(" + dataPaths[1].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), rate_limited(niofs(" + dataPaths[1].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
}
assertThat(storeString, endsWith(", type=MERGE, rate=20.0)])"));
@ -64,9 +64,9 @@ public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
dataPaths = dataPaths();
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(random[rate_limited(niofs(" + dataPaths[0].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(random[rate_limited(niofs(" + dataPaths[0].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
if (dataPaths.length > 1) {
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), rate_limited(niofs(" + dataPaths[1].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), rate_limited(niofs(" + dataPaths[1].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
}
assertThat(storeString, endsWith(", type=MERGE, rate=20.0)])"));
@ -74,9 +74,9 @@ public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
dataPaths = dataPaths();
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(least_used[rate_limited(mmapfs(" + dataPaths[0].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(least_used[rate_limited(mmapfs(" + dataPaths[0].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
if (dataPaths.length > 1) {
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), rate_limited(mmapfs(" + dataPaths[1].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), rate_limited(mmapfs(" + dataPaths[1].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
}
assertThat(storeString, endsWith(", type=MERGE, rate=20.0)])"));
@ -84,9 +84,9 @@ public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
dataPaths = dataPaths();
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(least_used[rate_limited(simplefs(" + dataPaths[0].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(least_used[rate_limited(simplefs(" + dataPaths[0].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
if (dataPaths.length > 1) {
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), rate_limited(simplefs(" + dataPaths[1].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), rate_limited(simplefs(" + dataPaths[1].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
}
assertThat(storeString, endsWith(", type=MERGE, rate=20.0)])"));
@ -94,11 +94,11 @@ public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
dataPaths = dataPaths();
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(least_used[rate_limited(default(mmapfs(" + dataPaths[0].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("),niofs(" + dataPaths[0].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(least_used[rate_limited(default(mmapfs(" + dataPaths[0].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("),niofs(" + dataPaths[0].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
if (dataPaths.length > 1) {
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), rate_limited(default(mmapfs(" + dataPaths[1].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), rate_limited(default(mmapfs(" + dataPaths[1].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
}
assertThat(storeString, endsWith(", type=MERGE, rate=20.0)])"));
@ -106,9 +106,9 @@ public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
storeString = getStoreDirectory("test", 0).toString();
logger.info(storeString);
dataPaths = dataPaths();
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(least_used[niofs(" + dataPaths[0].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), startsWith("store(least_used[niofs(" + dataPaths[0].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
if (dataPaths.length > 1) {
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), niofs(" + dataPaths[1].toAbsolutePath().toString().toLowerCase(Locale.ROOT)));
assertThat(storeString.toLowerCase(Locale.ROOT), containsString("), niofs(" + dataPaths[1].toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT)));
}
assertThat(storeString, endsWith(")])"));
}

View File

@ -19,7 +19,6 @@
package org.elasticsearch.plugins;
import com.google.common.base.Predicate;
import org.apache.http.impl.client.HttpClients;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.ElasticsearchException;
@ -28,7 +27,6 @@ import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.action.admin.cluster.node.info.PluginInfo;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
@ -41,16 +39,12 @@ import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
import org.elasticsearch.test.junit.annotations.Network;
import org.elasticsearch.test.rest.client.http.HttpRequestBuilder;
import org.elasticsearch.test.rest.client.http.HttpResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
@ -62,25 +56,12 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertDire
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileExists;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
@ClusterScope(scope = Scope.TEST, numDataNodes = 0, transportClientRatio = 0.0)
public class PluginManagerTests extends ElasticsearchIntegrationTest {
private static final Settings SETTINGS = ImmutableSettings.settingsBuilder()
.put("discovery.zen.ping.multicast.enabled", false)
.put("force.http.enabled", true)
.build();
private static final String PLUGIN_DIR = "plugins";
@After
public void afterTest() throws IOException {
deletePluginsFolder();
}
@Before
public void beforeTest() throws IOException {
deletePluginsFolder();
}
@Test(expected = ElasticsearchIllegalArgumentException.class)
public void testDownloadAndExtract_NullName_ThrowsException() throws IOException {
@ -91,9 +72,10 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
public void testLocalPluginInstallSingleFolder() throws Exception {
//When we have only a folder in top-level (no files either) we remove that folder while extracting
String pluginName = "plugin-test";
downloadAndExtract(pluginName, getPluginUrlForResource("plugin_single_folder.zip"));
Tuple<Settings, Environment> initialSettings = buildInitialSettings();
downloadAndExtract(pluginName, initialSettings, getPluginUrlForResource("plugin_single_folder.zip"));
internalCluster().startNode(SETTINGS);
internalCluster().startNode(initialSettings.v1());
assertPluginLoaded(pluginName);
assertPluginAvailable(pluginName);
@ -102,8 +84,7 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
@Test
public void testLocalPluginInstallWithBinAndConfig() throws Exception {
String pluginName = "plugin-test";
Tuple<Settings, Environment> initialSettings = InternalSettingsPreparer.prepareSettings(
ImmutableSettings.settingsBuilder().build(), false);
Tuple<Settings, Environment> initialSettings = buildInitialSettings();
Environment env = initialSettings.v2();
Path binDir = env.homeFile().resolve("bin");
if (!Files.exists(binDir)) {
@ -128,13 +109,13 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
assertDirectoryExists(pluginConfigDir);
Path toolFile = pluginBinDir.resolve("tool");
assertFileExists(toolFile);
// check that the file is marked executable, without actually checking that we can execute it.
PosixFileAttributeView view = Files.getFileAttributeView(toolFile, PosixFileAttributeView.class);
// the view might be null, on e.g. windows, there is nothing to check there!
if (view != null) {
PosixFileAttributes attributes = view.readAttributes();
assertTrue("unexpected permissions: " + attributes.permissions(),
assertTrue("unexpected permissions: " + attributes.permissions(),
attributes.permissions().contains(PosixFilePermission.OWNER_EXECUTE));
}
} finally {
@ -149,8 +130,7 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
@Test
public void testLocalPluginInstallWithBinAndConfigInAlreadyExistingConfigDir_7890() throws Exception {
String pluginName = "plugin-test";
Tuple<Settings, Environment> initialSettings = InternalSettingsPreparer.prepareSettings(
ImmutableSettings.settingsBuilder().build(), false);
Tuple<Settings, Environment> initialSettings = buildInitialSettings();
Environment env = initialSettings.v2();
Path configDir = env.configFile();
@ -229,8 +209,7 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
@Test
public void testLocalPluginInstallWithBinOnly_7152() throws Exception {
String pluginName = "plugin-test";
Tuple<Settings, Environment> initialSettings = InternalSettingsPreparer.prepareSettings(
ImmutableSettings.settingsBuilder().build(), false);
Tuple<Settings, Environment> initialSettings = buildInitialSettings();
Environment env = initialSettings.v2();
Path binDir = env.homeFile().resolve("bin");
if (!Files.exists(binDir)) {
@ -254,9 +233,10 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
//When we have only a folder in top-level (no files either) but it's called _site, we make it work
//we can either remove the folder while extracting and then re-add it manually or just leave it as it is
String pluginName = "plugin-test";
downloadAndExtract(pluginName, getPluginUrlForResource("plugin_folder_site.zip"));
Tuple<Settings, Environment> initialSettings = buildInitialSettings();
downloadAndExtract(pluginName, initialSettings, getPluginUrlForResource("plugin_folder_site.zip"));
internalCluster().startNode(SETTINGS);
internalCluster().startNode(initialSettings.v1());
assertPluginLoaded(pluginName);
assertPluginAvailable(pluginName);
@ -266,9 +246,10 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
public void testLocalPluginWithoutFolders() throws Exception {
//When we don't have folders at all in the top-level, but only files, we don't modify anything
String pluginName = "plugin-test";
downloadAndExtract(pluginName, getPluginUrlForResource("plugin_without_folders.zip"));
Tuple<Settings, Environment> initialSettings = buildInitialSettings();
downloadAndExtract(pluginName, initialSettings, getPluginUrlForResource("plugin_without_folders.zip"));
internalCluster().startNode(SETTINGS);
internalCluster().startNode(initialSettings.v1());
assertPluginLoaded(pluginName);
assertPluginAvailable(pluginName);
@ -278,9 +259,10 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
public void testLocalPluginFolderAndFile() throws Exception {
//When we have a single top-level folder but also files in the top-level, we don't modify anything
String pluginName = "plugin-test";
downloadAndExtract(pluginName, getPluginUrlForResource("plugin_folder_file.zip"));
Tuple<Settings, Environment> initialSettings = buildInitialSettings();
downloadAndExtract(pluginName, initialSettings, getPluginUrlForResource("plugin_folder_file.zip"));
internalCluster().startNode(SETTINGS);
internalCluster().startNode(initialSettings.v1());
assertPluginLoaded(pluginName);
assertPluginAvailable(pluginName);
@ -289,28 +271,34 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
@Test(expected = IllegalArgumentException.class)
public void testSitePluginWithSourceThrows() throws Exception {
String pluginName = "plugin-with-source";
downloadAndExtract(pluginName, getPluginUrlForResource("plugin_with_sourcefiles.zip"));
downloadAndExtract(pluginName, buildInitialSettings(), getPluginUrlForResource("plugin_with_sourcefiles.zip"));
}
private static PluginManager pluginManager(String pluginUrl) throws IOException {
Tuple<Settings, Environment> initialSettings = InternalSettingsPreparer.prepareSettings(
ImmutableSettings.settingsBuilder().build(), false);
return pluginManager(pluginUrl, initialSettings);
private PluginManager pluginManager(String pluginUrl) throws IOException {
return pluginManager(pluginUrl, buildInitialSettings());
}
private Tuple<Settings, Environment> buildInitialSettings() throws IOException {
Settings settings = ImmutableSettings.settingsBuilder()
.put("discovery.zen.ping.multicast.enabled", false)
.put("http.enabled", true)
.put("path.home", newTempDirPath()).build();
return InternalSettingsPreparer.prepareSettings(settings, false);
}
/**
* We build a plugin manager instance which wait only for 30 seconds before
* raising an ElasticsearchTimeoutException
*/
private static PluginManager pluginManager(String pluginUrl, Tuple<Settings, Environment> initialSettings) throws IOException {
private PluginManager pluginManager(String pluginUrl, Tuple<Settings, Environment> initialSettings) throws IOException {
if (!Files.exists(initialSettings.v2().pluginsFile())) {
Files.createDirectories(initialSettings.v2().pluginsFile());
}
return new PluginManager(initialSettings.v2(), pluginUrl, PluginManager.OutputMode.SILENT, TimeValue.timeValueSeconds(30));
return new PluginManager(initialSettings.v2(), pluginUrl, PluginManager.OutputMode.VERBOSE, TimeValue.timeValueSeconds(30));
}
private static void downloadAndExtract(String pluginName, String pluginUrl) throws IOException {
pluginManager(pluginUrl).downloadAndExtract(pluginName);
private void downloadAndExtract(String pluginName, Tuple<Settings, Environment> initialSettings, String pluginUrl) throws IOException {
pluginManager(pluginUrl, initialSettings).downloadAndExtract(pluginName);
}
private void assertPluginLoaded(String pluginName) {
@ -332,7 +320,7 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
}
private void assertPluginAvailable(String pluginName) throws InterruptedException, IOException {
final HttpRequestBuilder httpRequestBuilder = getHttpRequestBuilder();
final HttpRequestBuilder httpRequestBuilder = httpClient();
//checking that the http connector is working properly
// We will try it for some seconds as it could happen that the REST interface is not yet fully started
@ -356,15 +344,11 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
//checking now that the plugin is available
HttpResponse response = getHttpRequestBuilder().method("GET").path("/_plugin/" + pluginName + "/").execute();
HttpResponse response = httpClient().method("GET").path("/_plugin/" + pluginName + "/").execute();
assertThat(response, notNullValue());
assertThat(response.getReasonPhrase(), response.getStatusCode(), equalTo(RestStatus.OK.getStatus()));
}
private HttpRequestBuilder getHttpRequestBuilder() {
return new HttpRequestBuilder(HttpClients.createDefault()).httpTransport(internalCluster().getDataNodeInstance(HttpServerTransport.class));
}
@Test
public void testListInstalledEmpty() throws IOException {
Path[] plugins = pluginManager(null).getListInstalledPlugins();
@ -390,7 +374,8 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
@Test
public void testInstallSitePlugin() throws IOException {
PluginManager pluginManager = pluginManager(getPluginUrlForResource("plugin_without_folders.zip"));
Tuple<Settings, Environment> initialSettings = buildInitialSettings();
PluginManager pluginManager = pluginManager(getPluginUrlForResource("plugin_without_folders.zip"), initialSettings);
pluginManager.downloadAndExtract("plugin-site");
Path[] plugins = pluginManager.getListInstalledPlugins();
@ -398,8 +383,7 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
assertThat(plugins.length, is(1));
// We want to check that Plugin Manager moves content to _site
String pluginDir = PLUGIN_DIR.concat("/plugin-site/_site");
assertFileExists(Paths.get(pluginDir));
assertFileExists(initialSettings.v2().pluginsFile().resolve("plugin-site/_site"));
}
@ -479,10 +463,6 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest {
return false;
}
private void deletePluginsFolder() throws IOException {
IOUtils.rm(Paths.get(PLUGIN_DIR));
}
@Test
public void testRemovePlugin() throws Exception {
// We want to remove plugin with plugin short name

View File

@ -18,6 +18,7 @@
*/
package org.elasticsearch.test;
import com.carrotsearch.randomizedtesting.LifecycleScope;
import com.carrotsearch.randomizedtesting.RandomizedContext;
import com.carrotsearch.randomizedtesting.Randomness;
import com.carrotsearch.randomizedtesting.generators.RandomInts;
@ -25,7 +26,6 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import org.apache.http.impl.client.HttpClients;
import org.apache.lucene.store.StoreRateLimiting;
import org.apache.lucene.util.AbstractRandomizedTest;
@ -92,16 +92,23 @@ import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.discovery.zen.elect.ElectMasterService;
import org.elasticsearch.http.HttpServerTransport;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.FieldMapper.Loading;
import org.elasticsearch.index.mapper.internal.*;
import org.elasticsearch.index.merge.policy.*;
import org.elasticsearch.index.mapper.internal.AllFieldMapper;
import org.elasticsearch.index.mapper.internal.SizeFieldMapper;
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
import org.elasticsearch.index.mapper.internal.TimestampFieldMapper;
import org.elasticsearch.index.merge.policy.AbstractMergePolicyProvider;
import org.elasticsearch.index.merge.policy.LogByteSizeMergePolicyProvider;
import org.elasticsearch.index.merge.policy.LogDocMergePolicyProvider;
import org.elasticsearch.index.merge.policy.MergePolicyModule;
import org.elasticsearch.index.merge.policy.MergePolicyProvider;
import org.elasticsearch.index.merge.policy.TieredMergePolicyProvider;
import org.elasticsearch.index.merge.scheduler.ConcurrentMergeSchedulerProvider;
import org.elasticsearch.index.merge.scheduler.MergeSchedulerModule;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.store.StoreModule;
import org.elasticsearch.index.translog.TranslogService;
import org.elasticsearch.index.translog.fs.FsTranslog;
@ -122,7 +129,11 @@ import org.elasticsearch.test.rest.client.http.HttpRequestBuilder;
import org.elasticsearch.transport.netty.NettyTransport;
import org.hamcrest.Matchers;
import org.joda.time.DateTimeZone;
import org.junit.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import java.io.IOException;
import java.io.InputStream;
@ -136,8 +147,20 @@ import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@ -146,8 +169,13 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.test.InternalTestCluster.clusterName;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
import static org.hamcrest.Matchers.*;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout;
import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* {@link ElasticsearchIntegrationTest} is an abstract base class to run integration
@ -173,7 +201,7 @@ import static org.hamcrest.Matchers.*;
* If no {@link ClusterScope} annotation is present on an integration test the default scope is {@link Scope#SUITE}
* <p/>
* A test cluster creates a set of nodes in the background before the test starts. The number of nodes in the cluster is
* determined at random and can change across tests. The {@link ClusterScope} allows configuring the initial number of nodes
* determined at random and can change across tests. The {@link ClusterScope} allows configuring the initial number of nodes
* that are created before the tests start.
* <p/>
* <pre>
@ -325,7 +353,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
randomSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, numberOfShards())
.put(SETTING_NUMBER_OF_REPLICAS, numberOfReplicas());
randomSettingsBuilder.put("index.codec", randomFrom("default", "best_compression"));
XContentBuilder mappings = null;
if (frequently() && randomDynamicTemplates()) {
@ -469,7 +497,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
if (random.nextBoolean()) {
builder.put(IndicesQueryCache.INDEX_CACHE_QUERY_ENABLED, random.nextBoolean());
}
if (random.nextBoolean()) {
builder.put("index.shard.check_on_startup", randomFrom(random, "false", "checksum", "true"));
}
@ -778,7 +806,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
}
// 30% of the time
if (randomInt(9) < 3) {
String dataPath = "data/custom-" + CHILD_JVM_ID + "/" + UUID.randomUUID().toString();
final Path dataPath = newTempDirPath(LifecycleScope.SUITE);
logger.info("using custom data_path for index: [{}]", dataPath);
builder.put(IndexMetaData.SETTING_DATA_PATH, dataPath);
}
@ -1647,7 +1675,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
protected Settings transportClientSettings() {
return ImmutableSettings.EMPTY;
}
private ExternalTestCluster buildExternalCluster(String clusterAddresses) {
String[] stringAddresses = clusterAddresses.split(",");
TransportAddress[] transportAddresses = new TransportAddress[stringAddresses.length];
@ -1676,12 +1704,15 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
}
final String nodePrefix;
final LifecycleScope nodeDirScope;
switch (scope) {
case TEST:
nodePrefix = TEST_CLUSTER_NODE_PREFIX;
nodeDirScope = LifecycleScope.TEST;
break;
case SUITE:
nodePrefix = SUITE_CLUSTER_NODE_PREFIX;
nodeDirScope = LifecycleScope.SUITE;
break;
default:
throw new ElasticsearchException("Scope not supported: " + scope);
@ -1692,13 +1723,13 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
return ImmutableSettings.builder().put(Node.HTTP_ENABLED, false).
put(nodeSettings(nodeOrdinal)).build();
}
@Override
public Settings transportClient() {
return transportClientSettings();
}
};
int numDataNodes = getNumDataNodes();
int minNumDataNodes;
int maxNumDataNodes;
@ -1709,7 +1740,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
maxNumDataNodes = getMaxNumDataNodes();
}
return new InternalTestCluster(seed, minNumDataNodes, maxNumDataNodes,
return new InternalTestCluster(seed, newTempDirPath(nodeDirScope), minNumDataNodes, maxNumDataNodes,
clusterName(scope.name(), Integer.toString(CHILD_JVM_ID), seed), settingsSource, getNumClientNodes(),
InternalTestCluster.DEFAULT_ENABLE_HTTP_PIPELINING, CHILD_JVM_ID, nodePrefix);
}

View File

@ -18,6 +18,7 @@
*/
package org.elasticsearch.test;
import com.carrotsearch.randomizedtesting.LifecycleScope;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
@ -42,10 +43,15 @@ import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.threadpool.ThreadPool;
import org.junit.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
/**
* A test that keep a singleton node started for all tests that can be used to get
@ -114,15 +120,16 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
private static Node newNode() {
Node build = NodeBuilder.nodeBuilder().local(true).data(true).settings(ImmutableSettings.builder()
.put(ClusterName.SETTING, clusterName())
.put("node.name", nodeName())
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put("script.inline", "on")
.put("script.indexed", "on")
.put(EsExecutors.PROCESSORS, 1) // limit the number of threads created
.put("http.enabled", false)
.put("config.ignore_system_properties", true) // make sure we get what we set :)
.put(ClusterName.SETTING, clusterName())
.put("path.home", newTempDirPath(LifecycleScope.SUITE))
.put("node.name", nodeName())
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put("script.inline", "on")
.put("script.indexed", "on")
.put(EsExecutors.PROCESSORS, 1) // limit the number of threads created
.put("http.enabled", false)
.put("config.ignore_system_properties", true) // make sure we get what we set :)
).build();
build.start();
assertThat(DiscoveryNode.localNode(build.settings()), is(true));

View File

@ -25,7 +25,12 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks;
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.*;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
@ -107,20 +112,34 @@ import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static junit.framework.Assert.fail;
import static org.apache.lucene.util.LuceneTestCase.*;
import static org.apache.lucene.util.LuceneTestCase.TEST_NIGHTLY;
import static org.apache.lucene.util.LuceneTestCase.rarely;
import static org.apache.lucene.util.LuceneTestCase.usually;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
import static org.elasticsearch.test.ElasticsearchTestCase.assertBusy;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
@ -198,18 +217,20 @@ public final class InternalTestCluster extends TestCluster {
* All nodes started by the cluster will have their name set to nodePrefix followed by a positive number
*/
private final String nodePrefix;
private final Path baseDir;
private ServiceDisruptionScheme activeDisruptionScheme;
public InternalTestCluster(long clusterSeed, int minNumDataNodes, int maxNumDataNodes, String clusterName, int numClientNodes,
public InternalTestCluster(long clusterSeed, Path baseDir, int minNumDataNodes, int maxNumDataNodes, String clusterName, int numClientNodes,
boolean enableHttpPipelining, int jvmOrdinal, String nodePrefix) {
this(clusterSeed, minNumDataNodes, maxNumDataNodes, clusterName, DEFAULT_SETTINGS_SOURCE, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix);
this(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, DEFAULT_SETTINGS_SOURCE, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix);
}
public InternalTestCluster(long clusterSeed,
public InternalTestCluster(long clusterSeed, Path baseDir,
int minNumDataNodes, int maxNumDataNodes, String clusterName, SettingsSource settingsSource, int numClientNodes,
boolean enableHttpPipelining, int jvmOrdinal, String nodePrefix) {
super(clusterSeed);
this.baseDir = baseDir;
this.clusterName = clusterName;
if (minNumDataNodes < 0 || maxNumDataNodes < 0) {
@ -262,11 +283,12 @@ public final class InternalTestCluster extends TestCluster {
if (numOfDataPaths > 0) {
StringBuilder dataPath = new StringBuilder();
for (int i = 0; i < numOfDataPaths; i++) {
dataPath.append(Paths.get("data/d" + i).toAbsolutePath()).append(',');
dataPath.append(baseDir.resolve("d" + i).toAbsolutePath()).append(',');
}
builder.put("path.data", dataPath.toString());
}
}
builder.put("path.home", baseDir);
final int basePort = 9300 + (100 * (jvmOrdinal+1));
builder.put("transport.tcp.port", basePort + "-" + (basePort+100));
builder.put("http.port", basePort+101 + "-" + (basePort+200));
@ -569,6 +591,7 @@ public final class InternalTestCluster extends TestCluster {
String name = buildNodeName(nodeId);
assert !nodes.containsKey(name);
Settings finalSettings = settingsBuilder()
.put("path.home", baseDir) // allow overriding path.home
.put(settings)
.put("name", name)
.put("discovery.id.seed", seed)

View File

@ -28,6 +28,7 @@ import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.SettingsSource;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
@ -54,8 +55,9 @@ public class InternalTestClusterTests extends ElasticsearchTestCase {
int jvmOrdinal = randomIntBetween(0, 10);
String nodePrefix = randomRealisticUnicodeOfCodepointLengthBetween(1, 10);
InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix);
InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix);
Path baseDir = newTempDirPath();
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);
}
@ -93,13 +95,13 @@ public class InternalTestClusterTests extends ElasticsearchTestCase {
}
SettingsSource settingsSource = SettingsSource.EMPTY;
int numClientNodes = randomIntBetween(0, 2);
boolean enableRandomBenchNodes = randomBoolean();
boolean enableHttpPipelining = randomBoolean();
int jvmOrdinal = randomIntBetween(0, 10);
String nodePrefix = "foobar";
InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix);
InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, minNumDataNodes, maxNumDataNodes, clusterName1, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix);
Path baseDir = newTempDirPath();
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);
assertClusters(cluster0, cluster1, false);
long seed = randomLong();

View File

@ -19,6 +19,7 @@
package org.elasticsearch.tribe;
import com.carrotsearch.randomizedtesting.LifecycleScope;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
@ -69,7 +70,7 @@ public class TribeTests extends ElasticsearchIntegrationTest {
public static void setupSecondCluster() throws Exception {
ElasticsearchIntegrationTest.beforeClass();
// create another cluster
cluster2 = new InternalTestCluster(randomLong(), 2, 2, Strings.randomBase64UUID(getRandom()), 0, false, CHILD_JVM_ID, SECOND_CLUSTER_NODE_PREFIX);
cluster2 = new InternalTestCluster(randomLong(), newTempDirPath(LifecycleScope.SUITE), 2, 2, Strings.randomBase64UUID(getRandom()), 0, false, CHILD_JVM_ID, SECOND_CLUSTER_NODE_PREFIX);
cluster2.beforeTest(getRandom(), 0.1);
cluster2.ensureAtLeastNumDataNodes(2);
}

View File

@ -19,6 +19,7 @@
package org.elasticsearch.tribe;
import com.carrotsearch.randomizedtesting.LifecycleScope;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNode;
@ -52,11 +53,14 @@ public class TribeUnitTests extends ElasticsearchTestCase {
@BeforeClass
public static void createTribes() {
tribe1 = NodeBuilder.nodeBuilder().settings(ImmutableSettings.builder().put("config.ignore_system_properties", true).put("http.enabled", false)
.put("node.mode", NODE_MODE).put("cluster.name", "tribe1").put("node.name", "tribe1_node")).node();
tribe2 = NodeBuilder.nodeBuilder().settings(ImmutableSettings.builder().put("config.ignore_system_properties", true).put("http.enabled", false)
.put("node.mode", NODE_MODE).put("cluster.name", "tribe2").put("node.name", "tribe2_node")).node();
Settings baseSettings = ImmutableSettings.builder()
.put("config.ignore_system_properties", true)
.put("http.enabled", false)
.put("node.mode", NODE_MODE)
.put("path.home", newTempDirPath(LifecycleScope.SUITE)).build();
tribe1 = NodeBuilder.nodeBuilder().settings(ImmutableSettings.builder().put(baseSettings).put("cluster.name", "tribe1").put("node.name", "tribe1_node")).node();
tribe2 = NodeBuilder.nodeBuilder().settings(ImmutableSettings.builder().put(baseSettings).put("cluster.name", "tribe2").put("node.name", "tribe2_node")).node();
}
@AfterClass