Add unit test for MetaDataMappingService with typeless put mapping. (#40578) (#40720)

This is currently only tested via REST tests.

Closes #37450
This commit is contained in:
Adrien Grand 2019-04-04 10:07:55 +02:00 committed by GitHub
parent 4296ff2fd1
commit f5f5c3e429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.InternalSettingsPlugin;
@ -114,4 +115,23 @@ public class MetaDataMappingServiceTests extends ESSingleNodeTestCase {
assertThat(result.resultingState.metaData().index("test").getMappingVersion(), equalTo(previousVersion));
}
public void testMappingUpdateAccepts_docAsType() throws Exception {
final IndexService indexService = createIndex("test",
client().admin().indices().prepareCreate("test").addMapping("my_type"));
final MetaDataMappingService mappingService = getInstanceFromNode(MetaDataMappingService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest()
.type(MapperService.SINGLE_MAPPING_NAME);
request.indices(new Index[] {indexService.index()});
request.source("{ \"properties\": { \"foo\": { \"type\": \"keyword\" } }}");
final ClusterStateTaskExecutor.ClusterTasksResult<PutMappingClusterStateUpdateRequest> result =
mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request));
assertThat(result.executionResults.size(), equalTo(1));
assertTrue(result.executionResults.values().iterator().next().isSuccess());
MappingMetaData mappingMetaData = result.resultingState.metaData().index("test").mapping();
assertEquals("my_type", mappingMetaData.type());
assertEquals(Collections.singletonMap("properties",
Collections.singletonMap("foo",
Collections.singletonMap("type", "keyword"))), mappingMetaData.sourceAsMap());
}
}