|
10 | 10 |
|
11 | 11 | import org.elasticsearch.cluster.metadata.IndexMetadata;
|
12 | 12 | import org.elasticsearch.common.settings.Settings;
|
| 13 | +import org.elasticsearch.common.time.DateUtils; |
| 14 | +import org.elasticsearch.index.mapper.DataStreamTimestampFieldMapper; |
| 15 | +import org.elasticsearch.index.mapper.DateFieldMapper; |
| 16 | +import org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType; |
| 17 | +import org.elasticsearch.index.mapper.DocumentMapper; |
| 18 | +import org.elasticsearch.index.mapper.MappedFieldType; |
| 19 | +import org.elasticsearch.index.mapper.Mapper; |
| 20 | +import org.elasticsearch.index.mapper.MapperParsingException; |
13 | 21 | import org.elasticsearch.index.mapper.MapperServiceTestCase;
|
14 | 22 | import org.elasticsearch.script.Script;
|
15 | 23 | import org.elasticsearch.script.ScriptContext;
|
|
25 | 33 | public class TimeSeriesModeTests extends MapperServiceTestCase {
|
26 | 34 |
|
27 | 35 | public void testConfigureIndex() {
|
28 |
| - Settings s = Settings.builder() |
29 |
| - .put(IndexSettings.MODE.getKey(), "time_series") |
30 |
| - .put(IndexMetadata.INDEX_ROUTING_PATH.getKey(), "foo") |
31 |
| - .build(); |
| 36 | + Settings s = getSettings(); |
32 | 37 | assertSame(IndexMode.TIME_SERIES, IndexSettings.MODE.get(s));
|
33 | 38 | }
|
34 | 39 |
|
35 | 40 | public void testPartitioned() {
|
36 |
| - Settings s = Settings.builder() |
37 |
| - .put(IndexMetadata.INDEX_ROUTING_PARTITION_SIZE_SETTING.getKey(), 2) |
38 |
| - .put(IndexSettings.MODE.getKey(), "time_series") |
39 |
| - .build(); |
| 41 | + Settings s = Settings.builder().put(getSettings()).put(IndexMetadata.INDEX_ROUTING_PARTITION_SIZE_SETTING.getKey(), 2).build(); |
40 | 42 | Exception e = expectThrows(IllegalArgumentException.class, () -> IndexSettings.MODE.get(s));
|
41 | 43 | assertThat(e.getMessage(), equalTo("[index.mode=time_series] is incompatible with [index.routing_partition_size]"));
|
42 | 44 | }
|
43 | 45 |
|
44 | 46 | public void testSortField() {
|
45 |
| - Settings s = Settings.builder() |
46 |
| - .put(IndexSortConfig.INDEX_SORT_FIELD_SETTING.getKey(), "a") |
47 |
| - .put(IndexSettings.MODE.getKey(), "time_series") |
48 |
| - .build(); |
| 47 | + Settings s = Settings.builder().put(getSettings()).put(IndexSortConfig.INDEX_SORT_FIELD_SETTING.getKey(), "a").build(); |
49 | 48 | Exception e = expectThrows(IllegalArgumentException.class, () -> IndexSettings.MODE.get(s));
|
50 | 49 | assertThat(e.getMessage(), equalTo("[index.mode=time_series] is incompatible with [index.sort.field]"));
|
51 | 50 | }
|
52 | 51 |
|
53 | 52 | public void testSortMode() {
|
54 |
| - Settings s = Settings.builder() |
| 53 | + Settings s = Settings.builder().put(getSettings()) |
55 | 54 | .put(IndexSortConfig.INDEX_SORT_MISSING_SETTING.getKey(), "_last")
|
56 |
| - .put(IndexSettings.MODE.getKey(), "time_series") |
57 | 55 | .build();
|
58 | 56 | Exception e = expectThrows(IllegalArgumentException.class, () -> IndexSettings.MODE.get(s));
|
59 | 57 | assertThat(e.getMessage(), equalTo("[index.mode=time_series] is incompatible with [index.sort.missing]"));
|
60 | 58 | }
|
61 | 59 |
|
62 | 60 | public void testSortOrder() {
|
63 |
| - Settings s = Settings.builder() |
| 61 | + Settings s = Settings.builder().put(getSettings()) |
64 | 62 | .put(IndexSortConfig.INDEX_SORT_ORDER_SETTING.getKey(), "desc")
|
65 |
| - .put(IndexSettings.MODE.getKey(), "time_series") |
66 | 63 | .build();
|
67 | 64 | Exception e = expectThrows(IllegalArgumentException.class, () -> IndexSettings.MODE.get(s));
|
68 | 65 | assertThat(e.getMessage(), equalTo("[index.mode=time_series] is incompatible with [index.sort.order]"));
|
@@ -243,4 +240,21 @@ public LeafFactory newFactory(String fieldName, Map<String, Object> params, Sear
|
243 | 240 | }
|
244 | 241 | return super.compileScript(script, context);
|
245 | 242 | }
|
| 243 | + |
| 244 | + private Settings getSettings() { |
| 245 | + return getSettings(randomAlphaOfLength(5), 1, DateUtils.MAX_MILLIS_BEFORE_9999 - 1); |
| 246 | + } |
| 247 | + |
| 248 | + private Settings getSettings(String routingPath) { |
| 249 | + return getSettings(routingPath, 1, DateUtils.MAX_MILLIS_BEFORE_9999 - 1); |
| 250 | + } |
| 251 | + |
| 252 | + private Settings getSettings(String routingPath, long startTime, long endTime) { |
| 253 | + return Settings.builder() |
| 254 | + .put(IndexSettings.MODE.getKey(), "time_series") |
| 255 | + .put(IndexMetadata.INDEX_ROUTING_PATH.getKey(), routingPath) |
| 256 | + .put(IndexSettings.TIME_SERIES_START_TIME.getKey(), startTime) |
| 257 | + .put(IndexSettings.TIME_SERIES_END_TIME.getKey(), endTime) |
| 258 | + .build(); |
| 259 | + } |
246 | 260 | }
|
0 commit comments