Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Tests: AnalysisService constructor signature change
Browse files Browse the repository at this point in the history
Due to this [change](elastic/elasticsearch#8018), we need to fix our tests for elasticsearch 1.4.0 and above.

Closes #87.
  • Loading branch information
dadoonet committed Oct 15, 2014
1 parent d743fe9 commit b3b0d34
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -31,7 +31,7 @@
</parent>

<properties>
<elasticsearch.version>1.4.0.Beta1</elasticsearch.version>
<elasticsearch.version>1.4.0-SNAPSHOT</elasticsearch.version>
<lucene.maven.version>4.10.1</lucene.maven.version>
<lucene.version>4.10.1</lucene.version>
<poi.version>3.10.1</poi.version>
Expand Down
Expand Up @@ -19,9 +19,6 @@

package org.elasticsearch.index.mapper.xcontent;

import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
Expand All @@ -42,7 +39,7 @@ public class DateAttachmentMapperTests extends ElasticsearchTestCase {

@Before
public void setupMapperParser() {
mapperParser = new DocumentMapperParser(new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null, null);
mapperParser = MapperTestUtils.newMapperParser();
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
}

Expand Down
Expand Up @@ -21,8 +21,6 @@

import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.MapperParsingException;
Expand All @@ -47,7 +45,7 @@ public class EncryptedDocMapperTest extends ElasticsearchTestCase {

@Test
public void testMultipleDocsEncryptedLast() throws IOException {
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null, null);
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());

String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
Expand Down Expand Up @@ -80,7 +78,7 @@ public void testMultipleDocsEncryptedLast() throws IOException {

@Test
public void testMultipleDocsEncryptedFirst() throws IOException {
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null, null);
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());

String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
Expand Down Expand Up @@ -113,9 +111,7 @@ public void testMultipleDocsEncryptedFirst() throws IOException {

@Test(expected = MapperParsingException.class)
public void testMultipleDocsEncryptedNotIgnoringErrors() throws IOException {
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"),
ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build(),
new AnalysisService(new Index("test")), null, null, null, null);
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build());
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());

String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
Expand Down
Expand Up @@ -21,8 +21,6 @@

import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.ParseContext;
Expand Down Expand Up @@ -53,9 +51,8 @@ public void setupMapperParser() throws IOException {
}

public void setupMapperParser(boolean langDetect) throws IOException {
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"),
ImmutableSettings.settingsBuilder().put("index.mapping.attachment.detect_language", langDetect).build(),
new AnalysisService(new Index("test")), null, null, null, null);
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(
ImmutableSettings.settingsBuilder().put("index.mapping.attachment.detect_language", langDetect).build());
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/language/language-mapping.json");
docMapper = mapperParser.parse(mapping);
Expand Down
Expand Up @@ -19,6 +19,8 @@

package org.elasticsearch.index.mapper.xcontent;

import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.ImmutableSettings;
Expand All @@ -33,6 +35,7 @@
import org.elasticsearch.index.codec.docvaluesformat.DocValuesFormatService;
import org.elasticsearch.index.codec.postingsformat.PostingsFormatService;
import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.settings.IndexSettingsModule;
import org.elasticsearch.index.similarity.SimilarityLookupService;
Expand All @@ -46,7 +49,9 @@
public class MapperTestUtils {

public static MapperService newMapperService() {
return newMapperService(new Index("test"), ImmutableSettings.Builder.EMPTY_SETTINGS);
return newMapperService(new Index("test"), ImmutableSettings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.build());
}

public static MapperService newMapperService(Index index, Settings indexSettings) {
Expand All @@ -58,14 +63,17 @@ circuitBreakerService, new IndicesFieldDataCacheListener(circuitBreakerService))
}

public static AnalysisService newAnalysisService() {
return newAnalysisService(ImmutableSettings.Builder.EMPTY_SETTINGS);
return newAnalysisService(ImmutableSettings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.build());
}

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();
Index index = new Index("test");
Injector injector = new ModulesBuilder().add(
new IndexSettingsModule(new Index("test"), indexSettings),
new IndexNameModule(new Index("test")),
new IndexSettingsModule(index, indexSettings),
new IndexNameModule(index),
new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector);

return injector.getInstance(AnalysisService.class);
Expand All @@ -74,4 +82,16 @@ public static AnalysisService newAnalysisService(Settings indexSettings) {
public static SimilarityLookupService newSimilarityLookupService() {
return new SimilarityLookupService(new Index("test"), ImmutableSettings.Builder.EMPTY_SETTINGS);
}

public static DocumentMapperParser newMapperParser() {
return newMapperParser(ImmutableSettings.Builder.EMPTY_SETTINGS);
}

public static DocumentMapperParser newMapperParser(Settings settings) {
Settings forcedSettings = ImmutableSettings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put(settings)
.build();
return new DocumentMapperParser(new Index("test"), forcedSettings, MapperTestUtils.newAnalysisService(forcedSettings), null, null, null, null);
}
}
Expand Up @@ -22,8 +22,6 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.MapperParsingException;
Expand All @@ -45,7 +43,7 @@
public class MetadataMapperTest extends ElasticsearchTestCase {

protected void checkMeta(String filename, Settings settings, Long expectedDate, Long expectedLength) throws IOException {
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"), settings, new AnalysisService(new Index("test")), null, null, null, null);
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(settings);
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());

String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
Expand Down
Expand Up @@ -20,10 +20,7 @@
package org.elasticsearch.index.mapper.xcontent;

import org.elasticsearch.common.Base64;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.MapperService;
Expand All @@ -47,7 +44,7 @@ public class MultifieldAttachmentMapperTests extends ElasticsearchTestCase {

@Before
public void setupMapperParser() {
mapperParser = new DocumentMapperParser(new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null, null);
mapperParser = MapperTestUtils.newMapperParser();
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
}

Expand Down
Expand Up @@ -20,9 +20,6 @@
package org.elasticsearch.index.mapper.xcontent;

import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.ParseContext;
Expand All @@ -46,7 +43,7 @@ public class SimpleAttachmentMapperTests extends ElasticsearchTestCase {

@Before
public void setupMapperParser() {
mapperParser = new DocumentMapperParser(new Index("test"), ImmutableSettings.EMPTY, new AnalysisService(new Index("test")), null, null, null, null);
mapperParser = MapperTestUtils.newMapperParser();
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
}

Expand Down

0 comments on commit b3b0d34

Please sign in to comment.