Randomize numeric types in MLT test and apply mapping ahead of time.

This commit is contained in:
Simon Willnauer 2013-08-23 09:42:08 +02:00
parent 8b9396b6da
commit 7c76819040
2 changed files with 14 additions and 1 deletions

View File

@ -29,6 +29,7 @@ import org.apache.lucene.util.TimeUnits;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@ThreadLeakFilters(defaultFilters = true, filters = {ElasticsearchTestCase.ElasticSearchThreadFilter.class})
@ -69,5 +70,11 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest {
Thread.sleep(Math.max(timeInMillis, 0));
}
private static final String[] numericTypes = new String[] {"byte", "short", "integer", "long"};
public static String randomNumericType(Random random) {
return numericTypes[random.nextInt(numericTypes.length)];
}
}

View File

@ -179,7 +179,13 @@ public class MoreLikeThisActionTests extends AbstractSharedClusterTest {
@Test
// See issue https://github.com/elasticsearch/elasticsearch/issues/3252
public void testNumericField() throws Exception {
prepareCreate("test").execute().actionGet();
prepareCreate("test").addMapping("type", jsonBuilder()
.startObject().startObject("type")
.startObject("properties")
.startObject("int_value").field("type", randomNumericType(getRandom())).endObject()
.startObject("string_value").field("type", "string").endObject()
.endObject()
.endObject().endObject()).execute().actionGet();
ensureGreen();
client().prepareIndex("test", "type", "1")
.setSource(jsonBuilder().startObject().field("string_value", "lucene index").field("int_value", 1).endObject())