removed some esoteric helper functions, shuffled methods around in base class
This commit is contained in:
parent
e91a7de9f7
commit
d8a92947d1
|
@ -23,6 +23,7 @@ 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.common.xcontent.XContentType;
|
||||
import org.elasticsearch.env.NodeEnvironment;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
@ -113,7 +114,7 @@ public class MetaStateServiceTests extends ElasticsearchTestCase {
|
|||
private Settings randomSettings() {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder();
|
||||
if (randomBoolean()) {
|
||||
builder.put(MetaStateService.FORMAT_SETTING, randomXContentType().shortName());
|
||||
builder.put(MetaStateService.FORMAT_SETTING, randomFrom(XContentType.values()).shortName());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
@ -215,10 +215,11 @@ public class MoreLikeThisActionTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
// See issue https://github.com/elasticsearch/elasticsearch/issues/3252
|
||||
public void testNumericField() throws Exception {
|
||||
final String[] numericTypes = new String[]{"byte", "short", "integer", "long"};
|
||||
prepareCreate("test").addMapping("type", jsonBuilder()
|
||||
.startObject().startObject("type")
|
||||
.startObject("properties")
|
||||
.startObject("int_value").field("type", randomNumericType(getRandom())).endObject()
|
||||
.startObject("int_value").field("type", randomFrom(numericTypes)).endObject()
|
||||
.startObject("string_value").field("type", "string").endObject()
|
||||
.endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
|
|
@ -111,6 +111,10 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
SecurityHack.ensureInitialized();
|
||||
}
|
||||
|
||||
private static Thread.UncaughtExceptionHandler defaultHandler;
|
||||
|
||||
protected final ESLogger logger = Loggers.getLogger(getClass());
|
||||
|
||||
// setup mock filesystems for this test run. we change PathUtils
|
||||
// so that all accesses are plumbed thru any mock wrappers
|
||||
|
||||
|
@ -124,6 +128,33 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setBeforeClass() throws Exception {
|
||||
closeAfterSuite(new Closeable() {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
assertAllFilesClosed();
|
||||
}
|
||||
});
|
||||
closeAfterSuite(new Closeable() {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
assertAllSearchersClosed();
|
||||
}
|
||||
});
|
||||
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(new ElasticsearchUncaughtExceptionHandler(defaultHandler));
|
||||
Requests.CONTENT_TYPE = randomFrom(XContentType.values());
|
||||
Requests.INDEX_CONTENT_TYPE = randomFrom(XContentType.values());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void resetAfterClass() {
|
||||
Thread.setDefaultUncaughtExceptionHandler(defaultHandler);
|
||||
Requests.CONTENT_TYPE = XContentType.SMILE;
|
||||
Requests.INDEX_CONTENT_TYPE = XContentType.JSON;
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void restoreFileSystem() {
|
||||
|
@ -150,6 +181,26 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
System.clearProperty(EsExecutors.DEFAULT_SYSPROP);
|
||||
}
|
||||
|
||||
@After
|
||||
public void ensureAllPagesReleased() throws Exception {
|
||||
MockPageCacheRecycler.ensureAllPagesAreReleased();
|
||||
}
|
||||
|
||||
@After
|
||||
public void ensureAllArraysReleased() throws Exception {
|
||||
MockBigArrays.ensureAllArraysAreReleased();
|
||||
}
|
||||
|
||||
@After
|
||||
public void ensureAllSearchContextsReleased() throws Exception {
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MockSearchService.assertNoInFLightContext();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Before
|
||||
public void disableQueryCache() {
|
||||
// TODO: Parent/child and other things does not work with the query cache
|
||||
|
@ -165,20 +216,6 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
|
||||
// old shit:
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Test groups, system properties and other annotations modifying tests
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @see #ignoreAfterMaxFailures
|
||||
*/
|
||||
public static final String SYSPROP_MAXFAILURES = "tests.maxfailures";
|
||||
|
||||
/**
|
||||
* @see #ignoreAfterMaxFailures
|
||||
*/
|
||||
public static final String SYSPROP_FAILFAST = "tests.failfast";
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Suite and test case setup/ cleanup.
|
||||
// -----------------------------------------------------------------
|
||||
|
@ -204,12 +241,29 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Test facilities and facades for subclasses.
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
// old helper stuff, a lot of it is bad news and we should see if its all used
|
||||
|
||||
/**
|
||||
* Shortcut for {@link RandomizedContext#getRandom()}. Even though this method
|
||||
* is static, it returns per-thread {@link Random} instance, so no race conditions
|
||||
* can occur.
|
||||
*
|
||||
* <p>It is recommended that specific methods are used to pick random values.
|
||||
*/
|
||||
public static Random getRandom() {
|
||||
return random();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for {@link RandomizedContext#current()}.
|
||||
*/
|
||||
public static RandomizedContext getContext() {
|
||||
return RandomizedTest.getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a "scaled" random number between min and max (inclusive).
|
||||
|
@ -276,17 +330,6 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
return RandomPicks.randomFrom(random(), list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for {@link RandomizedContext#getRandom()}. Even though this method
|
||||
* is static, it returns per-thread {@link Random} instance, so no race conditions
|
||||
* can occur.
|
||||
*
|
||||
* <p>It is recommended that specific methods are used to pick random values.
|
||||
*/
|
||||
public static Random getRandom() {
|
||||
return random();
|
||||
}
|
||||
|
||||
/**
|
||||
* A random integer from 0..max (inclusive).
|
||||
*/
|
||||
|
@ -344,21 +387,6 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
return RandomizedTest.randomRealisticUnicodeOfCodepointLength(codePoints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for {@link RandomizedContext#current()}.
|
||||
*/
|
||||
public static RandomizedContext getContext() {
|
||||
return RandomizedTest.getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if we're running nightly tests.
|
||||
* @see Nightly
|
||||
*/
|
||||
public static boolean isNightly() {
|
||||
return RandomizedTest.isNightly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a non-negative random value smaller or equal <code>max</code>.
|
||||
* @see RandomizedTest#atMost(int);
|
||||
|
@ -367,16 +395,6 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
return RandomizedTest.atMost(max);
|
||||
}
|
||||
|
||||
private static Thread.UncaughtExceptionHandler defaultHandler;
|
||||
|
||||
protected final ESLogger logger = Loggers.getLogger(getClass());
|
||||
|
||||
|
||||
|
||||
static {
|
||||
SecurityHack.ensureInitialized();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the code block for 10 seconds waiting for no assertion to trip.
|
||||
*/
|
||||
|
@ -425,8 +443,7 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean awaitBusy(Predicate<?> breakPredicate) throws InterruptedException {
|
||||
return awaitBusy(breakPredicate, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
@ -449,12 +466,6 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
return breakPredicate.apply(null);
|
||||
}
|
||||
|
||||
private static final String[] numericTypes = new String[]{"byte", "short", "integer", "long"};
|
||||
|
||||
public static String randomNumericType(Random random) {
|
||||
return numericTypes[random.nextInt(numericTypes.length)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link java.nio.file.Path} pointing to the class path relative resource given
|
||||
* as the first argument. In contrast to
|
||||
|
@ -474,57 +485,6 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void ensureAllPagesReleased() throws Exception {
|
||||
MockPageCacheRecycler.ensureAllPagesAreReleased();
|
||||
}
|
||||
|
||||
@After
|
||||
public void ensureAllArraysReleased() throws Exception {
|
||||
MockBigArrays.ensureAllArraysAreReleased();
|
||||
}
|
||||
|
||||
@After
|
||||
public void ensureAllSearchContextsReleased() throws Exception {
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MockSearchService.assertNoInFLightContext();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setBeforeClass() throws Exception {
|
||||
closeAfterSuite(new Closeable() {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
assertAllFilesClosed();
|
||||
}
|
||||
});
|
||||
closeAfterSuite(new Closeable() {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
assertAllSearchersClosed();
|
||||
}
|
||||
});
|
||||
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(new ElasticsearchUncaughtExceptionHandler(defaultHandler));
|
||||
Requests.CONTENT_TYPE = randomXContentType();
|
||||
Requests.INDEX_CONTENT_TYPE = randomXContentType();
|
||||
}
|
||||
|
||||
public static XContentType randomXContentType() {
|
||||
return randomFrom(XContentType.values());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void resetAfterClass() {
|
||||
Thread.setDefaultUncaughtExceptionHandler(defaultHandler);
|
||||
Requests.CONTENT_TYPE = XContentType.SMILE;
|
||||
Requests.INDEX_CONTENT_TYPE = XContentType.JSON;
|
||||
}
|
||||
|
||||
private static final List<Version> SORTED_VERSIONS;
|
||||
|
||||
static {
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Set;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.RandomizedTest;
|
||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||
import org.apache.lucene.util.TestUtil;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
|
@ -556,7 +557,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
|
||||
int numIDs;
|
||||
if (isNightly()) {
|
||||
if (TEST_NIGHTLY) {
|
||||
numIDs = scaledRandomIntBetween(300, 1000);
|
||||
} else {
|
||||
numIDs = scaledRandomIntBetween(50, 100);
|
||||
|
@ -572,7 +573,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
// Attach random versions to them:
|
||||
long version = 0;
|
||||
final IDAndVersion[] idVersions = new IDAndVersion[TestUtil.nextInt(random, numIDs/2, numIDs*(isNightly() ? 8 : 2))];
|
||||
final IDAndVersion[] idVersions = new IDAndVersion[TestUtil.nextInt(random, numIDs/2, numIDs*(TEST_NIGHTLY ? 8 : 2))];
|
||||
final Map<String,IDAndVersion> truth = new HashMap<>();
|
||||
|
||||
if (VERBOSE) {
|
||||
|
@ -615,7 +616,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
final AtomicInteger upto = new AtomicInteger();
|
||||
final CountDownLatch startingGun = new CountDownLatch(1);
|
||||
Thread[] threads = new Thread[TestUtil.nextInt(random, 1, isNightly() ? 20 : 5)];
|
||||
Thread[] threads = new Thread[TestUtil.nextInt(random, 1, TEST_NIGHTLY ? 20 : 5)];
|
||||
final long startTime = System.nanoTime();
|
||||
for(int i=0;i<threads.length;i++) {
|
||||
final int threadID = i;
|
||||
|
|
Loading…
Reference in New Issue