[TESTS] Switch more tests to ElasticsearchSingleNodeTest.

This avoids loading modules manually all the time.
This commit is contained in:
Adrien Grand 2014-07-18 11:28:23 +02:00
parent 4eca0499fa
commit 97f4247880
68 changed files with 626 additions and 913 deletions

View File

@ -28,9 +28,8 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.indices.analysis.PreBuiltAnalyzers;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.io.IOException;
@ -43,7 +42,7 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
public class PreBuiltAnalyzerTests extends ElasticsearchTestCase {
public class PreBuiltAnalyzerTests extends ElasticsearchSingleNodeTest {
@Test
public void testThatDefaultAndStandardAnalyzerAreTheSameInstance() {
@ -161,7 +160,7 @@ public class PreBuiltAnalyzerTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "string").field("analyzer", analyzerName).endObject().endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser(indexSettings).parse(mapping);
DocumentMapper docMapper = createIndex("test", indexSettings).mapperService().documentMapperParser().parse(mapping);
FieldMapper fieldMapper = docMapper.mappers().name("field").mapper();
assertThat(fieldMapper.searchAnalyzer(), instanceOf(NamedAnalyzer.class));

View File

@ -44,9 +44,7 @@ import org.elasticsearch.index.mapper.internal.IdFieldMapper;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.index.mapper.internal.VersionFieldMapper;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.test.ElasticsearchLuceneTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.After;
import org.elasticsearch.test.ElasticsearchSingleNodeLuceneTestCase;
import org.junit.Before;
import org.junit.Test;
@ -56,7 +54,7 @@ import java.util.Arrays;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
public class CodecTests extends ElasticsearchLuceneTestCase {
public class CodecTests extends ElasticsearchSingleNodeLuceneTestCase {
@Override
@Before
@ -65,11 +63,6 @@ public class CodecTests extends ElasticsearchLuceneTestCase {
forceDefaultCodec(); // we test against default codec so never get a random one here!
}
@After
public void cleanup() {
ElasticsearchSingleNodeTest.cleanup();
}
@Test
public void testResolveDefaultCodecs() throws Exception {
CodecService codecService = createCodecService();
@ -405,7 +398,7 @@ public class CodecTests extends ElasticsearchLuceneTestCase {
}
private static CodecService createCodecService(Settings settings) {
IndexService indexService = ElasticsearchSingleNodeTest.createIndex("test", settings);
IndexService indexService = createIndex("test", settings);
return indexService.injector().getInstance(CodecService.class);
}

View File

@ -24,22 +24,21 @@ import org.apache.lucene.index.*;
import org.apache.lucene.store.RAMDirectory;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.Index;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.Mapper.BuilderContext;
import org.elasticsearch.indices.fielddata.breaker.CircuitBreakerService;
import org.elasticsearch.indices.fielddata.breaker.NoneCircuitBreakerService;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCacheListener;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.index.service.StubIndexService;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.After;
import org.junit.Before;
// we might wanna cut this over to LuceneTestCase
public abstract class AbstractFieldDataTests extends ElasticsearchTestCase {
public abstract class AbstractFieldDataTests extends ElasticsearchSingleNodeTest {
protected IndexService indexService;
protected IndexFieldDataService ifdService;
protected MapperService mapperService;
protected IndexWriter writer;
protected AtomicReaderContext readerContext;
protected IndexReader topLevelReader;
@ -86,14 +85,11 @@ public abstract class AbstractFieldDataTests extends ElasticsearchTestCase {
@Before
public void setup() throws Exception {
CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
indicesFieldDataCache = new IndicesFieldDataCache(
ImmutableSettings.Builder.EMPTY_SETTINGS,
new IndicesFieldDataCacheListener(circuitBreakerService)
);
ifdService = new IndexFieldDataService(new Index("test"), ImmutableSettings.builder().put("index.fielddata.cache", "none").build(), indicesFieldDataCache, circuitBreakerService, new IndicesFieldDataCacheListener(circuitBreakerService));
MapperService mapperService = MapperTestUtils.newMapperService(ifdService.index(), ImmutableSettings.Builder.EMPTY_SETTINGS);
ifdService.setIndexService(new StubIndexService(mapperService));
Settings settings = ImmutableSettings.builder().put("index.fielddata.cache", "none").build();
indexService = createIndex("test", settings);
mapperService = indexService.mapperService();
indicesFieldDataCache = indexService.injector().getInstance(IndicesFieldDataCache.class);
ifdService = indexService.fieldData();
// LogByteSizeMP to preserve doc ID order
writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(Lucene.VERSION, new StandardAnalyzer(Lucene.VERSION)).setMergePolicy(new LogByteSizeMergePolicy()));
}
@ -114,7 +110,6 @@ public abstract class AbstractFieldDataTests extends ElasticsearchTestCase {
readerContext.reader().close();
}
writer.close();
ifdService.clear();
}
}

View File

@ -27,7 +27,6 @@ import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.junit.Test;
@ -49,7 +48,7 @@ public class BinaryDVFieldDataTests extends AbstractFieldDataTests {
.endObject()
.endObject().endObject().string();
final DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
final DocumentMapper mapper = mapperService.documentMapperParser().parse(mapping);
ObjectArrayList<byte[]> bytesList1 = new ObjectArrayList<>(2);

View File

@ -39,7 +39,6 @@ import org.elasticsearch.common.unit.DistanceUnit.Distance;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.junit.Test;
@ -67,7 +66,7 @@ public class DuelFieldDataTests extends AbstractFieldDataTests {
.startObject("float").field("type", "float").startObject("fielddata").field("format", "doc_values").endObject().endObject()
.startObject("double").field("type", "double").startObject("fielddata").field("format", "doc_values").endObject().endObject()
.endObject().endObject().endObject().string();
final DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
final DocumentMapper mapper = mapperService.documentMapperParser().parse(mapping);
Random random = getRandom();
int atLeast = scaledRandomIntBetween(1000, 1500);
for (int i = 0; i < atLeast; i++) {
@ -146,7 +145,7 @@ public class DuelFieldDataTests extends AbstractFieldDataTests {
.startObject("long").field("type", "long").startObject("fielddata").field("format", "doc_values").endObject().endObject()
.endObject().endObject().endObject().string();
final DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
final DocumentMapper mapper = mapperService.documentMapperParser().parse(mapping);
Random random = getRandom();
int atLeast = scaledRandomIntBetween(1000, 1500);
final int maxNumValues = randomBoolean() ? 1 : randomIntBetween(2, 40);
@ -224,7 +223,7 @@ public class DuelFieldDataTests extends AbstractFieldDataTests {
.startObject("double").field("type", "double").startObject("fielddata").field("format", "doc_values").endObject().endObject()
.endObject().endObject().endObject().string();
final DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
final DocumentMapper mapper = mapperService.documentMapperParser().parse(mapping);
Random random = getRandom();
int atLeast = scaledRandomIntBetween(1000, 1500);
final int maxNumValues = randomBoolean() ? 1 : randomIntBetween(2, 40);
@ -415,7 +414,7 @@ public class DuelFieldDataTests extends AbstractFieldDataTests {
.startObject("geopoint").field("type", "geo_point").startObject("fielddata").field("format", "doc_values").endObject().endObject()
.endObject().endObject().endObject().string();
final DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
final DocumentMapper mapper = mapperService.documentMapperParser().parse(mapping);
Random random = getRandom();
int atLeast = scaledRandomIntBetween(1000, 1500);

View File

@ -27,14 +27,13 @@ import org.apache.lucene.index.*;
import org.apache.lucene.store.RAMDirectory;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.plain.*;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.ContentPath;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.Mapper.BuilderContext;
import org.elasticsearch.index.mapper.MapperBuilders;
import org.elasticsearch.index.mapper.core.*;
import org.elasticsearch.indices.fielddata.breaker.NoneCircuitBreakerService;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.index.service.StubIndexService;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import java.util.Arrays;
import java.util.Collections;
@ -43,15 +42,12 @@ import java.util.Set;
import static org.hamcrest.Matchers.instanceOf;
public class IndexFieldDataServiceTests extends ElasticsearchTestCase {
public class IndexFieldDataServiceTests extends ElasticsearchSingleNodeTest {
private static Settings DOC_VALUES_SETTINGS = ImmutableSettings.builder().put(FieldDataType.FORMAT_KEY, FieldDataType.DOC_VALUES_FORMAT_VALUE).build();
@SuppressWarnings("unchecked")
public void testGetForFieldDefaults() {
final IndexFieldDataService ifdService = new IndexFieldDataService(new Index("test"), new NoneCircuitBreakerService());
MapperService mapperService = MapperTestUtils.newMapperService(ifdService.index(), ImmutableSettings.Builder.EMPTY_SETTINGS);
ifdService.setIndexService(new StubIndexService(mapperService));
final IndexFieldDataService ifdService = createIndex("test").fieldData();
for (boolean docValues : Arrays.asList(true, false)) {
final BuilderContext ctx = new BuilderContext(null, new ContentPath(1));
final StringFieldMapper stringMapper = new StringFieldMapper.Builder("string").tokenized(false).fieldDataSettings(docValues ? DOC_VALUES_SETTINGS : ImmutableSettings.EMPTY).build(ctx);
@ -100,9 +96,7 @@ public class IndexFieldDataServiceTests extends ElasticsearchTestCase {
@SuppressWarnings("unchecked")
public void testByPassDocValues() {
final IndexFieldDataService ifdService = new IndexFieldDataService(new Index("test"), new NoneCircuitBreakerService());
MapperService mapperService = MapperTestUtils.newMapperService(ifdService.index(), ImmutableSettings.Builder.EMPTY_SETTINGS);
ifdService.setIndexService(new StubIndexService(mapperService));
final IndexFieldDataService ifdService = createIndex("test").fieldData();
final BuilderContext ctx = new BuilderContext(null, new ContentPath(1));
final StringFieldMapper stringMapper = MapperBuilders.stringField("string").tokenized(false).fieldDataSettings(DOC_VALUES_SETTINGS).fieldDataSettings(ImmutableSettings.builder().put("format", "fst").build()).build(ctx);
ifdService.clear();
@ -133,9 +127,7 @@ public class IndexFieldDataServiceTests extends ElasticsearchTestCase {
}
public void testChangeFieldDataFormat() throws Exception {
final IndexFieldDataService ifdService = new IndexFieldDataService(new Index("test"), new NoneCircuitBreakerService());
MapperService mapperService = MapperTestUtils.newMapperService(ifdService.index(), ImmutableSettings.Builder.EMPTY_SETTINGS);
ifdService.setIndexService(new StubIndexService(mapperService));
final IndexFieldDataService ifdService = createIndex("test").fieldData();
final BuilderContext ctx = new BuilderContext(null, new ContentPath(1));
final StringFieldMapper mapper1 = MapperBuilders.stringField("s").tokenized(false).fieldDataSettings(ImmutableSettings.builder().put(FieldDataType.FORMAT_KEY, "paged_bytes").build()).build(ctx);
final IndexWriter writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer()));

View File

@ -27,15 +27,10 @@ import org.apache.lucene.search.*;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.common.compress.CompressedString;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.internal.ParentFieldMapper;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.test.index.service.StubIndexService;
import org.junit.Before;
import org.junit.Test;
@ -51,15 +46,12 @@ public class ParentChildFieldDataTests extends AbstractFieldDataTests {
@Before
public void before() throws Exception {
MapperService mapperService = MapperTestUtils.newMapperService(ifdService.index(), ImmutableSettings.Builder.EMPTY_SETTINGS);
mapperService.merge(
childType, new CompressedString(PutMappingRequest.buildFromSimplifiedDef(childType, "_parent", "type=" + parentType).string()), true
);
mapperService.merge(
grandChildType, new CompressedString(PutMappingRequest.buildFromSimplifiedDef(grandChildType, "_parent", "type=" + childType).string()), true
);
IndexService indexService = new StubIndexService(mapperService);
ifdService.setIndexService(indexService);
Document d = new Document();
d.add(new StringField(UidFieldMapper.NAME, Uid.createUid(parentType, "1"), Field.Store.NO));

View File

@ -1,83 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.mapper;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNameModule;
import org.elasticsearch.index.analysis.AnalysisModule;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.codec.docvaluesformat.DocValuesFormatService;
import org.elasticsearch.index.codec.postingsformat.PostingsFormatService;
import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.settings.IndexSettingsModule;
import org.elasticsearch.index.similarity.SimilarityLookupService;
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
import org.elasticsearch.indices.fielddata.breaker.NoneCircuitBreakerService;
/**
*
*/
public class MapperTestUtils {
public static DocumentMapperParser newParser() {
return new DocumentMapperParser(new Index("test"), ImmutableSettings.Builder.EMPTY_SETTINGS, newAnalysisService(), new PostingsFormatService(new Index("test")),
new DocValuesFormatService(new Index("test")), newSimilarityLookupService(), null);
}
public static DocumentMapperParser newParser(Settings indexSettings) {
return new DocumentMapperParser(new Index("test"), indexSettings, newAnalysisService(indexSettings), new PostingsFormatService(new Index("test")),
new DocValuesFormatService(new Index("test")), newSimilarityLookupService(), null);
}
public static MapperService newMapperService() {
return newMapperService(new Index("test"), ImmutableSettings.Builder.EMPTY_SETTINGS);
}
public static MapperService newMapperService(Index index, Settings indexSettings) {
return new MapperService(index, indexSettings, new Environment(), newAnalysisService(), new IndexFieldDataService(index, new NoneCircuitBreakerService()),
new PostingsFormatService(index), new DocValuesFormatService(index), newSimilarityLookupService(), null);
}
public static AnalysisService newAnalysisService() {
return newAnalysisService(ImmutableSettings.Builder.EMPTY_SETTINGS);
}
public static AnalysisService newAnalysisService(Settings indexSettings) {
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(ImmutableSettings.Builder.EMPTY_SETTINGS)), new IndicesAnalysisModule()).createInjector();
Injector injector = new ModulesBuilder().add(
new IndexSettingsModule(new Index("test"), indexSettings),
new IndexNameModule(new Index("test")),
new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector);
return injector.getInstance(AnalysisService.class);
}
public static SimilarityLookupService newSimilarityLookupService() {
return new SimilarityLookupService(new Index("test"), ImmutableSettings.Builder.EMPTY_SETTINGS);
}
}

View File

@ -39,7 +39,7 @@ import org.elasticsearch.index.mapper.internal.IndexFieldMapper;
import org.elasticsearch.index.mapper.internal.SizeFieldMapper;
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.hamcrest.Matchers;
import org.junit.Test;
@ -54,12 +54,12 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
public class SimpleAllMapperTests extends ElasticsearchTestCase {
public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void testSimpleAllMappers() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
@ -78,7 +78,7 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test
public void testAllMappersNoBoost() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/noboost-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
@ -95,7 +95,7 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test
public void testAllMappersTermQuery() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mapping_omit_positions_on_all.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
@ -114,7 +114,7 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test
public void testAllMappersWithOffsetsTermQuery() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mapping_offsets_on_all.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
@ -134,7 +134,7 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test
public void testBoostWithOmitPositions() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mapping_boost_omit_positions_on_all.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
@ -146,7 +146,7 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test
public void testNoBoost() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/noboost-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
@ -157,11 +157,12 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test
public void testSimpleAllMappersWithReparse() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = parser.parse(mapping);
String builtMapping = docMapper.mappingSource().string();
// reparse it
DocumentMapper builtDocMapper = MapperTestUtils.newParser().parse(builtMapping);
DocumentMapper builtDocMapper = parser.parse(builtMapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = builtDocMapper.parse(new BytesArray(json)).rootDoc();
@ -177,7 +178,7 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test
public void testSimpleAllMappersWithStore() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/store-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
AllField field = (AllField) doc.getField("_all");
@ -193,11 +194,12 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test
public void testSimpleAllMappersWithReparseWithStore() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/store-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = parser.parse(mapping);
String builtMapping = docMapper.mappingSource().string();
// reparse it
DocumentMapper builtDocMapper = MapperTestUtils.newParser().parse(builtMapping);
DocumentMapper builtDocMapper = parser.parse(builtMapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json");
Document doc = builtDocMapper.parse(new BytesArray(json)).rootDoc();
@ -272,12 +274,13 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
mappingBuilder.endObject();
}
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = mappingBuilder.endObject().endObject().bytes().toUtf8();
logger.info(mapping);
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = parser.parse(mapping);
String builtMapping = docMapper.mappingSource().string();
// reparse it
DocumentMapper builtDocMapper = MapperTestUtils.newParser().parse(builtMapping);
DocumentMapper builtDocMapper = parser.parse(builtMapping);
byte[] json = jsonBuilder().startObject()
.field("foo", "bar")
@ -332,7 +335,7 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test
public void testMultiField_includeInAllSetToFalse() throws IOException {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/multifield-mapping_include_in_all_set_to_false.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject()
@ -352,7 +355,7 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test
public void testMultiField_defaults() throws IOException {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/multifield-mapping_default.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject()
@ -373,35 +376,36 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
@Test(expected = MapperParsingException.class)
public void testMisplacedTypeInRoot() throws IOException {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/misplaced_type_in_root.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse("test", mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("test", mapping);
}
// related to https://github.com/elasticsearch/elasticsearch/issues/5864
@Test(expected = MapperParsingException.class)
public void testMistypedTypeInRoot() throws IOException {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/mistyped_type_in_root.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse("test", mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("test", mapping);
}
// issue https://github.com/elasticsearch/elasticsearch/issues/5864
@Test(expected = MapperParsingException.class)
public void testMisplacedMappingAsRoot() throws IOException {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/misplaced_mapping_key_in_root.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse("test", mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("test", mapping);
}
// issue https://github.com/elasticsearch/elasticsearch/issues/5864
// test that RootObjectMapping still works
@Test
public void testRootObjectMapperPropertiesDoNotCauseException() throws IOException {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/type_dynamic_template_mapping.json");
MapperTestUtils.newParser().parse("test", mapping);
parser.parse("test", mapping);
mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/type_dynamic_date_formats_mapping.json");
MapperTestUtils.newParser().parse("test", mapping);
parser.parse("test", mapping);
mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/type_date_detection_mapping.json");
MapperTestUtils.newParser().parse("test", mapping);
parser.parse("test", mapping);
mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/type_numeric_detection_mapping.json");
MapperTestUtils.newParser().parse("test", mapping);
parser.parse("test", mapping);
}
// issue https://github.com/elasticsearch/elasticsearch/issues/5864
@ -425,6 +429,6 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
mapping += "\"" + key+ "\"" + ":" + rootTypes.get(key) + ",\n";
}
mapping += "\"properties\":{}}" ;
MapperTestUtils.newParser().parse("test", mapping);
createIndex("test").mapperService().documentMapperParser().parse("test", mapping);
}
}

View File

@ -23,22 +23,23 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.analysis.FieldNameAnalyzer;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
/**
*
*/
public class AnalyzerMapperTests extends ElasticsearchTestCase {
public class AnalyzerMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void testAnalyzerMapping() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_analyzer").field("path", "field_analyzer").endObject()
.startObject("properties")
@ -47,7 +48,7 @@ public class AnalyzerMapperTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper documentMapper = parser.parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field_analyzer", "whitespace")
@ -62,7 +63,7 @@ public class AnalyzerMapperTests extends ElasticsearchTestCase {
// check that it serializes and de-serializes correctly
DocumentMapper reparsedMapper = MapperTestUtils.newParser().parse(documentMapper.mappingSource().string());
DocumentMapper reparsedMapper = parser.parse(documentMapper.mappingSource().string());
doc = reparsedMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field_analyzer", "whitespace")
@ -79,6 +80,8 @@ public class AnalyzerMapperTests extends ElasticsearchTestCase {
@Test
public void testAnalyzerMappingExplicit() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_analyzer").field("path", "field_analyzer").endObject()
.startObject("properties")
@ -88,7 +91,7 @@ public class AnalyzerMapperTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper documentMapper = parser.parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field_analyzer", "whitespace")
@ -103,7 +106,7 @@ public class AnalyzerMapperTests extends ElasticsearchTestCase {
// check that it serializes and de-serializes correctly
DocumentMapper reparsedMapper = MapperTestUtils.newParser().parse(documentMapper.mappingSource().string());
DocumentMapper reparsedMapper = parser.parse(documentMapper.mappingSource().string());
doc = reparsedMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field_analyzer", "whitespace")
@ -119,6 +122,8 @@ public class AnalyzerMapperTests extends ElasticsearchTestCase {
@Test
public void testAnalyzerMappingNotIndexedNorStored() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_analyzer").field("path", "field_analyzer").endObject()
.startObject("properties")
@ -128,7 +133,7 @@ public class AnalyzerMapperTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper documentMapper = parser.parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field_analyzer", "whitespace")
@ -143,7 +148,7 @@ public class AnalyzerMapperTests extends ElasticsearchTestCase {
// check that it serializes and de-serializes correctly
DocumentMapper reparsedMapper = MapperTestUtils.newParser().parse(documentMapper.mappingSource().string());
DocumentMapper reparsedMapper = parser.parse(documentMapper.mappingSource().string());
doc = reparsedMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field_analyzer", "whitespace")

View File

@ -22,9 +22,8 @@ package org.elasticsearch.index.mapper.binary;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.core.BinaryFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
@ -32,7 +31,7 @@ import static org.hamcrest.Matchers.instanceOf;
/**
*/
public class BinaryMappingTests extends ElasticsearchTestCase {
public class BinaryMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testDefaultMapping() throws Exception {
@ -44,7 +43,7 @@ public class BinaryMappingTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldMapper fieldMapper = mapper.mappers().smartNameFieldMapper("field");
assertThat(fieldMapper, instanceOf(BinaryFieldMapper.class));

View File

@ -22,24 +22,22 @@ package org.elasticsearch.index.mapper.boost;
import org.apache.lucene.index.IndexableField;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.internal.BoostFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*/
public class BoostMappingTests extends ElasticsearchTestCase {
public class BoostMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testDefaultMapping() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("_boost", 2.0f)
@ -59,7 +57,7 @@ public class BoostMappingTests extends ElasticsearchTestCase {
.startObject("_boost").field("name", "custom_boost").endObject()
.endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field", "a")
@ -77,7 +75,7 @@ public class BoostMappingTests extends ElasticsearchTestCase {
@Test
public void testDefaultValues() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.boostFieldMapper().fieldType().stored(), equalTo(BoostFieldMapper.Defaults.FIELD_TYPE.stored()));
assertThat(docMapper.boostFieldMapper().fieldType().indexed(), equalTo(BoostFieldMapper.Defaults.FIELD_TYPE.indexed()));
}
@ -89,7 +87,7 @@ public class BoostMappingTests extends ElasticsearchTestCase {
.field("store", "yes").field("index", "not_analyzed")
.endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.boostFieldMapper().fieldType().stored(), equalTo(true));
assertThat(docMapper.boostFieldMapper().fieldType().indexed(), equalTo(true));
}

View File

@ -21,14 +21,13 @@ package org.elasticsearch.index.mapper.boost;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
public class CustomBoostMappingTests extends ElasticsearchTestCase {
public class CustomBoostMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testCustomBoostValues() throws Exception {
@ -43,7 +42,7 @@ public class CustomBoostMappingTests extends ElasticsearchTestCase {
.startObject("date_field").field("type", "date").startObject("norms").field("enabled", true).endObject().endObject()
.endObject().endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.startObject("s_field").field("value", "s_value").field("boost", 2.0f).endObject()

View File

@ -24,16 +24,15 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.Matchers.closeTo;
/**
*/
public class FieldLevelBoostTests extends ElasticsearchTestCase {
public class FieldLevelBoostTests extends ElasticsearchSingleNodeTest {
@Test
public void testFieldLevelBoost() throws Exception {
@ -48,7 +47,7 @@ public class FieldLevelBoostTests extends ElasticsearchTestCase {
.startObject("short_field").field("type", "short").startObject("norms").field("enabled", true).endObject().endObject()
.string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference json = XContentFactory.jsonBuilder().startObject().field("_id", "1")
.startObject("str_field").field("boost", 2.0).field("value", "some name").endObject()
.startObject("int_field").field("boost", 3.0).field("value", 10).endObject()
@ -99,7 +98,7 @@ public class FieldLevelBoostTests extends ElasticsearchTestCase {
.startObject("short_field").field("type", "short").startObject("norms").field("enabled", true).endObject().endObject()
.string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
try {
docMapper.parse(XContentFactory.jsonBuilder().startObject()
.field("_id", "1").startObject("str_field").field("foo", "bar")

View File

@ -21,26 +21,26 @@ package org.elasticsearch.index.mapper.camelcase;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
/**
*
*/
public class CamelCaseFieldNameTests extends ElasticsearchTestCase {
public class CamelCaseFieldNameTests extends ElasticsearchSingleNodeTest {
@Test
public void testCamelCaseFieldNameStaysAsIs() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper documentMapper = parser.parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("thisIsCamelCase", "value1")
@ -50,7 +50,7 @@ public class CamelCaseFieldNameTests extends ElasticsearchTestCase {
assertThat(documentMapper.mappers().indexName("this_is_camel_case"), nullValue());
documentMapper.refreshSource();
documentMapper = MapperTestUtils.newParser().parse(documentMapper.mappingSource().string());
documentMapper = parser.parse(documentMapper.mappingSource().string());
assertThat(documentMapper.mappers().indexName("thisIsCamelCase").isEmpty(), equalTo(false));
assertThat(documentMapper.mappers().indexName("this_is_camel_case"), nullValue());

View File

@ -22,9 +22,8 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.io.IOException;
@ -34,7 +33,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
public class CompletionFieldMapperTests extends ElasticsearchTestCase {
public class CompletionFieldMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void testDefaultConfiguration() throws IOException {
@ -44,7 +43,7 @@ public class CompletionFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("completion").mapper();
assertThat(fieldMapper, instanceOf(CompletionFieldMapper.class));
@ -68,7 +67,7 @@ public class CompletionFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("completion").mapper();
assertThat(fieldMapper, instanceOf(CompletionFieldMapper.class));
@ -97,7 +96,7 @@ public class CompletionFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("completion").mapper();
assertThat(fieldMapper, instanceOf(CompletionFieldMapper.class));

View File

@ -21,16 +21,14 @@ package org.elasticsearch.index.mapper.compound;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.equalTo;
public class CompoundTypesTests extends ElasticsearchTestCase {
public class CompoundTypesTests extends ElasticsearchSingleNodeTest {
@Test
public void testStringType() throws Exception {
@ -40,7 +38,7 @@ public class CompoundTypesTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()

View File

@ -25,10 +25,9 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
import org.elasticsearch.index.mapper.core.LongFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.util.Arrays;
@ -42,7 +41,7 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
public class CopyToMapperTests extends ElasticsearchTestCase {
public class CopyToMapperTests extends ElasticsearchSingleNodeTest {
@SuppressWarnings("unchecked")
@Test
@ -68,7 +67,7 @@ public class CopyToMapperTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldMapper fieldMapper = docMapper.mappers().name("copy_test").mapper();
assertThat(fieldMapper, instanceOf(StringFieldMapper.class));
@ -136,7 +135,7 @@ public class CopyToMapperTests extends ElasticsearchTestCase {
.endObject().endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference json = jsonBuilder().startObject()
.field("copy_test", "foo")
@ -164,7 +163,7 @@ public class CopyToMapperTests extends ElasticsearchTestCase {
.endObject().endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference json = jsonBuilder().startObject()
.field("copy_test", "foo")
@ -199,7 +198,8 @@ public class CopyToMapperTests extends ElasticsearchTestCase {
.endObject().endObject().endObject().string();
DocumentMapper docMapperBefore = MapperTestUtils.newParser().parse(mappingBefore);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper docMapperBefore = parser.parse(mappingBefore);
ImmutableList<String> fields = docMapperBefore.mappers().name("copy_test").mapper().copyTo().copyToFields();
@ -208,7 +208,7 @@ public class CopyToMapperTests extends ElasticsearchTestCase {
assertThat(fields.get(1), equalTo("bar"));
DocumentMapper docMapperAfter = MapperTestUtils.newParser().parse(mappingAfter);
DocumentMapper docMapperAfter = parser.parse(mappingAfter);
DocumentMapper.MergeResult mergeResult = docMapperBefore.merge(docMapperAfter, mergeFlags().simulate(true));

View File

@ -24,8 +24,8 @@ import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.io.IOException;
@ -38,7 +38,7 @@ import static org.hamcrest.Matchers.equalTo;
/**
* Test for {@link TokenCountFieldMapper}.
*/
public class TokenCountFieldMapperTests extends ElasticsearchTestCase {
public class TokenCountFieldMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void testMerge() throws IOException {
String stage1Mapping = XContentFactory.jsonBuilder().startObject()
@ -50,7 +50,8 @@ public class TokenCountFieldMapperTests extends ElasticsearchTestCase {
.endObject()
.endObject()
.endObject().endObject().string();
DocumentMapper stage1 = MapperTestUtils.newParser().parse(stage1Mapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper stage1 = parser.parse(stage1Mapping);
String stage2Mapping = XContentFactory.jsonBuilder().startObject()
.startObject("person")
@ -61,7 +62,7 @@ public class TokenCountFieldMapperTests extends ElasticsearchTestCase {
.endObject()
.endObject()
.endObject().endObject().string();
DocumentMapper stage2 = MapperTestUtils.newParser().parse(stage2Mapping);
DocumentMapper stage2 = parser.parse(stage2Mapping);
DocumentMapper.MergeResult mergeResult = stage1.merge(stage2, mergeFlags().simulate(true));
assertThat(mergeResult.hasConflicts(), equalTo(false));

View File

@ -36,7 +36,7 @@ import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.core.DateFieldMapper;
import org.elasticsearch.index.mapper.core.LongFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Test;
@ -47,7 +47,7 @@ import java.util.*;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.Matchers.*;
public class SimpleDateMappingTests extends ElasticsearchTestCase {
public class SimpleDateMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testAutomaticDateParser() throws Exception {
@ -130,16 +130,19 @@ public class SimpleDateMappingTests extends ElasticsearchTestCase {
assertNumericTokensEqual(doc, defaultMapper, "date_field_en", "date_field_de");
assertNumericTokensEqual(doc, defaultMapper, "date_field_en", "date_field_default");
}
int i = 0;
private DocumentMapper mapper(String mapping) throws IOException {
// we serialize and deserialize the mapping to make sure serialization works just fine
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapperParser parser = createIndex("test-" + (i++)).mapperService().documentMapperParser();
DocumentMapper defaultMapper = parser.parse(mapping);
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.startObject();
defaultMapper.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
String rebuildMapping = builder.string();
return MapperTestUtils.newParser().parse(rebuildMapping);
return parser.parse(rebuildMapping);
}
private void assertNumericTokensEqual(ParsedDocument doc, DocumentMapper defaultMapper, String fieldA, String fieldB) throws IOException {
@ -293,7 +296,7 @@ public class SimpleDateMappingTests extends ElasticsearchTestCase {
// Unless the global ignore_malformed option is set to true
Settings indexSettings = settingsBuilder().put("index.mapping.ignore_malformed", true).build();
defaultMapper = MapperTestUtils.newParser(indexSettings).parse(mapping);
defaultMapper = createIndex("test2", indexSettings).mapperService().documentMapperParser().parse(mapping);
doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
.field("field3", "a")

View File

@ -20,19 +20,17 @@ package org.elasticsearch.index.mapper.dynamic;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.StrictDynamicMappingException;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
public class DynamicMappingTests extends ElasticsearchTestCase {
public class DynamicMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testDynamicTrue() throws IOException {
@ -43,7 +41,7 @@ public class DynamicMappingTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -64,7 +62,7 @@ public class DynamicMappingTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -86,7 +84,7 @@ public class DynamicMappingTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
try {
defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
@ -111,7 +109,7 @@ public class DynamicMappingTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject().startObject("obj1")
@ -135,7 +133,7 @@ public class DynamicMappingTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
try {
defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()

View File

@ -23,9 +23,8 @@ import org.apache.lucene.index.IndexableField;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMappers;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
@ -35,12 +34,12 @@ import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class GenericStoreDynamicTemplateTests extends ElasticsearchTestCase {
public class GenericStoreDynamicTemplateTests extends ElasticsearchSingleNodeTest {
@Test
public void testSimple() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/genericstore/test-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/genericstore/test-data.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();

View File

@ -23,9 +23,8 @@ import org.apache.lucene.index.IndexableField;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMappers;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
@ -35,12 +34,12 @@ import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class PathMatchDynamicTemplateTests extends ElasticsearchTestCase {
public class PathMatchDynamicTemplateTests extends ElasticsearchSingleNodeTest {
@Test
public void testSimple() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-data.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();

View File

@ -25,7 +25,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.hamcrest.Matchers;
import org.junit.Test;
@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class SimpleDynamicTemplatesTests extends ElasticsearchTestCase {
public class SimpleDynamicTemplatesTests extends ElasticsearchSingleNodeTest {
@Test
public void testMatchTypeOnly() throws Exception {
@ -45,7 +45,7 @@ public class SimpleDynamicTemplatesTests extends ElasticsearchTestCase {
.field("match_mapping_type", "string")
.startObject("mapping").field("index", "no").endObject()
.endObject().endObject().endArray().endObject().endObject();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(builder.string());
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(builder.string());
builder = JsonXContent.contentBuilder();
builder.startObject().field("_id", "1").field("s", "hello").field("l", 1).endObject();
docMapper.parse(builder.bytes());
@ -65,7 +65,7 @@ public class SimpleDynamicTemplatesTests extends ElasticsearchTestCase {
@Test
public void testSimple() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();
@ -118,9 +118,10 @@ public class SimpleDynamicTemplatesTests extends ElasticsearchTestCase {
@Test
public void testSimpleWithXContentTraverse() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper docMapper = parser.parse(mapping);
docMapper.refreshSource();
docMapper = MapperTestUtils.newParser().parse(docMapper.mappingSource().string());
docMapper = parser.parse(docMapper.mappingSource().string());
byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json");
Document doc = docMapper.parse(new BytesArray(json)).rootDoc();

View File

@ -24,18 +24,17 @@ import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
import org.elasticsearch.common.geo.GeoUtils;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
public class GeoShapeFieldMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void testDefaultConfiguration() throws IOException {
@ -45,7 +44,7 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));
@ -68,7 +67,7 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));
@ -91,7 +90,7 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));
@ -105,6 +104,8 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
@Test
public void testLevelPrecisionConfiguration() throws IOException {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
{
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties").startObject("location")
@ -116,7 +117,8 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));
@ -140,7 +142,7 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));
@ -164,7 +166,7 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));
@ -187,7 +189,7 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));
@ -202,6 +204,7 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
@Test
public void testLevelDefaults() throws IOException {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
{
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties").startObject("location")
@ -211,7 +214,8 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));
@ -233,7 +237,7 @@ public class GeoShapeFieldMapperTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

View File

@ -23,9 +23,8 @@ import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.hamcrest.MatcherAssert;
import org.junit.Test;
@ -34,7 +33,7 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
public class GeohashMappingGeoPointTests extends ElasticsearchTestCase {
public class GeohashMappingGeoPointTests extends ElasticsearchSingleNodeTest {
@Test
public void testLatLonValues() throws Exception {
@ -42,7 +41,7 @@ public class GeohashMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", false).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -61,7 +60,7 @@ public class GeohashMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", false).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -80,7 +79,7 @@ public class GeohashMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("geohash", true).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -99,7 +98,7 @@ public class GeohashMappingGeoPointTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("point").field("type", "geo_point").field("geohash_precision", 10).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldMapper mapper = defaultMapper.mappers().smartName("point").mapper();
assertThat(mapper, instanceOf(GeoPointFieldMapper.class));
GeoPointFieldMapper geoPointFieldMapper = (GeoPointFieldMapper) mapper;
@ -111,7 +110,7 @@ public class GeohashMappingGeoPointTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("point").field("type", "geo_point").field("geohash_precision", "5m").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
FieldMapper mapper = defaultMapper.mappers().smartName("point").mapper();
assertThat(mapper, instanceOf(GeoPointFieldMapper.class));
GeoPointFieldMapper geoPointFieldMapper = (GeoPointFieldMapper) mapper;
@ -124,7 +123,7 @@ public class GeohashMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()

View File

@ -22,19 +22,17 @@ package org.elasticsearch.index.mapper.geo;
import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
/**
*
*/
public class LatLonAndGeohashMappingGeoPointTests extends ElasticsearchTestCase {
public class LatLonAndGeohashMappingGeoPointTests extends ElasticsearchSingleNodeTest {
@Test
public void testLatLonValues() throws Exception {
@ -42,7 +40,7 @@ public class LatLonAndGeohashMappingGeoPointTests extends ElasticsearchTestCase
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -61,7 +59,7 @@ public class LatLonAndGeohashMappingGeoPointTests extends ElasticsearchTestCase
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -80,7 +78,7 @@ public class LatLonAndGeohashMappingGeoPointTests extends ElasticsearchTestCase
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()

View File

@ -23,18 +23,16 @@ import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
*
*/
public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
public class LatLonMappingGeoPointTests extends ElasticsearchSingleNodeTest {
@Test
public void testNormalizeLatLonValuesDefault() throws Exception {
@ -43,7 +41,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -76,7 +74,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("normalize", false).field("validate", true).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
@ -137,7 +135,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("normalize", false).field("validate", false).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
@ -177,7 +175,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -199,7 +197,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -221,7 +219,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -248,7 +246,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -267,7 +265,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -288,7 +286,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -315,7 +313,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -334,7 +332,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -353,7 +351,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -374,7 +372,7 @@ public class LatLonMappingGeoPointTests extends ElasticsearchTestCase {
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()

View File

@ -24,25 +24,23 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.internal.IdFieldMapper;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
*/
public class IdMappingTests extends ElasticsearchTestCase {
public class IdMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void simpleIdTests() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -76,7 +74,7 @@ public class IdMappingTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_id").field("index", "not_analyzed").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -101,7 +99,7 @@ public class IdMappingTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_id").field("path", "my_path").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
// serialize the id mapping
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();

View File

@ -21,26 +21,25 @@ package org.elasticsearch.index.mapper.index;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.internal.IndexFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
*
*/
public class IndexTypeMapperTests extends ElasticsearchTestCase {
public class IndexTypeMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void simpleIndexMapperTests() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_index").field("enabled", true).field("store", "yes").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
IndexFieldMapper indexMapper = docMapper.rootMapper(IndexFieldMapper.class);
assertThat(indexMapper.enabled(), equalTo(true));
assertThat(indexMapper.fieldType().stored(), equalTo(true));
@ -61,7 +60,7 @@ public class IndexTypeMapperTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_index").field("enabled", false).field("store", "yes").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
IndexFieldMapper indexMapper = docMapper.rootMapper(IndexFieldMapper.class);
assertThat(indexMapper.enabled(), equalTo(false));
assertThat(indexMapper.fieldType().stored(), equalTo(true));
@ -80,7 +79,7 @@ public class IndexTypeMapperTests extends ElasticsearchTestCase {
public void defaultDisabledIndexMapperTests() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
IndexFieldMapper indexMapper = docMapper.rootMapper(IndexFieldMapper.class);
assertThat(indexMapper.enabled(), equalTo(false));
assertThat(indexMapper.fieldType().stored(), equalTo(false));
@ -100,13 +99,14 @@ public class IndexTypeMapperTests extends ElasticsearchTestCase {
String mappingWithIndexEnabled = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_index").field("enabled", true).field("store", "yes").endObject()
.endObject().endObject().string();
DocumentMapper mapperEnabled = MapperTestUtils.newParser().parse(mappingWithIndexEnabled);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper mapperEnabled = parser.parse(mappingWithIndexEnabled);
String mappingWithIndexDisabled = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_index").field("enabled", false).field("store", "yes").endObject()
.endObject().endObject().string();
DocumentMapper mapperDisabled = MapperTestUtils.newParser().parse(mappingWithIndexDisabled);
DocumentMapper mapperDisabled = parser.parse(mappingWithIndexDisabled);
mapperEnabled.merge(mapperDisabled, DocumentMapper.MergeFlags.mergeFlags().simulate(false));
assertThat(mapperEnabled.IndexFieldMapper().enabled(), is(false));

View File

@ -23,15 +23,14 @@ import com.google.common.collect.ImmutableSet;
import org.apache.lucene.index.IndexableField;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class FieldNamesFieldMapperTests extends ElasticsearchTestCase {
public class FieldNamesFieldMapperTests extends ElasticsearchSingleNodeTest {
private static Set<String> extract(String path) {
return ImmutableSet.<String>builder().addAll(FieldNamesFieldMapper.extractFieldNames(path)).build();
@ -52,7 +51,7 @@ public class FieldNamesFieldMapperTests extends ElasticsearchTestCase {
}
public void test() throws Exception {
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string());
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string());
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()

View File

@ -21,27 +21,22 @@ package org.elasticsearch.index.mapper.lucene;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.test.ElasticsearchLuceneTestCase;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeLuceneTestCase;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class DoubleIndexingDocTest extends ElasticsearchLuceneTestCase {
public class DoubleIndexingDocTest extends ElasticsearchSingleNodeLuceneTestCase {
@Test
public void testDoubleIndexingSameDoc() throws Exception {
@ -51,7 +46,7 @@ public class DoubleIndexingDocTest extends ElasticsearchLuceneTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").endObject()
.endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()

View File

@ -19,7 +19,9 @@
package org.elasticsearch.index.mapper.lucene;
import org.apache.lucene.document.*;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.StoredField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
@ -32,19 +34,19 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.fieldvisitor.CustomFieldsVisitor;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.util.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class StoredNumericValuesTest extends ElasticsearchTestCase{
public class StoredNumericValuesTest extends ElasticsearchSingleNodeTest {
@Test
public void testBytesAndNumericRepresentation() throws Exception {
@ -61,7 +63,7 @@ public class StoredNumericValuesTest extends ElasticsearchTestCase{
.endObject()
.endObject()
.string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()

View File

@ -22,19 +22,18 @@ package org.elasticsearch.index.mapper.merge;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.object.ObjectMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.elasticsearch.index.mapper.DocumentMapper.MergeFlags.mergeFlags;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
*
*/
public class TestMergeMapperTests extends ElasticsearchTestCase {
public class TestMergeMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void test1Merge() throws Exception {
@ -42,13 +41,14 @@ public class TestMergeMapperTests extends ElasticsearchTestCase {
String stage1Mapping = XContentFactory.jsonBuilder().startObject().startObject("person").startObject("properties")
.startObject("name").field("type", "string").endObject()
.endObject().endObject().endObject().string();
DocumentMapper stage1 = MapperTestUtils.newParser().parse(stage1Mapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper stage1 = parser.parse(stage1Mapping);
String stage2Mapping = XContentFactory.jsonBuilder().startObject().startObject("person").startObject("properties")
.startObject("name").field("type", "string").endObject()
.startObject("age").field("type", "integer").endObject()
.startObject("obj1").startObject("properties").startObject("prop1").field("type", "integer").endObject().endObject().endObject()
.endObject().endObject().endObject().string();
DocumentMapper stage2 = MapperTestUtils.newParser().parse(stage2Mapping);
DocumentMapper stage2 = parser.parse(stage2Mapping);
DocumentMapper.MergeResult mergeResult = stage1.merge(stage2, mergeFlags().simulate(true));
assertThat(mergeResult.hasConflicts(), equalTo(false));
@ -66,12 +66,13 @@ public class TestMergeMapperTests extends ElasticsearchTestCase {
@Test
public void testMergeObjectDynamic() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String objectMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(objectMapping);
DocumentMapper mapper = parser.parse(objectMapping);
assertThat(mapper.root().dynamic(), equalTo(ObjectMapper.Dynamic.TRUE));
String withDynamicMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").field("dynamic", "false").endObject().endObject().string();
DocumentMapper withDynamicMapper = MapperTestUtils.newParser().parse(withDynamicMapping);
DocumentMapper withDynamicMapper = parser.parse(withDynamicMapping);
assertThat(withDynamicMapper.root().dynamic(), equalTo(ObjectMapper.Dynamic.FALSE));
DocumentMapper.MergeResult mergeResult = mapper.merge(withDynamicMapper, mergeFlags().simulate(false));
@ -81,14 +82,15 @@ public class TestMergeMapperTests extends ElasticsearchTestCase {
@Test
public void testMergeObjectAndNested() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String objectMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("obj").field("type", "object").endObject()
.endObject().endObject().endObject().string();
DocumentMapper objectMapper = MapperTestUtils.newParser().parse(objectMapping);
DocumentMapper objectMapper = parser.parse(objectMapping);
String nestedMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("obj").field("type", "nested").endObject()
.endObject().endObject().endObject().string();
DocumentMapper nestedMapper = MapperTestUtils.newParser().parse(nestedMapping);
DocumentMapper nestedMapper = parser.parse(nestedMapping);
DocumentMapper.MergeResult mergeResult = objectMapper.merge(nestedMapper, mergeFlags().simulate(true));
assertThat(mergeResult.hasConflicts(), equalTo(true));
@ -102,6 +104,7 @@ public class TestMergeMapperTests extends ElasticsearchTestCase {
@Test
public void testMergeSearchAnalyzer() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "string").field("search_analyzer", "whitespace").endObject().endObject()
.endObject().endObject().string();
@ -109,8 +112,8 @@ public class TestMergeMapperTests extends ElasticsearchTestCase {
.startObject("properties").startObject("field").field("type", "string").field("search_analyzer", "keyword").endObject().endObject()
.endObject().endObject().string();
DocumentMapper existing = MapperTestUtils.newParser().parse(mapping1);
DocumentMapper changed = MapperTestUtils.newParser().parse(mapping2);
DocumentMapper existing = parser.parse(mapping1);
DocumentMapper changed = parser.parse(mapping2);
assertThat(((NamedAnalyzer) existing.mappers().name("field").mapper().searchAnalyzer()).name(), equalTo("whitespace"));
DocumentMapper.MergeResult mergeResult = existing.merge(changed, mergeFlags().simulate(false));
@ -121,6 +124,7 @@ public class TestMergeMapperTests extends ElasticsearchTestCase {
@Test
public void testNotChangeSearchAnalyzer() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "string").field("search_analyzer", "whitespace").endObject().endObject()
.endObject().endObject().string();
@ -128,8 +132,8 @@ public class TestMergeMapperTests extends ElasticsearchTestCase {
.startObject("properties").startObject("field").field("type", "string").field("postings_format", "direct").endObject().endObject()
.endObject().endObject().string();
DocumentMapper existing = MapperTestUtils.newParser().parse(mapping1);
DocumentMapper changed = MapperTestUtils.newParser().parse(mapping2);
DocumentMapper existing = parser.parse(mapping1);
DocumentMapper changed = parser.parse(mapping2);
assertThat(((NamedAnalyzer) existing.mappers().name("field").mapper().searchAnalyzer()).name(), equalTo("whitespace"));
DocumentMapper.MergeResult mergeResult = existing.merge(changed, mergeFlags().simulate(false));

View File

@ -25,11 +25,10 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.core.*;
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
@ -41,7 +40,7 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
public class MultiFieldTests extends ElasticsearchTestCase {
public class MultiFieldTests extends ElasticsearchSingleNodeTest {
@Test
public void testMultiField_multiFieldType() throws Exception {
@ -56,7 +55,7 @@ public class MultiFieldTests extends ElasticsearchTestCase {
}
private void testMultiField(String mapping) throws Exception {
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json"));
Document doc = docMapper.parse(json).rootDoc();
@ -128,7 +127,7 @@ public class MultiFieldTests extends ElasticsearchTestCase {
@Test
public void testBuildThenParse() throws Exception {
DocumentMapperParser mapperParser = MapperTestUtils.newParser();
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper builderDocMapper = doc("test", rootObject("person").add(
stringField("name").store(true)
@ -169,7 +168,7 @@ public class MultiFieldTests extends ElasticsearchTestCase {
@Test
public void testConvertMultiFieldNoDefaultField() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/test-multi-field-type-no-default-field.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/multifield/test-data.json"));
Document doc = docMapper.parse(json).rootDoc();
@ -239,7 +238,7 @@ public class MultiFieldTests extends ElasticsearchTestCase {
@Test
public void testConvertMultiFieldGeoPoint() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/test-multi-field-type-geo_point.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.mappers().fullName("a").mapper(), notNullValue());
assertThat(docMapper.mappers().fullName("a").mapper(), instanceOf(StringFieldMapper.class));
@ -339,7 +338,7 @@ public class MultiFieldTests extends ElasticsearchTestCase {
@Test
public void testConvertMultiFieldCompletion() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/test-multi-field-type-completion.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.mappers().fullName("a").mapper(), notNullValue());
assertThat(docMapper.mappers().fullName("a").mapper(), instanceOf(StringFieldMapper.class));

View File

@ -24,9 +24,8 @@ import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.util.Arrays;
@ -39,12 +38,12 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
public class JavaMultiFieldMergeTests extends ElasticsearchTestCase {
public class JavaMultiFieldMergeTests extends ElasticsearchSingleNodeTest {
@Test
public void testMergeMultiField() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping1.json");
DocumentMapperParser parser = MapperTestUtils.newParser();
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper docMapper = parser.parse(mapping);
@ -120,7 +119,7 @@ public class JavaMultiFieldMergeTests extends ElasticsearchTestCase {
@Test
public void testUpgradeFromMultiFieldTypeToMultiFields() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/merge/test-mapping1.json");
DocumentMapperParser parser = MapperTestUtils.newParser();
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper docMapper = parser.parse(mapping);

View File

@ -21,17 +21,16 @@ package org.elasticsearch.index.mapper.nested;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.index.mapper.object.ObjectMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
public class NestedMappingTests extends ElasticsearchTestCase {
public class NestedMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void emptyNested() throws Exception {
@ -39,7 +38,7 @@ public class NestedMappingTests extends ElasticsearchTestCase {
.startObject("nested1").field("type", "nested").endObject()
.endObject().endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -66,7 +65,7 @@ public class NestedMappingTests extends ElasticsearchTestCase {
.startObject("nested1").field("type", "nested").endObject()
.endObject().endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.hasNestedObjects(), equalTo(true));
ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
@ -116,7 +115,7 @@ public class NestedMappingTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.hasNestedObjects(), equalTo(true));
ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
@ -168,7 +167,7 @@ public class NestedMappingTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.hasNestedObjects(), equalTo(true));
ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
@ -220,7 +219,7 @@ public class NestedMappingTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.hasNestedObjects(), equalTo(true));
ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
@ -272,7 +271,7 @@ public class NestedMappingTests extends ElasticsearchTestCase {
.endObject().endObject()
.endObject().endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.hasNestedObjects(), equalTo(true));
ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");

View File

@ -33,7 +33,7 @@ import org.elasticsearch.index.mapper.core.LongFieldMapper;
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.mapper.string.SimpleStringMappingTests;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.io.IOException;
@ -43,7 +43,7 @@ import static org.hamcrest.Matchers.*;
/**
*/
public class SimpleNumericTests extends ElasticsearchTestCase {
public class SimpleNumericTests extends ElasticsearchSingleNodeTest {
@Test
public void testNumericDetectionEnabled() throws Exception {
@ -51,7 +51,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
.field("numeric_detection", true)
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -72,7 +72,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -98,7 +98,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -132,7 +132,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
// Unless the global ignore_malformed option is set to true
Settings indexSettings = settingsBuilder().put("index.mapping.ignore_malformed", true).build();
defaultMapper = MapperTestUtils.newParser(indexSettings).parse(mapping);
defaultMapper = createIndex("test2", indexSettings).mapperService().documentMapperParser().parse(mapping);
doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
.field("field3", "a")
@ -156,6 +156,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
public void testCoerceOption() throws Exception {
String [] nonFractionNumericFieldTypes={"integer","long","short"};
//Test co-ercion policies on all non-fraction numerics
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
for (String nonFractionNumericFieldType : nonFractionNumericFieldTypes) {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties")
@ -169,7 +170,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
//Test numbers passed as strings
String invalidJsonNumberAsString="1";
@ -269,7 +270,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument parsedDoc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -305,7 +306,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument parsedDoc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -338,7 +339,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
.field("date_detection", true)
.endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -389,7 +390,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -460,7 +461,7 @@ public class SimpleNumericTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()

View File

@ -21,20 +21,18 @@ package org.elasticsearch.index.mapper.object;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class NullValueObjectMappingTests extends ElasticsearchTestCase {
public class NullValueObjectMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testNullValueObject() throws IOException {
@ -42,7 +40,7 @@ public class NullValueObjectMappingTests extends ElasticsearchTestCase {
.startObject("properties").startObject("obj1").field("type", "object").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()

View File

@ -23,20 +23,19 @@ import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
/**
*/
public class SimpleObjectMappingTests extends ElasticsearchTestCase {
public class SimpleObjectMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testDifferentInnerObjectTokenFailure() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
try {
defaultMapper.parse("type", "1", new BytesArray(" {\n" +
" \"object\": {\n" +
@ -62,6 +61,6 @@ public class SimpleObjectMappingTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startArray("properties").endArray()
.endObject().endObject().string();
MapperTestUtils.newParser().parse(mapping);
createIndex("test").mapperService().documentMapperParser().parse(mapping);
}
}

View File

@ -19,8 +19,11 @@
package org.elasticsearch.index.mapper.parent;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
@ -29,13 +32,13 @@ import static org.hamcrest.Matchers.nullValue;
/**
*
*/
public class ParentMappingTests extends ElasticsearchTestCase {
public class ParentMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void parentNotMapped() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse(SourceToParse.source(XContentFactory.jsonBuilder()
.startObject()
@ -54,7 +57,7 @@ public class ParentMappingTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_parent").field("type", "p_type").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse(SourceToParse.source(XContentFactory.jsonBuilder()
.startObject()
@ -72,7 +75,7 @@ public class ParentMappingTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_parent").field("type", "p_type").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse(SourceToParse.source(XContentFactory.jsonBuilder()
.startObject()
@ -88,7 +91,7 @@ public class ParentMappingTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_parent").field("type", "p_type").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse(SourceToParse.source(XContentFactory.jsonBuilder()
.startObject()

View File

@ -20,26 +20,24 @@
package org.elasticsearch.index.mapper.path;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.io.IOException;
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
/**
*
*/
public class PathMapperTests extends ElasticsearchTestCase {
public class PathMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void testPathMapping() throws IOException {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/path/test-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.mappers().indexName("first1"), notNullValue());
assertThat(docMapper.mappers().indexName("name1.first1"), nullValue());

View File

@ -24,10 +24,9 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.util.Map;
@ -37,13 +36,13 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
public class RoutingTypeMapperTests extends ElasticsearchTestCase {
public class RoutingTypeMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void simpleRoutingMapperTests() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = docMapper.parse(SourceToParse.source(XContentFactory.jsonBuilder()
.startObject()
@ -64,7 +63,7 @@ public class RoutingTypeMapperTests extends ElasticsearchTestCase {
.field("path", "route")
.endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.routingFieldMapper().fieldType().stored(), equalTo(false));
assertThat(docMapper.routingFieldMapper().fieldType().indexed(), equalTo(false));
assertThat(docMapper.routingFieldMapper().path(), equalTo("route"));
@ -75,7 +74,7 @@ public class RoutingTypeMapperTests extends ElasticsearchTestCase {
String enabledMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_routing").field("store", "no").field("index", "no").endObject()
.endObject().endObject().string();
DocumentMapper enabledMapper = MapperTestUtils.newParser().parse(enabledMapping);
DocumentMapper enabledMapper = createIndex("test").mapperService().documentMapperParser().parse(enabledMapping);
XContentBuilder builder = JsonXContent.contentBuilder().startObject();
enabledMapper.routingFieldMapper().toXContent(builder, ToXContent.EMPTY_PARAMS).endObject();

View File

@ -26,7 +26,7 @@ import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
@ -37,11 +37,11 @@ import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class SimpleMapperTests extends ElasticsearchTestCase {
public class SimpleMapperTests extends ElasticsearchSingleNodeTest {
@Test
public void testSimpleMapper() throws Exception {
DocumentMapperParser mapperParser = MapperTestUtils.newParser();
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper docMapper = doc("test",
rootObject("person")
.add(object("name").add(stringField("first").store(true).index(false)))
@ -62,11 +62,12 @@ public class SimpleMapperTests extends ElasticsearchTestCase {
@Test
public void testParseToJsonAndParse() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper docMapper = parser.parse(mapping);
String builtMapping = docMapper.mappingSource().string();
// System.out.println(builtMapping);
// reparse it
DocumentMapper builtDocMapper = MapperTestUtils.newParser().parse(builtMapping);
DocumentMapper builtDocMapper = parser.parse(builtMapping);
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
Document doc = builtDocMapper.parse(json).rootDoc();
assertThat(doc.get(docMapper.uidMapper().names().indexName()), equalTo(Uid.createUid("person", "1")));
@ -78,7 +79,7 @@ public class SimpleMapperTests extends ElasticsearchTestCase {
@Test
public void testSimpleParser() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat((String) docMapper.meta().get("param1"), equalTo("value1"));
@ -93,7 +94,7 @@ public class SimpleMapperTests extends ElasticsearchTestCase {
@Test
public void testSimpleParserNoTypeNoId() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1-notype-noid.json"));
Document doc = docMapper.parse("person", "1", json).rootDoc();
assertThat(doc.get(docMapper.uidMapper().names().indexName()), equalTo(Uid.createUid("person", "1")));
@ -105,18 +106,19 @@ public class SimpleMapperTests extends ElasticsearchTestCase {
@Test
public void testAttributes() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper docMapper = parser.parse(mapping);
assertThat((String) docMapper.meta().get("param1"), equalTo("value1"));
String builtMapping = docMapper.mappingSource().string();
DocumentMapper builtDocMapper = MapperTestUtils.newParser().parse(builtMapping);
DocumentMapper builtDocMapper = parser.parse(builtMapping);
assertThat((String) builtDocMapper.meta().get("param1"), equalTo("value1"));
}
@Test
public void testNoDocumentSent() throws Exception {
DocumentMapperParser mapperParser = MapperTestUtils.newParser();
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper docMapper = doc("test",
rootObject("person")
.add(object("name").add(stringField("first").store(true).index(false)))
@ -135,7 +137,7 @@ public class SimpleMapperTests extends ElasticsearchTestCase {
public void testTypeWrapperWithSetting() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
Settings settings = ImmutableSettings.settingsBuilder().put("index.mapping.allow_type_wrapper", true).build();
DocumentMapper docMapper = MapperTestUtils.newParser(settings).parse(mapping);
DocumentMapper docMapper = createIndex("test", settings).mapperService().documentMapperParser().parse(mapping);
assertThat((String) docMapper.meta().get("param1"), equalTo("value1"));

View File

@ -22,22 +22,22 @@ package org.elasticsearch.index.mapper.size;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
public class SizeMappingTests extends ElasticsearchTestCase {
public class SizeMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testSizeEnabled() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_size").field("enabled", true).endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference source = XContentFactory.jsonBuilder()
.startObject()
@ -55,7 +55,7 @@ public class SizeMappingTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_size").field("enabled", true).field("store", "yes").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference source = XContentFactory.jsonBuilder()
.startObject()
@ -73,7 +73,7 @@ public class SizeMappingTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_size").field("enabled", false).endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference source = XContentFactory.jsonBuilder()
.startObject()
@ -89,7 +89,7 @@ public class SizeMappingTests extends ElasticsearchTestCase {
public void testSizeNotSet() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference source = XContentFactory.jsonBuilder()
.startObject()
@ -106,12 +106,13 @@ public class SizeMappingTests extends ElasticsearchTestCase {
String enabledMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_size").field("enabled", true).endObject()
.endObject().endObject().string();
DocumentMapper enabledMapper = MapperTestUtils.newParser().parse(enabledMapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper enabledMapper = parser.parse(enabledMapping);
String disabledMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_size").field("enabled", false).endObject()
.endObject().endObject().string();
DocumentMapper disabledMapper = MapperTestUtils.newParser().parse(disabledMapping);
DocumentMapper disabledMapper = parser.parse(disabledMapping);
enabledMapper.merge(disabledMapper, DocumentMapper.MergeFlags.mergeFlags().simulate(false));
assertThat(enabledMapper.SizeFieldMapper().enabled(), is(false));

View File

@ -23,18 +23,16 @@ import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.compress.CompressorFactory;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class CompressSourceMappingTests extends ElasticsearchTestCase {
public class CompressSourceMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testCompressDisabled() throws Exception {
@ -42,7 +40,7 @@ public class CompressSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").field("compress", false).endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field1", "value1")
@ -58,7 +56,7 @@ public class CompressSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").field("compress", true).endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field1", "value1")
@ -75,7 +73,7 @@ public class CompressSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").field("compress_threshold", "200b").endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field1", "value1")

View File

@ -26,7 +26,7 @@ import org.elasticsearch.common.compress.CompressorFactory;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.util.Map;
@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class DefaultSourceMappingTests extends ElasticsearchTestCase {
public class DefaultSourceMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testNoFormat() throws Exception {
@ -44,14 +44,15 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper documentMapper = parser.parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field", "value")
.endObject().bytes());
assertThat(XContentFactory.xContentType(doc.source()), equalTo(XContentType.JSON));
documentMapper = MapperTestUtils.newParser().parse(mapping);
documentMapper = parser.parse(mapping);
doc = documentMapper.parse("type", "1", XContentFactory.smileBuilder().startObject()
.field("field", "value")
.endObject().bytes());
@ -65,14 +66,15 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").field("format", "json").endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper documentMapper = parser.parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field", "value")
.endObject().bytes());
assertThat(XContentFactory.xContentType(doc.source()), equalTo(XContentType.JSON));
documentMapper = MapperTestUtils.newParser().parse(mapping);
documentMapper = parser.parse(mapping);
doc = documentMapper.parse("type", "1", XContentFactory.smileBuilder().startObject()
.field("field", "value")
.endObject().bytes());
@ -86,7 +88,8 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").field("format", "json").field("compress", true).endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper documentMapper = parser.parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field", "value")
.endObject().bytes());
@ -95,7 +98,7 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
byte[] uncompressed = CompressorFactory.uncompressIfNeeded(doc.source()).toBytes();
assertThat(XContentFactory.xContentType(uncompressed), equalTo(XContentType.JSON));
documentMapper = MapperTestUtils.newParser().parse(mapping);
documentMapper = parser.parse(mapping);
doc = documentMapper.parse("type", "1", XContentFactory.smileBuilder().startObject()
.field("field", "value")
.endObject().bytes());
@ -111,7 +114,7 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").field("includes", new String[]{"path1*"}).endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper documentMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.startObject("path1").field("field1", "value1").endObject()
@ -130,11 +133,12 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").field("enabled", false).endObject()
.endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse("my_type", null, defaultMapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper mapper = parser.parse("my_type", null, defaultMapping);
assertThat(mapper.type(), equalTo("my_type"));
assertThat(mapper.sourceMapper().enabled(), equalTo(false));
try {
mapper = MapperTestUtils.newParser().parse(null, null, defaultMapping);
mapper = parser.parse(null, null, defaultMapping);
assertThat(mapper.type(), equalTo("my_type"));
assertThat(mapper.sourceMapper().enabled(), equalTo(false));
fail();
@ -142,7 +146,7 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
// all is well
}
try {
mapper = MapperTestUtils.newParser().parse(null, "{}", defaultMapping);
mapper = parser.parse(null, "{}", defaultMapping);
assertThat(mapper.type(), equalTo("my_type"));
assertThat(mapper.sourceMapper().enabled(), equalTo(false));
fail();
@ -162,7 +166,7 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").field("enabled", true).endObject()
.endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse("my_type", mapping, defaultMapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse("my_type", mapping, defaultMapping);
assertThat(mapper.type(), equalTo("my_type"));
assertThat(mapper.sourceMapper().enabled(), equalTo(true));
}
@ -173,7 +177,7 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").field("enabled", false).endObject()
.endObject().endObject().string();
MapperService mapperService = MapperTestUtils.newMapperService();
MapperService mapperService = createIndex("test").mapperService();
mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedString(defaultMapping), true);
DocumentMapper mapper = mapperService.documentMapperWithAutoCreate("my_type").v1();
@ -187,7 +191,7 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
.startObject("_source").field("enabled", false).endObject()
.endObject().endObject().string();
MapperService mapperService = MapperTestUtils.newMapperService();
MapperService mapperService = createIndex("test").mapperService();
mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedString(defaultMapping), true);
String mapping = XContentFactory.jsonBuilder().startObject().startObject("my_type")

View File

@ -35,7 +35,8 @@ import org.elasticsearch.index.mapper.DocumentMapper.MergeResult;
import org.elasticsearch.index.mapper.Mapper.BuilderContext;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
@ -44,17 +45,24 @@ import static org.hamcrest.Matchers.*;
/**
*/
public class SimpleStringMappingTests extends ElasticsearchTestCase {
public class SimpleStringMappingTests extends ElasticsearchSingleNodeTest {
private static Settings DOC_VALUES_SETTINGS = ImmutableSettings.builder().put(FieldDataType.FORMAT_KEY, FieldDataType.DOC_VALUES_FORMAT_VALUE).build();
DocumentMapperParser parser;
@Before
public void before() {
parser = createIndex("test").mapperService().documentMapperParser();
}
@Test
public void testLimit() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "string").field("ignore_above", 5).endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -101,7 +109,7 @@ public class SimpleStringMappingTests extends ElasticsearchTestCase {
private void assertParseIdemPotent(IndexableFieldType expected, DocumentMapper mapper) throws Exception {
String mapping = mapper.toXContent(XContentFactory.jsonBuilder().startObject(), new ToXContent.MapParams(ImmutableMap.<String, String>of())).endObject().string();
mapper = MapperTestUtils.newParser().parse(mapping);
mapper = parser.parse(mapping);
ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
.field("field", "2345")
@ -116,7 +124,7 @@ public class SimpleStringMappingTests extends ElasticsearchTestCase {
.startObject("properties").startObject("field").field("type", "string").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -135,7 +143,7 @@ public class SimpleStringMappingTests extends ElasticsearchTestCase {
.startObject("properties").startObject("field").field("type", "string").field("index", "not_analyzed").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -158,7 +166,7 @@ public class SimpleStringMappingTests extends ElasticsearchTestCase {
.startObject("properties").startObject("field").field("type", "string").field("index", "not_analyzed").startObject("norms").field("enabled", true).endObject().field("index_options", "freqs").endObject().endObject()
.endObject().endObject().string();
defaultMapper = MapperTestUtils.newParser().parse(mapping);
defaultMapper = parser.parse(mapping);
doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -181,7 +189,7 @@ public class SimpleStringMappingTests extends ElasticsearchTestCase {
.startObject("properties").startObject("field").field("type", "string").field("index", "not_analyzed").field("omit_norms", false).endObject().endObject()
.endObject().endObject().string();
defaultMapper = MapperTestUtils.newParser().parse(mapping);
defaultMapper = parser.parse(mapping);
doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -225,7 +233,7 @@ public class SimpleStringMappingTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -301,7 +309,7 @@ public class SimpleStringMappingTests extends ElasticsearchTestCase {
.endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
ParsedDocument parsedDoc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -329,7 +337,7 @@ public class SimpleStringMappingTests extends ElasticsearchTestCase {
.startObject("properties").startObject("field").field("type", "string").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper defaultMapper = parser.parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -343,7 +351,7 @@ public class SimpleStringMappingTests extends ElasticsearchTestCase {
String updatedMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "string").startObject("norms").field("enabled", false).endObject()
.endObject().endObject().endObject().endObject().string();
MergeResult mergeResult = defaultMapper.merge(MapperTestUtils.newParser().parse(updatedMapping), MergeFlags.mergeFlags().simulate(false));
MergeResult mergeResult = defaultMapper.merge(parser.parse(updatedMapping), MergeFlags.mergeFlags().simulate(false));
assertFalse(Arrays.toString(mergeResult.conflicts()), mergeResult.hasConflicts());
doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
@ -358,7 +366,7 @@ public class SimpleStringMappingTests extends ElasticsearchTestCase {
updatedMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "string").startObject("norms").field("enabled", true).endObject()
.endObject().endObject().endObject().endObject().string();
mergeResult = defaultMapper.merge(MapperTestUtils.newParser().parse(updatedMapping), MergeFlags.mergeFlags());
mergeResult = defaultMapper.merge(parser.parse(updatedMapping), MergeFlags.mergeFlags());
assertTrue(mergeResult.hasConflicts());
assertEquals(1, mergeResult.conflicts().length);
assertTrue(mergeResult.conflicts()[0].contains("cannot enable norms"));

View File

@ -25,11 +25,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.mapper.internal.TimestampFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import java.util.Locale;
@ -39,12 +39,12 @@ import static org.hamcrest.Matchers.*;
/**
*/
public class TimestampMappingTests extends ElasticsearchTestCase {
public class TimestampMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testSimpleDisabled() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference source = XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -60,7 +60,7 @@ public class TimestampMappingTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_timestamp").field("enabled", "yes").field("store", "yes").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference source = XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -76,7 +76,7 @@ public class TimestampMappingTests extends ElasticsearchTestCase {
@Test
public void testDefaultValues() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.timestampFieldMapper().enabled(), equalTo(TimestampFieldMapper.Defaults.ENABLED.enabled));
assertThat(docMapper.timestampFieldMapper().fieldType().stored(), equalTo(TimestampFieldMapper.Defaults.FIELD_TYPE.stored()));
assertThat(docMapper.timestampFieldMapper().fieldType().indexed(), equalTo(TimestampFieldMapper.Defaults.FIELD_TYPE.indexed()));
@ -93,7 +93,7 @@ public class TimestampMappingTests extends ElasticsearchTestCase {
.field("path", "timestamp").field("format", "year")
.endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.timestampFieldMapper().enabled(), equalTo(true));
assertThat(docMapper.timestampFieldMapper().fieldType().stored(), equalTo(true));
assertThat(docMapper.timestampFieldMapper().fieldType().indexed(), equalTo(false));
@ -106,12 +106,13 @@ public class TimestampMappingTests extends ElasticsearchTestCase {
String enabledMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_timestamp").field("enabled", true).field("store", "yes").endObject()
.endObject().endObject().string();
DocumentMapper enabledMapper = MapperTestUtils.newParser().parse(enabledMapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper enabledMapper = parser.parse(enabledMapping);
String disabledMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_timestamp").field("enabled", false).endObject()
.endObject().endObject().string();
DocumentMapper disabledMapper = MapperTestUtils.newParser().parse(disabledMapping);
DocumentMapper disabledMapper = parser.parse(disabledMapping);
enabledMapper.merge(disabledMapper, DocumentMapper.MergeFlags.mergeFlags().simulate(false));
@ -125,7 +126,7 @@ public class TimestampMappingTests extends ElasticsearchTestCase {
.startObject("_timestamp").field("enabled", false).field("store", inversedStoreSetting).endObject()
.endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
mapper.timestampFieldMapper().toXContent(builder, ToXContent.EMPTY_PARAMS);
@ -139,7 +140,7 @@ public class TimestampMappingTests extends ElasticsearchTestCase {
String enabledMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_timestamp").field("enabled", true).field("store", "yes").field("index", "no").endObject()
.endObject().endObject().string();
DocumentMapper enabledMapper = MapperTestUtils.newParser().parse(enabledMapping);
DocumentMapper enabledMapper = createIndex("test").mapperService().documentMapperParser().parse(enabledMapping);
XContentBuilder builder = JsonXContent.contentBuilder().startObject();
enabledMapper.timestampFieldMapper().toXContent(builder, ToXContent.EMPTY_PARAMS).endObject();

View File

@ -22,21 +22,21 @@ package org.elasticsearch.index.mapper.ttl;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.mapper.internal.TTLFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
public class TTLMappingTests extends ElasticsearchTestCase {
public class TTLMappingTests extends ElasticsearchSingleNodeTest {
@Test
public void testSimpleDisabled() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference source = XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -52,7 +52,7 @@ public class TTLMappingTests extends ElasticsearchTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_ttl").field("enabled", "yes").endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
BytesReference source = XContentFactory.jsonBuilder()
.startObject()
.field("field", "value")
@ -68,7 +68,7 @@ public class TTLMappingTests extends ElasticsearchTestCase {
@Test
public void testDefaultValues() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.TTLFieldMapper().enabled(), equalTo(TTLFieldMapper.Defaults.ENABLED_STATE.enabled));
assertThat(docMapper.TTLFieldMapper().fieldType().stored(), equalTo(TTLFieldMapper.Defaults.TTL_FIELD_TYPE.stored()));
assertThat(docMapper.TTLFieldMapper().fieldType().indexed(), equalTo(TTLFieldMapper.Defaults.TTL_FIELD_TYPE.indexed()));
@ -82,7 +82,7 @@ public class TTLMappingTests extends ElasticsearchTestCase {
.field("enabled", "yes").field("store", "no").field("index", "no")
.endObject()
.endObject().endObject().string();
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping);
assertThat(docMapper.TTLFieldMapper().enabled(), equalTo(true));
assertThat(docMapper.TTLFieldMapper().fieldType().stored(), equalTo(false));
assertThat(docMapper.TTLFieldMapper().fieldType().indexed(), equalTo(false));
@ -101,8 +101,9 @@ public class TTLMappingTests extends ElasticsearchTestCase {
.startObject("properties").field("field").startObject().field("type", "string").endObject().endObject()
.endObject().endObject().string();
DocumentMapper mapperWithoutTtl = MapperTestUtils.newParser().parse(mappingWithoutTtl);
DocumentMapper mapperWithTtl = MapperTestUtils.newParser().parse(mappingWithTtl);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper mapperWithoutTtl = parser.parse(mappingWithoutTtl);
DocumentMapper mapperWithTtl = parser.parse(mappingWithTtl);
DocumentMapper.MergeFlags mergeFlags = DocumentMapper.MergeFlags.mergeFlags().simulate(false);
DocumentMapper.MergeResult mergeResult = mapperWithoutTtl.merge(mapperWithTtl, mergeFlags);
@ -127,8 +128,9 @@ public class TTLMappingTests extends ElasticsearchTestCase {
.startObject("properties").field("field").startObject().field("type", "string").endObject().endObject()
.endObject().endObject().string();
DocumentMapper initialMapper = MapperTestUtils.newParser().parse(mappingWithTtl);
DocumentMapper updatedMapper = MapperTestUtils.newParser().parse(updatedMapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper initialMapper = parser.parse(mappingWithTtl);
DocumentMapper updatedMapper = parser.parse(updatedMapping);
DocumentMapper.MergeFlags mergeFlags = DocumentMapper.MergeFlags.mergeFlags().simulate(false);
DocumentMapper.MergeResult mergeResult = initialMapper.merge(updatedMapper, mergeFlags);

View File

@ -21,9 +21,8 @@ package org.elasticsearch.index.mapper.typelevels;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
@ -31,13 +30,13 @@ import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class ParseDocumentTypeLevelsTests extends ElasticsearchTestCase {
public class ParseDocumentTypeLevelsTests extends ElasticsearchSingleNodeTest {
@Test
public void testNoLevel() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(defaultMapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(defaultMapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -56,7 +55,7 @@ public class ParseDocumentTypeLevelsTests extends ElasticsearchTestCase {
public void testTypeLevel() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(defaultMapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(defaultMapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject().startObject("type")
@ -75,7 +74,7 @@ public class ParseDocumentTypeLevelsTests extends ElasticsearchTestCase {
public void testNoLevelWithFieldTypeAsValue() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(defaultMapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(defaultMapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -96,7 +95,7 @@ public class ParseDocumentTypeLevelsTests extends ElasticsearchTestCase {
public void testTypeLevelWithFieldTypeAsValue() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(defaultMapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(defaultMapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject().startObject("type")
@ -117,7 +116,7 @@ public class ParseDocumentTypeLevelsTests extends ElasticsearchTestCase {
public void testNoLevelWithFieldTypeAsObject() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(defaultMapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(defaultMapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -138,7 +137,7 @@ public class ParseDocumentTypeLevelsTests extends ElasticsearchTestCase {
public void testTypeLevelWithFieldTypeAsObject() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(defaultMapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(defaultMapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject().startObject("type")
@ -159,7 +158,7 @@ public class ParseDocumentTypeLevelsTests extends ElasticsearchTestCase {
public void testNoLevelWithFieldTypeAsValueNotFirst() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(defaultMapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(defaultMapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject().startObject("type")
@ -180,7 +179,7 @@ public class ParseDocumentTypeLevelsTests extends ElasticsearchTestCase {
public void testTypeLevelWithFieldTypeAsValueNotFirst() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(defaultMapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(defaultMapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject().startObject("type")
@ -201,7 +200,7 @@ public class ParseDocumentTypeLevelsTests extends ElasticsearchTestCase {
public void testNoLevelWithFieldTypeAsObjectNotFirst() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(defaultMapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(defaultMapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
@ -223,7 +222,7 @@ public class ParseDocumentTypeLevelsTests extends ElasticsearchTestCase {
public void testTypeLevelWithFieldTypeAsObjectNotFirst() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(defaultMapping);
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse(defaultMapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject().startObject("type")

View File

@ -21,17 +21,16 @@ package org.elasticsearch.index.mapper.typelevels;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class ParseMappingTypeLevelTests extends ElasticsearchTestCase {
public class ParseMappingTypeLevelTests extends ElasticsearchSingleNodeTest {
@Test
public void testTypeLevel() throws Exception {
@ -39,11 +38,12 @@ public class ParseMappingTypeLevelTests extends ElasticsearchTestCase {
.startObject("_source").field("enabled", false).endObject()
.endObject().endObject().string();
DocumentMapper mapper = MapperTestUtils.newParser().parse("type", mapping);
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper mapper = parser.parse("type", mapping);
assertThat(mapper.type(), equalTo("type"));
assertThat(mapper.sourceMapper().enabled(), equalTo(false));
mapper = MapperTestUtils.newParser().parse(mapping);
mapper = parser.parse(mapping);
assertThat(mapper.type(), equalTo("type"));
assertThat(mapper.sourceMapper().enabled(), equalTo(false));
}

View File

@ -31,12 +31,11 @@ import org.elasticsearch.common.lucene.search.NoCacheFilter;
import org.elasticsearch.common.lucene.search.XBooleanFilter;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.search.child.TestSearchContext;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.elasticsearch.test.index.service.StubIndexService;
import org.elasticsearch.test.TestSearchContext;
import org.junit.Before;
import org.junit.Test;
@ -61,14 +60,15 @@ public class IndexQueryParserFilterCachingTests extends ElasticsearchSingleNodeT
.put("index.cache.filter.type", "weighted")
.put("name", "IndexQueryParserFilterCachingTests")
.build();
injector = createIndex("test", settings).injector();
IndexService indexService = createIndex("test", settings);
injector = indexService.injector();
injector.getInstance(IndexFieldDataService.class).setIndexService((new StubIndexService(injector.getInstance(MapperService.class))));
MapperService mapperService = indexService.mapperService();
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/query/mapping.json");
injector.getInstance(MapperService.class).merge("person", new CompressedString(mapping), true);
mapperService.merge("person", new CompressedString(mapping), true);
String childMapping = copyToStringFromClasspath("/org/elasticsearch/index/query/child-mapping.json");
injector.getInstance(MapperService.class).merge("child", new CompressedString(childMapping), true);
injector.getInstance(MapperService.class).documentMapper("person").parse(new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
mapperService.merge("child", new CompressedString(childMapping), true);
mapperService.documentMapper("person").parse(new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
queryParser = injector.getInstance(IndexQueryParserService.class);
}

View File

@ -33,7 +33,6 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.get.MultiGetRequest;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.compress.CompressedString;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.lucene.search.*;
import org.elasticsearch.common.lucene.search.function.BoostScoreFunction;
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
@ -42,7 +41,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.cache.filter.support.CacheKeyFilter;
import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
import org.elasticsearch.index.search.NumericRangeFieldDataFilter;
@ -51,8 +49,8 @@ import org.elasticsearch.index.search.geo.GeoPolygonFilter;
import org.elasticsearch.index.search.geo.InMemoryGeoBoundingBoxFilter;
import org.elasticsearch.index.search.morelikethis.MoreLikeThisFetchService;
import org.elasticsearch.index.search.morelikethis.MoreLikeThisFetchService.LikeText;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.elasticsearch.test.index.service.StubIndexService;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
@ -77,7 +75,6 @@ import static org.hamcrest.Matchers.*;
*/
public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
private Injector injector;
private IndexQueryParserService queryParser;
@Before
@ -86,14 +83,14 @@ public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
.put("index.cache.filter.type", "none")
.put("name", "SimpleIndexQueryParserTests")
.build();
injector = createIndex("test", settings).injector();
IndexService indexService = createIndex("test", settings);
MapperService mapperService = indexService.mapperService();
injector.getInstance(IndexFieldDataService.class).setIndexService((new StubIndexService(injector.getInstance(MapperService.class))));
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/query/mapping.json");
injector.getInstance(MapperService.class).merge("person", new CompressedString(mapping), true);
injector.getInstance(MapperService.class).documentMapper("person").parse(new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
mapperService.merge("person", new CompressedString(mapping), true);
mapperService.documentMapper("person").parse(new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
queryParser = injector.getInstance(IndexQueryParserService.class);
queryParser = indexService.queryParserService();
}
private IndexQueryParserService queryParser() throws IOException {

View File

@ -56,6 +56,7 @@ import java.io.IOException;
/**
* Test parsing and executing a template request.
*/
// NOTE: this can't be migrated to ElasticsearchSingleNodeTest because of the custom path.conf
public class TemplateQueryParserTest extends ElasticsearchTestCase {
private Injector injector;

View File

@ -19,34 +19,9 @@
package org.elasticsearch.index.query.guice;
import org.elasticsearch.cache.recycler.CacheRecyclerModule;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.inject.util.Providers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNameModule;
import org.elasticsearch.index.analysis.AnalysisModule;
import org.elasticsearch.index.cache.IndexCacheModule;
import org.elasticsearch.index.codec.CodecModule;
import org.elasticsearch.index.engine.IndexEngineModule;
import org.elasticsearch.index.query.IndexQueryParserModule;
import org.elasticsearch.index.query.IndexQueryParserService;
import org.elasticsearch.index.query.functionscore.FunctionScoreModule;
import org.elasticsearch.index.settings.IndexSettingsModule;
import org.elasticsearch.index.similarity.SimilarityModule;
import org.elasticsearch.indices.fielddata.breaker.NoneCircuitBreakerService;
import org.elasticsearch.indices.query.IndicesQueriesModule;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.indices.fielddata.breaker.CircuitBreakerService;
import org.elasticsearch.indices.query.IndicesQueriesModule;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.threadpool.ThreadPoolModule;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
@ -55,7 +30,7 @@ import static org.hamcrest.Matchers.equalTo;
/**
*
*/
public class IndexQueryParserModuleTests extends ElasticsearchTestCase {
public class IndexQueryParserModuleTests extends ElasticsearchSingleNodeTest {
@Test
public void testCustomInjection() {
@ -68,32 +43,7 @@ public class IndexQueryParserModuleTests extends ElasticsearchTestCase {
.put("name", "IndexQueryParserModuleTests")
.build();
Index index = new Index("test");
Injector injector = new ModulesBuilder().add(
new SettingsModule(settings),
new CacheRecyclerModule(settings),
new CodecModule(settings),
new ThreadPoolModule(settings),
new IndicesQueriesModule(),
new ScriptModule(settings),
new IndexSettingsModule(index, settings),
new IndexCacheModule(settings),
new AnalysisModule(settings),
new IndexEngineModule(settings),
new SimilarityModule(settings),
new IndexQueryParserModule(settings),
new IndexNameModule(index),
new FunctionScoreModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(ClusterService.class).toProvider(Providers.of((ClusterService) null));
bind(CircuitBreakerService.class).to(NoneCircuitBreakerService.class);
}
}
).createInjector();
IndexQueryParserService indexQueryParserService = injector.getInstance(IndexQueryParserService.class);
IndexQueryParserService indexQueryParserService = createIndex("test", settings).queryParserService();
MyJsonQueryParser myJsonQueryParser = (MyJsonQueryParser) indexQueryParserService.queryParser("my");
@ -103,7 +53,5 @@ public class IndexQueryParserModuleTests extends ElasticsearchTestCase {
MyJsonFilterParser myJsonFilterParser = (MyJsonFilterParser) indexQueryParserService.filterParser("my");
assertThat(myJsonFilterParser.names()[0], equalTo("my"));
assertThat(myJsonFilterParser.settings().get("param2"), equalTo("value2"));
injector.getInstance(ThreadPool.class).shutdownNow();
}
}

View File

@ -22,7 +22,6 @@ package org.elasticsearch.index.search;
import com.carrotsearch.hppc.DoubleOpenHashSet;
import com.carrotsearch.hppc.LongOpenHashSet;
import com.carrotsearch.hppc.ObjectOpenHashSet;
import com.google.common.collect.ImmutableSet;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.*;
@ -31,27 +30,22 @@ import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.Index;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.ContentPath;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.core.DoubleFieldMapper;
import org.elasticsearch.index.mapper.core.LongFieldMapper;
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.query.FilterParser;
import org.elasticsearch.index.query.IndexQueryParserService;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryParser;
import org.elasticsearch.indices.fielddata.breaker.CircuitBreakerService;
import org.elasticsearch.indices.fielddata.breaker.NoneCircuitBreakerService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCacheListener;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.index.service.StubIndexService;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -64,7 +58,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
/**
*/
public class FieldDataTermsFilterTests extends ElasticsearchTestCase {
public class FieldDataTermsFilterTests extends ElasticsearchSingleNodeTest {
protected QueryParseContext parseContext;
protected IndexFieldDataService ifdService;
@ -89,20 +83,11 @@ public class FieldDataTermsFilterTests extends ElasticsearchTestCase {
.build(new Mapper.BuilderContext(null, new ContentPath(1)));
// create index and fielddata service
Index index = new Index("test");
CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(
ImmutableSettings.Builder.EMPTY_SETTINGS,
new IndicesFieldDataCacheListener(circuitBreakerService)
);
ifdService = new IndexFieldDataService(index, ImmutableSettings.builder().put("index.fielddata.cache", "none").build(), indicesFieldDataCache, circuitBreakerService, new IndicesFieldDataCacheListener(circuitBreakerService));
MapperService mapperService = MapperTestUtils.newMapperService(ifdService.index(), ImmutableSettings.Builder.EMPTY_SETTINGS);
ifdService.setIndexService(new StubIndexService(mapperService));
IndexQueryParserService parserService = new IndexQueryParserService(
index, ImmutableSettings.EMPTY, new IndicesQueriesRegistry(ImmutableSettings.EMPTY, ImmutableSet.<QueryParser>of(), ImmutableSet.<FilterParser>of()),
null, null, null, mapperService, null, ifdService, null, null, null, null
);
parseContext = new QueryParseContext(index, parserService);
Settings settings = ImmutableSettings.builder().put("index.fielddata.cache", "none").build();
IndexService indexService = createIndex("test", settings);
ifdService = indexService.injector().getInstance(IndexFieldDataService.class);
IndexQueryParserService parserService = indexService.queryParserService();
parseContext = new QueryParseContext(indexService.index(), parserService);
writer = new IndexWriter(new RAMDirectory(),
new IndexWriterConfig(Lucene.VERSION, new StandardAnalyzer(Lucene.VERSION)));

View File

@ -0,0 +1,91 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.search.child;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.common.compress.CompressedString;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ElasticsearchSingleNodeLuceneTestCase;
import org.hamcrest.Description;
import org.hamcrest.StringDescription;
import org.junit.Ignore;
import java.io.IOException;
import static org.hamcrest.Matchers.equalTo;
@Ignore
public abstract class AbstractChildTests extends ElasticsearchSingleNodeLuceneTestCase {
static SearchContext createSearchContext(String indexName, String parentType, String childType) throws IOException {
IndexService indexService = createIndex(indexName);
MapperService mapperService = indexService.mapperService();
mapperService.merge(childType, new CompressedString(PutMappingRequest.buildFromSimplifiedDef(childType, "_parent", "type=" + parentType).string()), true);
return createSearchContext(indexService);
}
static void assertBitSet(FixedBitSet actual, FixedBitSet expected, IndexSearcher searcher) throws IOException {
if (!actual.equals(expected)) {
Description description = new StringDescription();
description.appendText(reason(actual, expected, searcher));
description.appendText("\nExpected: ");
description.appendValue(expected);
description.appendText("\n got: ");
description.appendValue(actual);
description.appendText("\n");
throw new java.lang.AssertionError(description.toString());
}
}
static String reason(FixedBitSet actual, FixedBitSet expected, IndexSearcher indexSearcher) throws IOException {
StringBuilder builder = new StringBuilder();
builder.append("expected cardinality:").append(expected.cardinality()).append('\n');
DocIdSetIterator iterator = expected.iterator();
for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
builder.append("Expected doc[").append(doc).append("] with id value ").append(indexSearcher.doc(doc).get(UidFieldMapper.NAME)).append('\n');
}
builder.append("actual cardinality: ").append(actual.cardinality()).append('\n');
iterator = actual.iterator();
for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
builder.append("Actual doc[").append(doc).append("] with id value ").append(indexSearcher.doc(doc).get(UidFieldMapper.NAME)).append('\n');
}
return builder.toString();
}
static void assertTopDocs(TopDocs actual, TopDocs expected) {
assertThat("actual.totalHits != expected.totalHits", actual.totalHits, equalTo(expected.totalHits));
assertThat("actual.getMaxScore() != expected.getMaxScore()", actual.getMaxScore(), equalTo(expected.getMaxScore()));
assertThat("actual.scoreDocs.length != expected.scoreDocs.length", actual.scoreDocs.length, equalTo(actual.scoreDocs.length));
for (int i = 0; i < actual.scoreDocs.length; i++) {
ScoreDoc actualHit = actual.scoreDocs[i];
ScoreDoc expectedHit = expected.scoreDocs[i];
assertThat("actualHit.doc != expectedHit.doc", actualHit.doc, equalTo(expectedHit.doc));
assertThat("actualHit.score != expectedHit.score", actualHit.score, equalTo(expectedHit.score));
}
}
}

View File

@ -30,40 +30,20 @@ import org.apache.lucene.search.*;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.cache.recycler.CacheRecycler;
import org.elasticsearch.cache.recycler.PageCacheRecycler;
import org.elasticsearch.common.compress.CompressedString;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.lucene.search.NotFilter;
import org.elasticsearch.common.lucene.search.XConstantScoreQuery;
import org.elasticsearch.common.lucene.search.XFilteredQuery;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.cache.filter.weighted.WeightedFilterCache;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.MapperTestUtils;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.internal.ParentFieldMapper;
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.index.search.nested.NonNestedDocsFilter;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.indices.cache.filter.IndicesFilterCache;
import org.elasticsearch.indices.fielddata.breaker.NoneCircuitBreakerService;
import org.elasticsearch.node.settings.NodeSettingsService;
import org.elasticsearch.search.internal.ContextIndexSearcher;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ElasticsearchLuceneTestCase;
import org.elasticsearch.test.index.service.StubIndexService;
import org.elasticsearch.threadpool.ThreadPool;
import org.hamcrest.Description;
import org.hamcrest.StringDescription;
import org.elasticsearch.test.TestSearchContext;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -75,7 +55,7 @@ import java.util.TreeSet;
import static org.hamcrest.Matchers.equalTo;
public class ChildrenConstantScoreQueryTests extends ElasticsearchLuceneTestCase {
public class ChildrenConstantScoreQueryTests extends AbstractChildTests {
@BeforeClass
public static void before() throws IOException {
@ -321,54 +301,4 @@ public class ChildrenConstantScoreQueryTests extends ElasticsearchLuceneTestCase
directory.close();
}
static void assertBitSet(FixedBitSet actual, FixedBitSet expected, IndexSearcher searcher) throws IOException {
if (!actual.equals(expected)) {
Description description = new StringDescription();
description.appendText(reason(actual, expected, searcher));
description.appendText("\nExpected: ");
description.appendValue(expected);
description.appendText("\n got: ");
description.appendValue(actual);
description.appendText("\n");
throw new java.lang.AssertionError(description.toString());
}
}
static String reason(FixedBitSet actual, FixedBitSet expected, IndexSearcher indexSearcher) throws IOException {
StringBuilder builder = new StringBuilder();
builder.append("expected cardinality:").append(expected.cardinality()).append('\n');
DocIdSetIterator iterator = expected.iterator();
for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
builder.append("Expected doc[").append(doc).append("] with id value ").append(indexSearcher.doc(doc).get(UidFieldMapper.NAME)).append('\n');
}
builder.append("actual cardinality: ").append(actual.cardinality()).append('\n');
iterator = actual.iterator();
for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
builder.append("Actual doc[").append(doc).append("] with id value ").append(indexSearcher.doc(doc).get(UidFieldMapper.NAME)).append('\n');
}
return builder.toString();
}
static SearchContext createSearchContext(String indexName, String parentType, String childType) throws IOException {
final Index index = new Index(indexName);
final CacheRecycler cacheRecycler = new CacheRecycler(ImmutableSettings.EMPTY);
ThreadPool threadPool = new ThreadPool("ChildrenConstantScoreQueryTests");
final PageCacheRecycler pageCacheRecycler = new PageCacheRecycler(ImmutableSettings.EMPTY, threadPool);
final BigArrays bigArrays = new BigArrays(ImmutableSettings.EMPTY, pageCacheRecycler);
Settings settings = ImmutableSettings.EMPTY;
MapperService mapperService = MapperTestUtils.newMapperService(index, settings);
IndexFieldDataService indexFieldDataService = new IndexFieldDataService(index, new NoneCircuitBreakerService());
final IndexService indexService = new StubIndexService(mapperService);
indexFieldDataService.setIndexService(indexService);
// Id_cache is now registered as document type listener, so we can add mappings.
mapperService.merge(
childType, new CompressedString(PutMappingRequest.buildFromSimplifiedDef(childType, "_parent", "type=" + parentType).string()), true
);
NodeSettingsService nodeSettingsService = new NodeSettingsService(settings);
IndicesFilterCache indicesFilterCache = new IndicesFilterCache(settings, threadPool, cacheRecycler, nodeSettingsService);
WeightedFilterCache filterCache = new WeightedFilterCache(index, settings, indicesFilterCache);
return new TestSearchContext(threadPool, cacheRecycler, pageCacheRecycler, bigArrays, indexService, filterCache, indexFieldDataService);
}
}

View File

@ -44,7 +44,7 @@ import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.index.search.nested.NonNestedDocsFilter;
import org.elasticsearch.search.internal.ContextIndexSearcher;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ElasticsearchLuceneTestCase;
import org.elasticsearch.test.TestSearchContext;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -55,11 +55,7 @@ import java.util.NavigableMap;
import java.util.Random;
import java.util.TreeMap;
import static org.elasticsearch.index.search.child.ChildrenConstantScoreQueryTests.assertBitSet;
import static org.elasticsearch.index.search.child.ChildrenConstantScoreQueryTests.createSearchContext;
import static org.hamcrest.Matchers.equalTo;
public class ChildrenQueryTests extends ElasticsearchLuceneTestCase {
public class ChildrenQueryTests extends AbstractChildTests {
@BeforeClass
public static void before() throws IOException {
@ -276,16 +272,4 @@ public class ChildrenQueryTests extends ElasticsearchLuceneTestCase {
directory.close();
}
static void assertTopDocs(TopDocs actual, TopDocs expected) {
assertThat("actual.totalHits != expected.totalHits", actual.totalHits, equalTo(expected.totalHits));
assertThat("actual.getMaxScore() != expected.getMaxScore()", actual.getMaxScore(), equalTo(expected.getMaxScore()));
assertThat("actual.scoreDocs.length != expected.scoreDocs.length", actual.scoreDocs.length, equalTo(actual.scoreDocs.length));
for (int i = 0; i < actual.scoreDocs.length; i++) {
ScoreDoc actualHit = actual.scoreDocs[i];
ScoreDoc expectedHit = expected.scoreDocs[i];
assertThat("actualHit.doc != expectedHit.doc", actualHit.doc, equalTo(expectedHit.doc));
assertThat("actualHit.score != expectedHit.score", actualHit.score, equalTo(expectedHit.score));
}
}
}

View File

@ -42,7 +42,7 @@ import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.search.internal.ContextIndexSearcher;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ElasticsearchLuceneTestCase;
import org.elasticsearch.test.TestSearchContext;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -52,12 +52,9 @@ import java.util.NavigableSet;
import java.util.Random;
import java.util.TreeSet;
import static org.elasticsearch.index.search.child.ChildrenConstantScoreQueryTests.assertBitSet;
import static org.elasticsearch.index.search.child.ChildrenConstantScoreQueryTests.createSearchContext;
/**
*/
public class ParentConstantScoreQueryTests extends ElasticsearchLuceneTestCase {
public class ParentConstantScoreQueryTests extends AbstractChildTests {
@BeforeClass
public static void before() throws IOException {

View File

@ -42,7 +42,7 @@ import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.search.internal.ContextIndexSearcher;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ElasticsearchLuceneTestCase;
import org.elasticsearch.test.TestSearchContext;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -53,11 +53,7 @@ import java.util.NavigableMap;
import java.util.Random;
import java.util.TreeMap;
import static org.elasticsearch.index.search.child.ChildrenConstantScoreQueryTests.assertBitSet;
import static org.elasticsearch.index.search.child.ChildrenConstantScoreQueryTests.createSearchContext;
import static org.elasticsearch.index.search.child.ChildrenQueryTests.assertTopDocs;
public class ParentQueryTests extends ElasticsearchLuceneTestCase {
public class ParentQueryTests extends AbstractChildTests {
@BeforeClass
public static void before() throws IOException {

View File

@ -23,30 +23,25 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryUtils;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData;
import org.elasticsearch.index.mapper.internal.ParentFieldMapper;
import org.elasticsearch.index.search.nested.NonNestedDocsFilter;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ElasticsearchLuceneTestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import static org.elasticsearch.index.search.child.ChildrenConstantScoreQueryTests.createSearchContext;
/**
*/
public class TopChildrenQueryTests extends ElasticsearchLuceneTestCase {
public class TopChildrenQueryTests extends AbstractChildTests {
@BeforeClass
public static void before() throws IOException {
forceDefaultCodec();
SearchContext.setCurrent(createSearchContext("test", "parent", "child"));
SearchContext.setCurrent(ChildrenConstantScoreQueryTests.createSearchContext("test", "parent", "child"));
}
@AfterClass

View File

@ -28,18 +28,20 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.search.child.TestSearchContext;
import org.elasticsearch.search.SearchShardTarget;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.significant.heuristics.*;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.TestSearchContext;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import static org.hamcrest.Matchers.*;

View File

@ -0,0 +1,60 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.search.internal.SearchContext;
import org.junit.After;
import org.junit.Ignore;
/**
* Like {@link ElasticsearchSingleNodeTest} but for tests that need to extend
* {@link ElasticsearchLuceneTestCase}.
*/
@Ignore
public abstract class ElasticsearchSingleNodeLuceneTestCase extends ElasticsearchLuceneTestCase {
@After
public void cleanup() {
ElasticsearchSingleNodeTest.cleanup();
}
/**
* Create a new index on the singleton node with empty index settings.
*/
protected static IndexService createIndex(String index) {
return ElasticsearchSingleNodeTest.createIndex(index);
}
/**
* Create a new index on the singleton node with the provided index settings.
*/
protected static IndexService createIndex(String index, Settings settings) {
return ElasticsearchSingleNodeTest.createIndex(index, settings);
}
/**
* Create a new search context.
*/
protected static SearchContext createSearchContext(IndexService indexService) {
return ElasticsearchSingleNodeTest.createSearchContext(indexService);
}
}

View File

@ -20,6 +20,8 @@ package org.elasticsearch.test;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cache.recycler.CacheRecycler;
import org.elasticsearch.cache.recycler.PageCacheRecycler;
import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.metadata.IndexMetaData;
@ -28,12 +30,15 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.threadpool.ThreadPool;
import org.junit.After;
import org.junit.Ignore;
@ -49,8 +54,8 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
private static final Node node = newNode();
public static void cleanup() {
node.client().admin().indices().prepareDelete("*").get();
static void cleanup() {
assertAcked(node.client().admin().indices().prepareDelete("*").get());
MetaData metaData = node.client().admin().cluster().prepareState().get().getState().getMetaData();
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(),
metaData.persistentSettings().getAsMap().size(), equalTo(0));
@ -82,28 +87,28 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
/**
* Return a reference to the singleton node.
*/
public static Node node() {
protected static Node node() {
return node;
}
/**
* Get an instance for a particular class using the injector of the singleton node.
*/
public static <T> T getInstanceFromNode(Class<T> clazz) {
protected static <T> T getInstanceFromNode(Class<T> clazz) {
return ((InternalNode) node).injector().getInstance(clazz);
}
/**
* Create a new index on the singleton node with empty index settings.
*/
public static IndexService createIndex(String index) {
protected static IndexService createIndex(String index) {
return createIndex(index, ImmutableSettings.EMPTY);
}
/**
* Create a new index on the singleton node with the provided index settings.
*/
public static IndexService createIndex(String index, Settings settings) {
protected static IndexService createIndex(String index, Settings settings) {
assertAcked(node.client().admin().indices().prepareCreate(index).setSettings(settings).get());
// Wait for the index to be allocated so that cluster state updates don't override
// changes that would have been done locally
@ -115,5 +120,15 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
return instanceFromNode.indexServiceSafe(index);
}
/**
* Create a new search context.
*/
protected static SearchContext createSearchContext(IndexService indexService) {
BigArrays bigArrays = indexService.injector().getInstance(BigArrays.class);
ThreadPool threadPool = indexService.injector().getInstance(ThreadPool.class);
CacheRecycler cacheRecycler = indexService.injector().getInstance(CacheRecycler.class);
PageCacheRecycler pageCacheRecycler = indexService.injector().getInstance(PageCacheRecycler.class);
return new TestSearchContext(threadPool, cacheRecycler, pageCacheRecycler, bigArrays, indexService, indexService.cache().filter(), indexService.fieldData());
}
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.search.child;
package org.elasticsearch.test;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
@ -63,8 +63,6 @@ import org.elasticsearch.search.suggest.SuggestionSearchContext;
import org.elasticsearch.threadpool.ThreadPool;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
public class TestSearchContext extends SearchContext {
@ -75,7 +73,6 @@ public class TestSearchContext extends SearchContext {
final FilterCache filterCache;
final IndexFieldDataService indexFieldDataService;
final ThreadPool threadPool;
private final AtomicBoolean closed = new AtomicBoolean(false);
ContextIndexSearcher searcher;
int size;
@ -281,7 +278,7 @@ public class TestSearchContext extends SearchContext {
return searcher;
}
void setSearcher(ContextIndexSearcher searcher) {
public void setSearcher(ContextIndexSearcher searcher) {
this.searcher = searcher;
}
@ -573,7 +570,7 @@ public class TestSearchContext extends SearchContext {
}
@Override
public FieldMapper smartNameFieldMapper(String name) {
public FieldMapper<?> smartNameFieldMapper(String name) {
return null;
}
@ -584,14 +581,6 @@ public class TestSearchContext extends SearchContext {
@Override
public void doClose() throws ElasticsearchException {
if (closed.compareAndSet(false, true)) {
threadPool.shutdownNow();
try {
threadPool.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.interrupted();
}
}
}
@Override

View File

@ -1,172 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.index.service;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexShardMissingException;
import org.elasticsearch.index.aliases.IndexAliasesService;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.cache.IndexCache;
import org.elasticsearch.index.engine.IndexEngine;
import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.gateway.IndexGateway;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.IndexQueryParserService;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.index.settings.IndexSettingsService;
import org.elasticsearch.index.shard.service.IndexShard;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.store.IndexStore;
import java.util.Iterator;
/**
*/
public class StubIndexService implements IndexService {
private final MapperService mapperService;
public StubIndexService(MapperService mapperService) {
this.mapperService = mapperService;
}
@Override
public Injector injector() {
return null;
}
@Override
public IndexGateway gateway() {
return null;
}
@Override
public IndexCache cache() {
return null;
}
@Override
public IndexFieldDataService fieldData() {
return null;
}
@Override
public IndexSettingsService settingsService() {
return null;
}
@Override
public AnalysisService analysisService() {
return null;
}
@Override
public MapperService mapperService() {
return mapperService;
}
@Override
public IndexQueryParserService queryParserService() {
return null;
}
@Override
public SimilarityService similarityService() {
return null;
}
@Override
public IndexAliasesService aliasesService() {
return null;
}
@Override
public IndexEngine engine() {
return null;
}
@Override
public IndexStore store() {
return null;
}
@Override
public IndexShard createShard(int sShardId) throws ElasticsearchException {
return null;
}
@Override
public void removeShard(int shardId, String reason) throws ElasticsearchException {
}
@Override
public int numberOfShards() {
return 0;
}
@Override
public ImmutableSet<Integer> shardIds() {
return null;
}
@Override
public boolean hasShard(int shardId) {
return false;
}
@Override
public IndexShard shard(int shardId) {
return null;
}
@Override
public IndexShard shardSafe(int shardId) throws IndexShardMissingException {
return null;
}
@Override
public Injector shardInjector(int shardId) {
return null;
}
@Override
public Injector shardInjectorSafe(int shardId) throws IndexShardMissingException {
return null;
}
@Override
public String indexUUID() {
return IndexMetaData.INDEX_UUID_NA_VALUE;
}
@Override
public Index index() {
return null;
}
@Override
public Iterator<IndexShard> iterator() {
return null;
}
}