|
5 | 5 | */
|
6 | 6 | package org.elasticsearch.datastreams;
|
7 | 7 |
|
| 8 | +import org.elasticsearch.ElasticsearchStatusException; |
8 | 9 | import org.elasticsearch.ExceptionsHelper;
|
9 | 10 | import org.elasticsearch.action.ActionRequestBuilder;
|
10 | 11 | import org.elasticsearch.action.DocWriteRequest;
|
@@ -1044,6 +1045,54 @@ public void testAutoCreateV1TemplateNoDataStream() {
|
1044 | 1045 | assertThat(getIndexResponse.getSettings().get("logs-foobar").get(IndexMetadata.SETTING_NUMBER_OF_REPLICAS), equalTo("0"));
|
1045 | 1046 | }
|
1046 | 1047 |
|
| 1048 | + public void testCreatingDataStreamAndFirstBackingIndexExistsFails() throws Exception { |
| 1049 | + String dataStreamName = "logs-foobar"; |
| 1050 | + String backingIndex = DataStream.getDefaultBackingIndexName(dataStreamName, 1); |
| 1051 | + |
| 1052 | + createIndex(backingIndex); |
| 1053 | + putComposableIndexTemplate("id", List.of("logs-*")); |
| 1054 | + CreateDataStreamAction.Request createDataStreamRequest = new CreateDataStreamAction.Request(dataStreamName); |
| 1055 | + Exception e = expectThrows( |
| 1056 | + ElasticsearchStatusException.class, |
| 1057 | + () -> client().execute(CreateDataStreamAction.INSTANCE, createDataStreamRequest).actionGet() |
| 1058 | + ); |
| 1059 | + assertThat(e.getMessage(), equalTo("data stream could not be created because backing index [" + backingIndex + "] already exists")); |
| 1060 | + } |
| 1061 | + |
| 1062 | + public void testAutoCreatingDataStreamAndFirstBackingIndexExistsFails() throws Exception { |
| 1063 | + String dataStreamName = "logs-foobar"; |
| 1064 | + String backingIndex = DataStream.getDefaultBackingIndexName(dataStreamName, 1); |
| 1065 | + |
| 1066 | + createIndex(backingIndex); |
| 1067 | + putComposableIndexTemplate("id", List.of("logs-*")); |
| 1068 | + |
| 1069 | + IndexRequest indexRequest = new IndexRequest(dataStreamName).opType("create") |
| 1070 | + .source("{\"@timestamp\": \"2020-12-12\"}", XContentType.JSON); |
| 1071 | + Exception e = expectThrows(ElasticsearchStatusException.class, () -> client().index(indexRequest).actionGet()); |
| 1072 | + assertThat(e.getMessage(), equalTo("data stream could not be created because backing index [" + backingIndex + "] already exists")); |
| 1073 | + } |
| 1074 | + |
| 1075 | + public void testCreatingDataStreamAndBackingIndexExistsFails() throws Exception { |
| 1076 | + String dataStreamName = "logs-foobar"; |
| 1077 | + String backingIndex = DataStream.getDefaultBackingIndexName(dataStreamName, 2); |
| 1078 | + |
| 1079 | + createIndex(backingIndex); |
| 1080 | + putComposableIndexTemplate("id", List.of("logs-*")); |
| 1081 | + |
| 1082 | + CreateDataStreamAction.Request createDataStreamRequest = new CreateDataStreamAction.Request(dataStreamName); |
| 1083 | + Exception e = expectThrows( |
| 1084 | + IllegalStateException.class, |
| 1085 | + () -> client().execute(CreateDataStreamAction.INSTANCE, createDataStreamRequest).actionGet() |
| 1086 | + ); |
| 1087 | + assertThat( |
| 1088 | + e.getMessage(), |
| 1089 | + equalTo( |
| 1090 | + "data stream [logs-foobar] could create backing indices that conflict with 1 " |
| 1091 | + + "existing index(s) or alias(s) including '.ds-logs-foobar-000002'" |
| 1092 | + ) |
| 1093 | + ); |
| 1094 | + } |
| 1095 | + |
1047 | 1096 | private static void verifyResolvability(String dataStream, ActionRequestBuilder<?, ?> requestBuilder, boolean fail) {
|
1048 | 1097 | verifyResolvability(dataStream, requestBuilder, fail, 0);
|
1049 | 1098 | }
|
|
0 commit comments