|
47 | 47 | import java.util.stream.Collectors;
|
48 | 48 |
|
49 | 49 | import static org.elasticsearch.cluster.DataStreamTestHelper.createTimestampField;
|
| 50 | +import static org.hamcrest.Matchers.arrayContaining; |
50 | 51 | import static org.hamcrest.Matchers.equalTo;
|
51 | 52 | import static org.hamcrest.Matchers.is;
|
52 | 53 | import static org.hamcrest.core.IsNull.notNullValue;
|
@@ -169,6 +170,29 @@ public void testResolveWithMultipleNames() {
|
169 | 170 | validateDataStreams(dataStreams, "logs-mysql-test");
|
170 | 171 | }
|
171 | 172 |
|
| 173 | + public void testResolvePreservesBackingIndexOrdering() { |
| 174 | + Metadata.Builder builder = Metadata.builder(); |
| 175 | + String dataStreamName = "my-data-stream"; |
| 176 | + String[] names = {"not-in-order-2", "not-in-order-1", DataStream.getDefaultBackingIndexName(dataStreamName, 3)}; |
| 177 | + List<IndexMetadata> backingIndices = Arrays.stream(names).map(n -> createIndexMetadata(n, true)).collect(Collectors.toList()); |
| 178 | + for (IndexMetadata index : backingIndices) { |
| 179 | + builder.put(index, false); |
| 180 | + } |
| 181 | + |
| 182 | + DataStream ds = new DataStream(dataStreamName, createTimestampField("@timestamp"), |
| 183 | + backingIndices.stream().map(IndexMetadata::getIndex).collect(Collectors.toList())); |
| 184 | + builder.put(ds); |
| 185 | + |
| 186 | + IndicesOptions indicesOptions = IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN; |
| 187 | + List<ResolvedIndex> indices = new ArrayList<>(); |
| 188 | + List<ResolvedAlias> aliases = new ArrayList<>(); |
| 189 | + List<ResolvedDataStream> dataStreams = new ArrayList<>(); |
| 190 | + TransportAction.resolveIndices(new String[]{"*"}, indicesOptions, builder.build(), resolver, indices, aliases, dataStreams, true); |
| 191 | + |
| 192 | + assertThat(dataStreams.size(), equalTo(1)); |
| 193 | + assertThat(dataStreams.get(0).getBackingIndices(), arrayContaining(names)); |
| 194 | + } |
| 195 | + |
172 | 196 | private void validateIndices(List<ResolvedIndex> resolvedIndices, String... expectedIndices) {
|
173 | 197 | assertThat(resolvedIndices.size(), equalTo(expectedIndices.length));
|
174 | 198 | for (int k = 0; k < resolvedIndices.size(); k++) {
|
|
0 commit comments