|
25 | 25 | import org.elasticsearch.Version; |
26 | 26 | import org.elasticsearch.cluster.metadata.IndexMetaData; |
27 | 27 | import org.elasticsearch.common.UUIDs; |
| 28 | +import org.elasticsearch.common.breaker.CircuitBreaker; |
| 29 | +import org.elasticsearch.common.breaker.NoopCircuitBreaker; |
28 | 30 | import org.elasticsearch.common.settings.Settings; |
29 | 31 | import org.elasticsearch.index.IndexSettings; |
| 32 | +import org.elasticsearch.index.fielddata.IndexFieldData; |
| 33 | +import org.elasticsearch.index.fielddata.IndexFieldDataCache; |
30 | 34 | import org.elasticsearch.index.mapper.MappedFieldType; |
31 | 35 | import org.elasticsearch.index.mapper.UidFieldMapper; |
32 | 36 | import org.elasticsearch.index.query.QueryShardContext; |
| 37 | +import org.elasticsearch.indices.breaker.CircuitBreakerService; |
| 38 | +import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; |
33 | 39 | import org.mockito.Mockito; |
34 | 40 |
|
| 41 | +import java.io.IOException; |
35 | 42 | import java.util.Collection; |
36 | 43 | import java.util.Collections; |
37 | 44 |
|
| 45 | +import static org.mockito.Matchers.any; |
| 46 | + |
38 | 47 | public class UidFieldTypeTests extends FieldTypeTestCase { |
39 | 48 | @Override |
40 | 49 | protected MappedFieldType createDefaultFieldType() { |
@@ -132,4 +141,35 @@ public void testTermsQuery() throws Exception { |
132 | 141 | query = ft.termQuery("type2#id", context); |
133 | 142 | assertEquals(new TermInSetQuery("_id"), query); |
134 | 143 | } |
| 144 | + |
| 145 | + public void testIsAggregatable() { |
| 146 | + Settings indexSettings = Settings.builder() |
| 147 | + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) |
| 148 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 149 | + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) |
| 150 | + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) |
| 151 | + .build(); |
| 152 | + IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build(); |
| 153 | + IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY); |
| 154 | + MappedFieldType ft = UidFieldMapper.defaultFieldType(mockSettings); |
| 155 | + assertTrue(ft.isAggregatable()); |
| 156 | + } |
| 157 | + |
| 158 | + public void testFieldDataDeprecation() { |
| 159 | + Settings indexSettings = Settings.builder() |
| 160 | + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) |
| 161 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 162 | + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) |
| 163 | + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) |
| 164 | + .build(); |
| 165 | + IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build(); |
| 166 | + IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY); |
| 167 | + MappedFieldType ft = UidFieldMapper.defaultFieldType(mockSettings); |
| 168 | + IndexFieldData.Builder builder = ft.fielddataBuilder(""); |
| 169 | + MapperService mockMapper = Mockito.mock(MapperService.class); |
| 170 | + Mockito.when(mockMapper.fullName(any())).thenReturn(new IdFieldMapper.IdFieldType()); |
| 171 | + Mockito.when(mockMapper.types()).thenReturn(Collections.singleton("doc")); |
| 172 | + builder.build(mockSettings, ft, null, new NoneCircuitBreakerService(), mockMapper); |
| 173 | + assertWarnings("Fielddata access on the _uid field is deprecated, use _id instead"); |
| 174 | + } |
135 | 175 | } |
0 commit comments