Remove createMapped and mapping helpers from AbstractSharedClusterTest

our tests should use the API we have in favor of hard to read / understand
test helpers.
This commit is contained in:
Simon Willnauer 2013-09-06 15:09:48 +02:00
parent da4c58d853
commit a5bf8824d2
13 changed files with 425 additions and 237 deletions

View File

@ -53,11 +53,9 @@ import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.indices.IndexTemplateMissingException;
import org.junit.*;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ExecutionException;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo;
@ -186,21 +184,6 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase {
}
}
public void createIndexMapped(String name, String type, String... simpleMapping) throws IOException {
XContentBuilder builder = jsonBuilder().startObject().startObject(type).startObject("properties");
for (int i = 0; i < simpleMapping.length; i++) {
builder.startObject(simpleMapping[i++]).field("type", simpleMapping[i]).endObject();
}
builder.endObject().endObject().endObject();
try {
prepareCreate(name).setSettings(getSettings()).addMapping(type, builder).execute().actionGet();
return;
} catch (IndexAlreadyExistsException ex) {
wipeIndex(name);
}
prepareCreate(name).setSettings(getSettings()).addMapping(type, builder).execute().actionGet();
}
public CreateIndexRequestBuilder prepareCreate(String index, int numNodes) {
return prepareCreate(index, numNodes, ImmutableSettings.builder());
}
@ -215,39 +198,6 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase {
return client().admin().indices().prepareCreate(index).setSettings(builder.build());
}
public CreateIndexRequestBuilder addMapping(CreateIndexRequestBuilder builder, String type, Object[]... mapping) throws IOException {
XContentBuilder mappingBuilder = jsonBuilder();
mappingBuilder.startObject().startObject(type);
for (Object[] objects : mapping) {
if (!objects[0].toString().equals("_all")) {
continue;
}
mappingBuilder.startObject("_all");
for (int i = 1; i < objects.length; i++) {
String name = objects[i++].toString();
Object value = objects[i];
mappingBuilder.field(name, value);
}
mappingBuilder.endObject();
}
mappingBuilder.startObject("properties");
for (Object[] objects : mapping) {
if (objects[0].toString().equals("_all")) {
continue;
}
mappingBuilder.startObject(objects[0].toString());
for (int i = 1; i < objects.length; i++) {
String name = objects[i++].toString();
Object value = objects[i];
mappingBuilder.field(name, value);
}
mappingBuilder.endObject();
}
mappingBuilder.endObject().endObject().endObject();
builder.addMapping(type, mappingBuilder);
return builder;
}
private ImmutableSettings.Builder getExcludeSettings(String index, int num, ImmutableSettings.Builder builder) {
String exclude = Joiner.on(',').join(cluster().allButN(num));
builder.put("index.routing.allocation.exclude._name", exclude);
@ -339,7 +289,7 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase {
return client().prepareIndex(index, type).setSource(source).execute().actionGet();
}
protected IndexResponse index(String index, String type, String id, Map<String, ? extends Object> source) {
protected IndexResponse index(String index, String type, String id, Map<String, Object> source) {
return client().prepareIndex(index, type, id).setSource(source).execute().actionGet();
}
@ -426,13 +376,14 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase {
Collections.shuffle(list, random);
for (IndexRequestBuilder indexRequestBuilder : list) {
indexRequestBuilder.execute().actionGet();
if (frequently()) {
if (rarely()) {
if (rarely()) {
client().admin().indices().prepareRefresh(index).execute().get();
} else if (rarely()) {
client().admin().indices().prepareFlush(index).execute().get();
} else if (rarely()) {
client().admin().indices().prepareOptimize(index).setMaxNumSegments(between(1, 10)).setFlush(random.nextBoolean()).execute().get();
client().admin().indices().prepareOptimize(index).setMaxNumSegments(between(1, 10)).setFlush(random.nextBoolean()).execute().get();
}
client().admin().indices().prepareRefresh(index).execute().get();
}
}
if (forceRefresh) {

View File

@ -40,8 +40,7 @@ import java.io.IOException;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.FilterBuilders.*;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
/**
*
@ -673,7 +672,10 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
@Test
public void testEmptyTermsFilter() throws Exception {
createIndexMapped("test", "type", "term", "string");
assertAcked(prepareCreate("test").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("terms").field("type", "string").endObject()
.endObject().endObject().endObject()));
ensureGreen();
client().prepareIndex("test", "type", "1").setSource("term", "1").execute().actionGet();
client().prepareIndex("test", "type", "2").setSource("term", "2").execute().actionGet();
@ -695,9 +697,19 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
@Test
public void testTermsLookupFilter() throws Exception {
createIndexMapped("lookup", "type", "terms", "string", "other", "string");
createIndexMapped("lookup2", "type", "term", "string");
createIndexMapped("test", "type", "term", "string");
assertAcked(prepareCreate("lookup").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("terms").field("type", "string").endObject()
.startObject("other").field("type", "string").endObject()
.endObject().endObject().endObject()));
assertAcked(prepareCreate("lookup2").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("terms").field("type", "string").endObject()
.endObject().endObject().endObject()));
assertAcked(prepareCreate("test").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("terms").field("type", "string").endObject()
.endObject().endObject().endObject()));
ensureGreen();
client().prepareIndex("lookup", "type", "1").setSource("terms", new String[]{"1", "3"}).execute().actionGet();
client().prepareIndex("lookup", "type", "2").setSource("terms", new String[]{"2"}).execute().actionGet();

View File

@ -22,6 +22,8 @@ import java.util.Map;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.hamcrest.Matchers.*;
@ -119,8 +121,12 @@ public class UpdateMappingTests extends AbstractSharedClusterTest {
@SuppressWarnings("unchecked")
@Test
public void updateIncludeExclude() throws Exception {
createIndexMapped("test", "type", "normal", "long", "exclude", "long", "include", "long");
assertAcked(prepareCreate("test").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("normal").field("type", "long").endObject()
.startObject("exclude").field("type", "long").endObject()
.startObject("include").field("type", "long").endObject()
.endObject().endObject().endObject()));
ensureGreen(); // make sure that replicas are initialized so the refresh command will work them too
logger.info("Index doc");

View File

@ -45,7 +45,11 @@ public class MoreLikeThisActionTests extends AbstractSharedClusterTest {
@Test
public void testSimpleMoreLikeThis() throws Exception {
logger.info("Creating index test");
createIndexMapped("test", "type1", "text", "string");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("text").field("type", "string").endObject()
.endObject().endObject().endObject()));
logger.info("Running Cluster Health");
assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
@ -84,7 +88,10 @@ public class MoreLikeThisActionTests extends AbstractSharedClusterTest {
@Test
public void testMoreLikeThisWithAliases() throws Exception {
logger.info("Creating index test");
createIndexMapped("test", "type1", "text", "string");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("text").field("type", "string").endObject()
.endObject().endObject().endObject()));
logger.info("Creating aliases alias release");
client().admin().indices().aliases(indexAliasesRequest().addAlias("test", "release", termFilter("text", "release"))).actionGet();
client().admin().indices().aliases(indexAliasesRequest().addAlias("test", "beta", termFilter("text", "beta"))).actionGet();

View File

@ -29,6 +29,7 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.index.query.QueryBuilders;
@ -38,6 +39,7 @@ import org.elasticsearch.search.facet.statistical.StatisticalFacet;
import org.elasticsearch.search.facet.termsstats.TermsStatsFacet;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.junit.Assert;
import org.junit.Test;
@ -53,7 +55,21 @@ public class SimpleNestedTests extends AbstractSharedClusterTest {
@Test
public void simpleNested() throws Exception {
run(addMapping(prepareCreate("test"), "type1", new Object[] {"nested1", "type", "nested"}));
XContentBuilder builder = jsonBuilder().
startObject().
field("type1").
startObject().
field("properties").
startObject().
field("nested1").
startObject().
field("type").
value("nested").
endObject().
endObject().
endObject().
endObject();
ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("type1", builder));
ensureGreen();
// check on no data, see it works

View File

@ -45,14 +45,18 @@ import static org.elasticsearch.index.query.QueryBuilders.functionScoreQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.*;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.*;
public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test
public void testDistanceScoreGeoLinGaussExp() throws Exception {
createIndexMapped("test", "type1", "test", "string", "loc", "geo_point");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("test").field("type", "string").endObject()
.startObject("loc").field("type", "geo_point").endObject()
.endObject().endObject().endObject()));
ensureYellow();
List<IndexRequestBuilder> indexBuilders = new ArrayList<IndexRequestBuilder>();
@ -150,8 +154,11 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test
public void testDistanceScoreGeoLinGaussExpWithOffset() throws Exception {
createIndexMapped("test", "type1", "test", "string", "num", "double");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("test").field("type", "string").endObject()
.startObject("num").field("type", "double").endObject()
.endObject().endObject().endObject()));
ensureYellow();
// add tw docs within offset
@ -228,8 +235,11 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test
public void testBoostModeSettingWorks() throws Exception {
createIndexMapped("test", "type1", "test", "string", "loc", "geo_point");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("test").field("type", "string").endObject()
.startObject("loc").field("type", "geo_point").endObject()
.endObject().endObject().endObject()));
ensureYellow();
List<IndexRequestBuilder> indexBuilders = new ArrayList<IndexRequestBuilder>();
@ -284,8 +294,11 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test
public void testParseGeoPoint() throws Exception {
createIndexMapped("test", "type1", "test", "string", "loc", "geo_point");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("test").field("type", "string").endObject()
.startObject("loc").field("type", "geo_point").endObject()
.endObject().endObject().endObject()));
ensureYellow();
List<IndexRequestBuilder> indexBuilders = new ArrayList<IndexRequestBuilder>();
@ -328,7 +341,11 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test
public void testCombineModes() throws Exception {
createIndexMapped("test", "type1", "test", "string", "num", "double");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("test").field("type", "string").endObject()
.startObject("num").field("type", "double").endObject()
.endObject().endObject().endObject()));
ensureYellow();
List<IndexRequestBuilder> indexBuilders = new ArrayList<IndexRequestBuilder>();
@ -417,8 +434,11 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test(expected = SearchPhaseExecutionException.class)
public void testExceptionThrownIfScaleLE0() throws Exception {
createIndexMapped("test", "type1", "test", "string", "num1", "date");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("test").field("type", "string").endObject()
.startObject("num1").field("type", "date").endObject()
.endObject().endObject().endObject()));
ensureYellow();
client().index(
indexRequest("test").type("type1").id("1")
@ -444,7 +464,6 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test(expected = ElasticSearchIllegalStateException.class)
public void testExceptionThrownIfScaleRefNotBetween0And1() throws Exception {
DecayFunctionBuilder gfb = new GaussDecayFunctionBuilder("num1", "2013-05-28", "1d").setDecay(100);
}
@ -452,7 +471,12 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test
public void testValueMissingLin() throws Exception {
createIndexMapped("test", "type1", "test", "string", "num1", "date", "num2", "double");
assertAcked(prepareCreate("test").addMapping("type1",
jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("test").field("type", "string").endObject()
.startObject("num1").field("type", "date").endObject()
.startObject("num2").field("type", "double").endObject()
.endObject().endObject().endObject()));
ensureYellow();
client().index(
indexRequest("test")
@ -497,8 +521,13 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test
public void testManyDocsLin() throws Exception {
createIndexMapped("test", "type", "test", "string", "date", "date", "num", "double", "geo", "geo_point");
assertAcked(prepareCreate("test").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("test").field("type", "string").endObject()
.startObject("date").field("type", "date").endObject()
.startObject("num").field("type", "double").endObject()
.startObject("geo").field("type", "geo_point").endObject()
.endObject().endObject().endObject()));
ensureYellow();
int numDocs = 200;
List<IndexRequestBuilder> indexBuilders = new ArrayList<IndexRequestBuilder>();
@ -519,18 +548,13 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
.field("lat", lat).field("lon", lon).endObject().endObject()));
}
IndexRequestBuilder[] builders = indexBuilders.toArray(new IndexRequestBuilder[indexBuilders.size()]);
indexRandom("test", false, builders);
refresh();
indexRandom("test", true, builders);
List<Float> lonlat = new ArrayList<Float>();
lonlat.add(new Float(100));
lonlat.add(new Float(110));
ActionFuture<SearchResponse> response = client().search(
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
searchSource()
.explain(true)
.size(numDocs)
.query(functionScoreQuery(termQuery("test", "value"))
.add(new MatchAllFilterBuilder(), linearDecayFunction("date", "2013-05-30", "+15d"))
@ -556,8 +580,11 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test(expected = SearchPhaseExecutionException.class)
public void testParsingExceptionIfFieldDoesNotExist() throws Exception {
createIndexMapped("test", "type", "test", "string", "geo", "geo_point");
assertAcked(prepareCreate("test").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("test").field("type", "string").endObject()
.startObject("geo").field("type", "geo_point").endObject()
.endObject().endObject().endObject()));
ensureYellow();
int numDocs = 2;
client().index(
@ -581,7 +608,11 @@ public class DecayFunctionScoreTests extends AbstractSharedClusterTest {
@Test(expected = SearchPhaseExecutionException.class)
public void testParsingExceptionIfFieldTypeDoesNotMatch() throws Exception {
createIndexMapped("test", "type", "test", "string", "num", "string");
assertAcked(prepareCreate("test").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("test").field("type", "string").endObject()
.startObject("num").field("type", "string").endObject()
.endObject().endObject().endObject()));
ensureYellow();
client().index(
indexRequest("test").type("type").source(

View File

@ -36,6 +36,7 @@ import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.highlight.HighlightBuilder;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.junit.Test;
@ -161,18 +162,29 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
assertHighlight(search, 0, "name.autocomplete", 0, equalTo("ARCO<em>TEL</em> Ho<em>tel</em>s <em>Deut</em>schland"));
}
@Test
public void testMultiPhraseCutoff() throws ElasticSearchException, IOException {
/*
* MultiPhraseQuery can literally kill an entire node if there are too many terms in the
* query. We cut off and extract terms if there are more than 16 terms in the query
*/
run(addMapping(prepareCreate("test"), "test",
new Object[] {
"body", "type", "string", "index_analyzer", "custom_analyzer", "search_analyzer", "custom_analyzer",
"term_vector", "with_positions_offsets" }).setSettings(
XContentBuilder builder = jsonBuilder().
startObject().
field("test").
startObject().
field("properties").
startObject().
field("body").
startObject().
field("type", "string").
field("index_analyzer", "custom_analyzer").
field("search_analyzer", "custom_analyzer").
field("term_vector", "with_positions_offsets").
endObject().
endObject().
endObject().
endObject();
ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("test", builder).setSettings(
ImmutableSettings.settingsBuilder() .put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0)
.put("analysis.filter.wordDelimiter.type", "word_delimiter")
@ -183,8 +195,8 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
.put("analysis.filter.wordDelimiter.catenate_numbers", true)
.put("analysis.filter.wordDelimiter.catenate_all", false)
.put("analysis.analyzer.custom_analyzer.tokenizer", "whitespace")
.putArray("analysis.analyzer.custom_analyzer.filter", "lowercase", "wordDelimiter")));
.putArray("analysis.analyzer.custom_analyzer.filter", "lowercase", "wordDelimiter"))
);
ensureGreen();
client().prepareIndex("test", "test", "1")
.setSource(XContentFactory.jsonBuilder()

View File

@ -126,7 +126,7 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
createIndex("test");
indexRandom("test", true, client().prepareIndex("test", "type1", "1").setSource("field1", "quick brown fox", "field2", "quick brown fox"),
client().prepareIndex("test", "type1", "2").setSource("field1", "quick lazy huge brown fox", "field2", "quick lazy huge brown fox"));
refresh();
ensureYellow();
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick"))).get();
SearchHits hits = searchResponse.getHits();
assertThat(hits.totalHits(), equalTo(2l));
@ -134,19 +134,19 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
assertThat(searchHit.getScore(), equalTo(1.0f));
}
searchResponse = client().prepareSearch().setQuery(
searchResponse = client().prepareSearch("test").setQuery(
QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must(
QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat()))).get();
hits = searchResponse.getHits();
assertThat(hits.totalHits(), equalTo(2l));
assertThat(hits.getAt(0).score(), equalTo(hits.getAt(1).score()));
client().prepareSearch().setQuery(QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat())).get();
client().prepareSearch("test").setQuery(QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat())).get();
hits = searchResponse.getHits();
assertThat(hits.totalHits(), equalTo(2l));
assertThat(hits.getAt(0).score(), equalTo(hits.getAt(1).score()));
searchResponse = client().prepareSearch().setQuery(
searchResponse = client().prepareSearch("test").setQuery(
QueryBuilders.constantScoreQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must(
QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + (random.nextBoolean()? 0.0f : random.nextFloat()))))).get();
hits = searchResponse.getHits();
@ -163,6 +163,7 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
}
createIndex("test_1");
indexRandom("test_1", true, builders);
ensureYellow();
int queryRounds = atLeast(10);
for (int i = 0; i < queryRounds; i++) {
MatchQueryBuilder matchQuery = QueryBuilders.matchQuery("f", English.intToEnglish(between(0, num)));
@ -962,7 +963,10 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
@Test
public void testEmptyTermsFilter() throws Exception {
createIndexMapped("test", "type", "term", "string");
assertAcked(prepareCreate("test").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("term").field("type", "string").endObject()
.endObject().endObject().endObject()));
ensureGreen();
client().prepareIndex("test", "type", "1").setSource("term", "1").execute().actionGet();
client().prepareIndex("test", "type", "2").setSource("term", "2").execute().actionGet();
@ -984,9 +988,19 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
@Test
public void testTermsLookupFilter() throws Exception {
createIndexMapped("lookup", "type", "terms", "string", "other", "string");
createIndexMapped("lookup2", "type", "term", "string");
createIndexMapped("test", "type", "term", "string");
assertAcked(prepareCreate("lookup").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("terms").field("type", "string").endObject()
.startObject("other").field("type", "string").endObject()
.endObject().endObject().endObject()));
assertAcked(prepareCreate("lookup2").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("terms").field("type", "string").endObject()
.endObject().endObject().endObject()));
assertAcked(prepareCreate("test").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("terms").field("type", "string").endObject()
.endObject().endObject().endObject()));
ensureGreen();
client().prepareIndex("lookup", "type", "1").setSource("terms", new String[]{"1", "3"}).execute().actionGet();
client().prepareIndex("lookup", "type", "2").setSource("terms", new String[]{"2"}).execute().actionGet();
@ -1511,41 +1525,41 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
.put("index.number_of_replicas", 0)
).addMapping("s", jsonBuilder()
.startObject()
.startObject("s")
.startObject("_routing")
.field("required", true)
.field("path", "bs")
.endObject()
.startObject("properties")
.startObject("online")
.field("type", "boolean")
.endObject()
.startObject("ts")
.field("type", "date")
.field("ignore_malformed", false)
.field("format", "dateOptionalTime")
.endObject()
.startObject("bs")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.endObject()
.endObject()
.startObject("s")
.startObject("_routing")
.field("required", true)
.field("path", "bs")
.endObject()
.startObject("properties")
.startObject("online")
.field("type", "boolean")
.endObject()
.startObject("ts")
.field("type", "date")
.field("ignore_malformed", false)
.field("format", "dateOptionalTime")
.endObject()
.startObject("bs")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.endObject()
.endObject()
.endObject())
.addMapping("bs", jsonBuilder()
.startObject()
.startObject("s")
.startObject("properties")
.startObject("online")
.field("type", "boolean")
.endObject()
.startObject("ts")
.field("type", "date")
.field("ignore_malformed", false)
.field("format", "dateOptionalTime")
.endObject()
.endObject()
.endObject()
.startObject("s")
.startObject("properties")
.startObject("online")
.field("type", "boolean")
.endObject()
.startObject("ts")
.field("type", "date")
.field("ignore_malformed", false)
.field("format", "dateOptionalTime")
.endObject()
.endObject()
.endObject()
.endObject())
.execute().actionGet();
ensureGreen();

View File

@ -648,7 +648,10 @@ public class SimpleSortTests extends AbstractSharedClusterTest {
@Test
public void test2920() throws IOException {
createIndexMapped("test", "test", "value", "string");
assertAcked(prepareCreate("test").addMapping("test",
jsonBuilder().startObject().startObject("test").startObject("properties")
.startObject("value").field("type", "string").endObject()
.endObject().endObject().endObject()));
ensureGreen();
for (int i = 0; i < 10; i++) {
client().prepareIndex("test", "test", Integer.toString(i)).setSource(jsonBuilder().startObject()

View File

@ -20,7 +20,6 @@
package org.elasticsearch.test.integration.search.suggest;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
@ -29,6 +28,8 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.search.suggest.SuggestBuilder.SuggestionBuilder;
import org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilder;
@ -69,17 +70,28 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
.put("index.analysis.filter.shingler.type", "shingle")
.put("index.analysis.filter.shingler.min_shingle_size", 2)
.put("index.analysis.filter.shingler.max_shingle_size", 3));
addMapping(builder, "type1", new Object[] {"name",
"type", "multi_field",
"path", "just_name",
"fields", ImmutableMap.of(
"name", ImmutableMap.of("type", "string"),
"name_shingled", ImmutableMap.of(
"type", "string",
"index_analyzer", "biword",
"search_analyzer", "standard"))});
builder.get();
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("name")
.field("type", "multi_field")
.field("path", "just_name")
.startObject("fields")
.startObject("name")
.field("type", "string")
.endObject()
.startObject("name_shingled")
.field("type", "string")
.field("index_analyzer", "biword")
.field("search_analyzer", "standard")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().endObject();
assertAcked(builder.addMapping("type1", mapping));
ensureGreen();
index("test", "type1", "1", "name", "I like iced tea");
index("test", "type1", "2", "name", "I like tea.");
@ -136,16 +148,25 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
.put("index.analysis.filter.shingler.type", "shingle")
.put("index.analysis.filter.shingler.min_shingle_size", 2)
.put("index.analysis.filter.shingler.max_shingle_size", 3));
addMapping(builder, "type1", new Object[] {"name",
"type", "multi_field",
"path", "just_name",
"fields", ImmutableMap.of(
"name", ImmutableMap.of("type", "string"),
"name_shingled", ImmutableMap.of(
"type", "string",
"index_analyzer", "biword",
"search_analyzer", "standard"))});
builder.get();
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("name")
.field("type", "multi_field")
.field("path", "just_name")
.startObject("fields")
.startObject("name")
.field("type", "string")
.endObject()
.startObject("name_shingled")
.field("type", "string")
.field("index_analyzer", "biword")
.field("search_analyzer", "standard")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().endObject();
assertAcked(builder.addMapping("type1", mapping));
ensureGreen();
indexRandom("test", true,
@ -341,12 +362,15 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
.put("index.analysis.filter.my_shingle.output_unigrams", false)
.put("index.analysis.filter.my_shingle.min_shingle_size", 2)
.put("index.analysis.filter.my_shingle.max_shingle_size", 2));
addMapping(builder, "type1",
new Object[] {"_all", "store", "yes", "termVector", "with_positions_offsets"},
new Object[] {"body", "type", "string", "analyzer", "body"},
new Object[] {"body_reverse", "type", "string", "analyzer", "reverse"},
new Object[] {"bigram", "type", "string", "analyzer", "bigram"});
builder.get();
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("_all").field("store", "yes").field("termVector", "with_positions_offsets").endObject()
.startObject("properties")
.startObject("body").field("type", "string").field("analyzer", "body").endObject()
.startObject("body_reverse").field("type", "string").field("analyzer", "reverse").endObject()
.startObject("bigram").field("type", "string").field("analyzer", "bigram").endObject()
.endObject()
.endObject().endObject();
assertAcked(builder.addMapping("type1", mapping));
ensureGreen();
index("test", "type1", "1", "body", "hello world");
@ -381,12 +405,27 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
.put("index.analysis.filter.my_shingle.output_unigrams", false)
.put("index.analysis.filter.my_shingle.min_shingle_size", 2)
.put("index.analysis.filter.my_shingle.max_shingle_size", 2));
addMapping(builder, "type1",
new Object[] {"_all", "store", "yes", "termVector", "with_positions_offsets"},
new Object[] {"body", "type", "string", "analyzer", "body"},
new Object[] {"body_reverse", "type", "string", "analyzer", "reverse"},
new Object[] {"bigram", "type", "string", "analyzer", "bigram"});
builder.get();
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("_all")
.field("store", "yes")
.field("termVector", "with_positions_offsets")
.endObject()
.startObject("properties")
.startObject("body").
field("type", "string").
field("analyzer", "body")
.endObject()
.startObject("body_reverse").
field("type", "string").
field("analyzer", "reverse")
.endObject()
.startObject("bigram").
field("type", "string").
field("analyzer", "bigram")
.endObject()
.endObject()
.endObject().endObject();
ElasticsearchAssertions.assertAcked(builder.addMapping("type1", mapping));
ensureGreen();
for (String line: Resources.readLines(SuggestSearchTests.class.getResource("/config/names.txt"), Charsets.UTF_8)) {
@ -496,12 +535,31 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
.put("index.analysis.filter.my_shingle.output_unigrams", false)
.put("index.analysis.filter.my_shingle.min_shingle_size", 2)
.put("index.analysis.filter.my_shingle.max_shingle_size", 2));
addMapping(builder, "type1",
new Object[] {"_all", "store", "yes", "termVector", "with_positions_offsets"},
new Object[] {"body", "type", "string", "analyzer", "body"},
new Object[] {"body_reverse", "type", "string", "analyzer", "reverse"},
new Object[] {"bigram", "type", "string", "analyzer", "bigram"});
builder.get();
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("_all")
.field("store", "yes")
.field("termVector", "with_positions_offsets")
.endObject()
.startObject("properties")
.startObject("body")
.field("type", "string")
.field("analyzer", "body")
.endObject()
.startObject("body_reverse")
.field("type", "string")
.field("analyzer", "reverse")
.endObject()
.startObject("bigram")
.field("type", "string")
.field("analyzer", "bigram")
.endObject()
.endObject()
.endObject()
.endObject();
assertAcked(builder.addMapping("type1", mapping));
ensureGreen();
String line = "xorr the god jewel";
@ -548,12 +606,17 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
.put("index.analysis.filter.my_shingle2.output_unigrams", true)
.put("index.analysis.filter.my_shingle2.min_shingle_size", 2)
.put("index.analysis.filter.my_shingle2.max_shingle_size", 2));
addMapping(builder, "type1",
new Object[] {"_all", "store", "yes", "termVector", "with_positions_offsets"},
new Object[] {"body", "type", "string", "analyzer", "body"},
new Object[] {"bigram", "type", "string", "analyzer", "bigram"},
new Object[] {"ngram", "type", "string", "analyzer", "ngram"});
builder.get();
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject().startObject("type1")
.startObject("_all").field("store", "yes").field("termVector", "with_positions_offsets").endObject()
.startObject("properties")
.startObject("body").field("type", "string").field("analyzer", "body").endObject()
.startObject("bigram").field("type", "string").field("analyzer", "bigram").endObject()
.startObject("ngram").field("type", "string").field("analyzer", "ngram").endObject()
.endObject()
.endObject().endObject();
assertAcked(builder.addMapping("type1", mapping));
ensureGreen();
for (String line: Resources.readLines(SuggestSearchTests.class.getResource("/config/names.txt"), Charsets.UTF_8)) {
@ -613,11 +676,10 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
.put(SETTING_NUMBER_OF_SHARDS, 5)
.put(SETTING_NUMBER_OF_REPLICAS, 0)).get();
ensureGreen();
client().prepareIndex("text", "type1", "1").setSource("field1", "foobar1").setRouting("1").get();
client().prepareIndex("text", "type1", "2").setSource("field1", "foobar2").setRouting("2").get();
client().prepareIndex("text", "type1", "3").setSource("field1", "foobar3").setRouting("3").get();
refresh();
indexRandom("text", true,
client().prepareIndex("text", "type1", "1").setSource("field1", "foobar1").setRouting("1"),
client().prepareIndex("text", "type1", "2").setSource("field1", "foobar2").setRouting("2"),
client().prepareIndex("text", "type1", "3").setSource("field1", "foobar3").setRouting("3"));
Suggest suggest = searchSuggest(client(), "foobar",
termSuggestion("simple")
@ -636,14 +698,22 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
.put("index.analysis.filter.shingler.min_shingle_size", 2)
.put("index.analysis.filter.shingler.max_shingle_size", 5)
.put("index.analysis.filter.shingler.output_unigrams", true));
addMapping(builder, "type1", new Object[] {"name",
"type", "multi_field",
"path", "just_name",
"fields", ImmutableMap.of(
"name", ImmutableMap.of(
"type", "string",
"analyzer", "suggest"))});
builder.get();
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("name")
.field("type", "multi_field")
.field("path", "just_name")
.startObject("fields")
.startObject("name")
.field("type", "string")
.field("analyzer", "suggest")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().endObject();
assertAcked(builder.addMapping("type1", mapping));
ensureGreen();
index("test", "type2", "1", "foo", "bar");
@ -673,7 +743,24 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
@Test // see #3469
public void testEmptyShards() throws IOException, InterruptedException {
CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(settingsBuilder()
XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().
startObject().
startObject("type1").
startObject("properties").
startObject("name").
field("type", "multi_field").
field("path", "just_name").
startObject("fields").
startObject("name").
field("type", "string").
field("analyzer", "suggest").
endObject().
endObject().
endObject().
endObject().
endObject().
endObject();
ElasticsearchAssertions.assertAcked(prepareCreate("test").setSettings(settingsBuilder()
.put(SETTING_NUMBER_OF_SHARDS, 5)
.put(SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.analysis.analyzer.suggest.tokenizer", "standard")
@ -681,15 +768,7 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
.put("index.analysis.filter.shingler.type", "shingle")
.put("index.analysis.filter.shingler.min_shingle_size", 2)
.put("index.analysis.filter.shingler.max_shingle_size", 5)
.put("index.analysis.filter.shingler.output_unigrams", true));
addMapping(builder, "type1", new Object[] {"name",
"type", "multi_field",
"path", "just_name",
"fields", ImmutableMap.of(
"name", ImmutableMap.of(
"type", "string",
"analyzer", "suggest"))});
builder.get();
.put("index.analysis.filter.shingler.output_unigrams", true)).addMapping("type1", mappingBuilder));
ensureGreen();
index("text", "type2", "1", "foo", "bar");
@ -728,12 +807,23 @@ public class SuggestSearchTests extends AbstractSharedClusterTest {
.put("index.analysis.filter.my_shingle.output_unigrams", true)
.put("index.analysis.filter.my_shingle.min_shingle_size", 2)
.put("index.analysis.filter.my_shingle.max_shingle_size", 2));
addMapping( builder, "type1", new Object[] {"body",
"store", true,
"termVector", "with_positions_offsets",
"type", "string",
"analyzer", "body"});
builder.get();
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("_all")
.field("store", "yes")
.field("termVector", "with_positions_offsets")
.endObject()
.startObject("properties")
.startObject("body")
.field("type", "string")
.field("analyzer", "body")
.endObject()
.endObject()
.endObject()
.endObject();
assertAcked(builder.addMapping("type1", mapping));
ensureGreen();
List<String> phrases = new ArrayList<String>();

View File

@ -118,6 +118,7 @@ public abstract class AbstractTermVectorTests extends AbstractSharedClusterTest
public TestDoc(String id, TestFieldSetting[] fieldSettings, String[] fieldContent) {
this.id = id;
assert fieldSettings.length == fieldContent.length;
this.fieldSettings = fieldSettings;
this.fieldContent = fieldContent;
}

View File

@ -31,6 +31,7 @@ import org.elasticsearch.common.io.BytesStream;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.hamcrest.Matchers;
import org.junit.Test;
@ -45,13 +46,21 @@ public class GetTermVectorCheckDocFreqTests extends AbstractSharedClusterTest {
@Test
public void testSimpleTermVectors() throws ElasticSearchException, IOException {
run(addMapping(prepareCreate("test"), "type1",
new Object[] { "field", "type", "string", "term_vector", "with_positions_offsets_payloads", "analyzer", "tv_test" })
.setSettings(
ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)
.put("index.analysis.analyzer.tv_test.tokenizer", "whitespace").put("index.number_of_replicas", 0)
.putArray("index.analysis.analyzer.tv_test.filter", "type_as_payload", "lowercase")));
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("field")
.field("type", "string")
.field("term_vector", "with_positions_offsets_payloads")
.field("analyzer", "tv_test")
.endObject()
.endObject()
.endObject().endObject();
ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("type1", mapping).setSettings(
ImmutableSettings.settingsBuilder()
.put("index.number_of_shards", 1)
.put("index.analysis.analyzer.tv_test.tokenizer", "whitespace")
.put("index.number_of_replicas", 0)
.putArray("index.analysis.analyzer.tv_test.filter", "type_as_payload", "lowercase")));
ensureGreen();
int numDocs = 15;
for (int i = 0; i < numDocs; i++) {

View File

@ -28,11 +28,13 @@ import org.elasticsearch.action.termvector.TermVectorRequest;
import org.elasticsearch.action.termvector.TermVectorRequestBuilder;
import org.elasticsearch.action.termvector.TermVectorResponse;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.mapper.core.TypeParsers;
import org.elasticsearch.index.mapper.internal.AllFieldMapper;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.hamcrest.Matchers;
import org.junit.Test;
@ -47,9 +49,15 @@ public class GetTermVectorTests extends AbstractTermVectorTests {
@Test
public void testNoSuchDoc() throws Exception {
run(addMapping(prepareCreate("test"), "type1", new Object[]{"field", "type", "string", "term_vector",
"with_positions_offsets_payloads"}));
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("field")
.field("type", "string")
.field("term_vector", "with_positions_offsets_payloads")
.endObject()
.endObject()
.endObject().endObject();
ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("type1", mapping));
ensureYellow();
@ -67,9 +75,15 @@ public class GetTermVectorTests extends AbstractTermVectorTests {
@Test
public void testExistingFieldWithNoTermVectorsNoNPE() throws Exception {
run(addMapping(prepareCreate("test"), "type1", new Object[] { "existingfield", "type", "string", "term_vector",
"with_positions_offsets_payloads" }));
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("existingfield")
.field("type", "string")
.field("term_vector", "with_positions_offsets_payloads")
.endObject()
.endObject()
.endObject().endObject();
ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("type1", mapping));
ensureYellow();
// when indexing a field that simply has a question mark, the term
@ -89,9 +103,15 @@ public class GetTermVectorTests extends AbstractTermVectorTests {
@Test
public void testExistingFieldButNotInDocNPE() throws Exception {
run(addMapping(prepareCreate("test"), "type1", new Object[] { "existingfield", "type", "string", "term_vector",
"with_positions_offsets_payloads" }));
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("existingfield")
.field("type", "string")
.field("term_vector", "with_positions_offsets_payloads")
.endObject()
.endObject()
.endObject().endObject();
ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("type1", mapping));
ensureYellow();
// when indexing a field that simply has a question mark, the term
// vectors will be null
@ -110,12 +130,19 @@ public class GetTermVectorTests extends AbstractTermVectorTests {
@Test
public void testSimpleTermVectors() throws ElasticSearchException, IOException {
run(addMapping(prepareCreate("test"), "type1",
new Object[]{"field", "type", "string", "term_vector", "with_positions_offsets_payloads", "analyzer", "tv_test"})
.setSettings(
ImmutableSettings.settingsBuilder().put("index.analysis.analyzer.tv_test.tokenizer", "whitespace")
.putArray("index.analysis.analyzer.tv_test.filter", "type_as_payload", "lowercase")));
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("field")
.field("type", "string")
.field("term_vector", "with_positions_offsets_payloads")
.field("analyzer", "tv_test")
.endObject()
.endObject()
.endObject().endObject();
ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("type1", mapping)
.setSettings(ImmutableSettings.settingsBuilder()
.put("index.analysis.analyzer.tv_test.tokenizer", "whitespace")
.putArray("index.analysis.analyzer.tv_test.filter", "type_as_payload", "lowercase")));
ensureYellow();
for (int i = 0; i < 10; i++) {
client().prepareIndex("test", "type1", Integer.toString(i))
@ -215,9 +242,18 @@ public class GetTermVectorTests extends AbstractTermVectorTests {
ft.setStoreTermVectorPositions(storePositions);
String optionString = AbstractFieldMapper.termVectorOptionsToString(ft);
run(addMapping(prepareCreate("test"), "type1",
new Object[]{"field", "type", "string", "term_vector", optionString, "analyzer", "tv_test"}).setSettings(
ImmutableSettings.settingsBuilder().put("index.analysis.analyzer.tv_test.tokenizer", "whitespace")
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("field")
.field("type", "string")
.field("term_vector", optionString)
.field("analyzer", "tv_test")
.endObject()
.endObject()
.endObject().endObject();
ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("type1", mapping)
.setSettings(ImmutableSettings.settingsBuilder()
.put("index.analysis.analyzer.tv_test.tokenizer", "whitespace")
.putArray("index.analysis.analyzer.tv_test.filter", "type_as_payload", "lowercase")));
ensureYellow();
for (int i = 0; i < 10; i++) {