Skip to content

Commit 7f7e433

Browse files
authored
Merge branch 'main' into entitlements/reenable-ingest-tests
2 parents 5247acb + dc46b79 commit 7f7e433

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/IndexResolutionIT.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77

88
package org.elasticsearch.xpack.esql.plugin;
99

10+
import org.elasticsearch.action.NoShardAvailableActionException;
1011
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
1112
import org.elasticsearch.action.datastreams.CreateDataStreamAction;
13+
import org.elasticsearch.action.support.ActiveShardCount;
1214
import org.elasticsearch.cluster.block.ClusterBlockException;
1315
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
16+
import org.elasticsearch.cluster.metadata.IndexMetadata;
17+
import org.elasticsearch.common.settings.Settings;
1418
import org.elasticsearch.common.util.CollectionUtils;
1519
import org.elasticsearch.datastreams.DataStreamsPlugin;
1620
import org.elasticsearch.index.IndexNotFoundException;
@@ -21,6 +25,7 @@
2125

2226
import java.util.Collection;
2327
import java.util.List;
28+
import java.util.UUID;
2429

2530
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
2631
import static org.elasticsearch.xpack.esql.action.EsqlQueryRequest.syncEsqlQueryRequest;
@@ -108,12 +113,77 @@ public void testDoesNotResolveClosedIndex() {
108113
assertAcked(client().admin().indices().prepareCreate("index-1"));
109114
indexRandom(true, "index-1", 10);
110115
assertAcked(client().admin().indices().prepareClose("index-1"));
116+
assertAcked(client().admin().indices().prepareCreate("index-2"));
117+
indexRandom(true, "index-2", 15);
111118

112119
expectThrows(
113120
ClusterBlockException.class,
114121
containsString("index [index-1] blocked by: [FORBIDDEN/4/index closed]"),
115122
() -> run(syncEsqlQueryRequest().query("FROM index-1"))
116123
);
124+
expectThrows(
125+
ClusterBlockException.class,
126+
containsString("index [index-1] blocked by: [FORBIDDEN/4/index closed]"),
127+
() -> run(syncEsqlQueryRequest().query("FROM index-1,index-2"))
128+
);
129+
try (var response = run(syncEsqlQueryRequest().query("FROM index-*"))) {
130+
assertOk(response);
131+
assertResultCount(response, 15);// only index-2 records match
132+
}
133+
}
134+
135+
public void testHiddenIndices() {
136+
assertAcked(client().admin().indices().prepareCreate("regular-index-1"));
137+
indexRandom(true, "regular-index-1", 10);
138+
assertAcked(
139+
client().admin()
140+
.indices()
141+
.prepareCreate(".hidden-index-1")
142+
.setSettings(Settings.builder().put(IndexMetadata.SETTING_INDEX_HIDDEN, true))
143+
);
144+
indexRandom(true, ".hidden-index-1", 15);
145+
146+
try (var response = run(syncEsqlQueryRequest().query("FROM .hidden-index-1"))) {
147+
assertOk(response);
148+
assertResultCount(response, 15);
149+
}
150+
try (var response = run(syncEsqlQueryRequest().query("FROM *-index-1"))) {
151+
assertOk(response);
152+
assertResultCount(response, 10); // only non-hidden index matches when specifying pattern
153+
}
154+
try (var response = run(syncEsqlQueryRequest().query("FROM .hidden-*"))) {
155+
assertOk(response);
156+
assertResultCount(response, 15); // hidden indices do match when specifying hidden/dot pattern
157+
}
158+
}
159+
160+
public void testUnavailableIndex() {
161+
assertAcked(client().admin().indices().prepareCreate("available-index-1"));
162+
indexRandom(true, "available-index-1", 10);
163+
assertAcked(
164+
client().admin()
165+
.indices()
166+
.prepareCreate("unavailable-index-1")
167+
.setSettings(Settings.builder().put("index.routing.allocation.require._name", UUID.randomUUID().toString()))
168+
.setWaitForActiveShards(ActiveShardCount.NONE)
169+
);
170+
171+
expectThrows(
172+
NoShardAvailableActionException.class,
173+
containsString("index [unavailable-index-1] has no active shard copy"),
174+
() -> run(syncEsqlQueryRequest().query("FROM unavailable-index-1"))
175+
);
176+
177+
expectThrows(
178+
NoShardAvailableActionException.class,
179+
containsString("index [unavailable-index-1] has no active shard copy"),
180+
() -> run(syncEsqlQueryRequest().query("FROM unavailable-index-1,available-index-1"))
181+
);
182+
expectThrows(
183+
NoShardAvailableActionException.class,
184+
containsString("index [unavailable-index-1] has no active shard copy"),
185+
() -> run(syncEsqlQueryRequest().query("FROM *-index-1"))
186+
);
117187
}
118188

119189
public void testPartialResolution() {
@@ -134,4 +204,12 @@ public void testPartialResolution() {
134204
private static void assertOk(EsqlQueryResponse response) {
135205
assertThat(response.isPartial(), equalTo(false));
136206
}
207+
208+
private static void assertResultCount(EsqlQueryResponse response, long rows) {
209+
long count = 0;
210+
for (var iterator = response.column(0); iterator.hasNext(); iterator.next()) {
211+
count++;
212+
}
213+
assertThat(count, equalTo(rows));
214+
}
137215
}

0 commit comments

Comments
 (0)