Skip to content

Commit dbdc721

Browse files
committed
Fixup
1 parent 2d6d9cc commit dbdc721

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlSecurityIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.xcontent.XContentBuilder;
2828
import org.elasticsearch.xcontent.json.JsonXContent;
2929
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
30-
import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase;
3130
import org.junit.Before;
3231
import org.junit.ClassRule;
3332

@@ -40,6 +39,7 @@
4039
import static org.elasticsearch.test.ListMatcher.matchesList;
4140
import static org.elasticsearch.test.MapMatcher.assertMap;
4241
import static org.elasticsearch.test.MapMatcher.matchesMap;
42+
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.hasCapabilities;
4343
import static org.hamcrest.Matchers.containsString;
4444
import static org.hamcrest.Matchers.equalTo;
4545
import static org.hamcrest.Matchers.is;
@@ -594,7 +594,7 @@ record Listen(long timestamp, String songId, double duration) {
594594
public void testLookupJoinIndexAllowed() throws Exception {
595595
assumeTrue(
596596
"Requires LOOKUP JOIN capability",
597-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
597+
hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
598598
);
599599

600600
Response resp = runESQLCommand(
@@ -685,7 +685,7 @@ public void testLookupJoinIndexAllowed() throws Exception {
685685
public void testLookupJoinDocLevelSecurity() throws Exception {
686686
assumeTrue(
687687
"Requires LOOKUP JOIN capability",
688-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
688+
hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
689689
);
690690

691691
Response resp = runESQLCommand("dls_user", "ROW x = 40.0 | EVAL value = x | LOOKUP JOIN lookup-user2 ON value | KEEP x, org");
@@ -734,7 +734,7 @@ public void testLookupJoinDocLevelSecurity() throws Exception {
734734
public void testLookupJoinFieldLevelSecurity() throws Exception {
735735
assumeTrue(
736736
"Requires LOOKUP JOIN capability",
737-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
737+
hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
738738
);
739739

740740
Response resp = runESQLCommand("fls_user2", "ROW x = 40.0 | EVAL value = x | LOOKUP JOIN lookup-user2 ON value");
@@ -792,7 +792,7 @@ public void testLookupJoinFieldLevelSecurity() throws Exception {
792792
public void testLookupJoinFieldLevelSecurityOnAlias() throws Exception {
793793
assumeTrue(
794794
"Requires LOOKUP JOIN capability",
795-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
795+
hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
796796
);
797797

798798
Response resp = runESQLCommand("fls_user2_alias", "ROW x = 40.0 | EVAL value = x | LOOKUP JOIN lookup-second-alias ON value");
@@ -850,7 +850,7 @@ public void testLookupJoinFieldLevelSecurityOnAlias() throws Exception {
850850
public void testLookupJoinIndexForbidden() throws Exception {
851851
assumeTrue(
852852
"Requires LOOKUP JOIN capability",
853-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
853+
hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
854854
);
855855

856856
var resp = expectThrows(

x-pack/plugin/esql/qa/server/mixed-cluster/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/mixed/MixedClusterEsqlSpecIT.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import static org.elasticsearch.xpack.esql.CsvTestUtils.isEnabled;
2323
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_LOOKUP_V12;
24+
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.hasCapabilities;
2425

2526
public class MixedClusterEsqlSpecIT extends EsqlSpecTestCase {
2627
@ClassRule
@@ -80,12 +81,12 @@ protected boolean supportsInferenceTestService() {
8081
}
8182

8283
@Override
83-
protected boolean supportsIndexModeLookup() throws IOException {
84-
return hasCapabilities(List.of(JOIN_LOOKUP_V12.capabilityName()));
84+
protected boolean supportsIndexModeLookup() {
85+
return hasCapabilities(client(), List.of(JOIN_LOOKUP_V12.capabilityName()));
8586
}
8687

8788
@Override
88-
protected boolean supportsSourceFieldMapping() throws IOException {
89+
protected boolean supportsSourceFieldMapping() {
8990
return false;
9091
}
9192

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,12 @@ protected boolean supportTimeSeriesCommand() {
187187
return true;
188188
}
189189

190-
protected static void checkCapabilities(RestClient client, TestFeatureService testFeatureService, String testName, CsvTestCase testCase)
191-
throws IOException {
190+
protected static void checkCapabilities(
191+
RestClient client,
192+
TestFeatureService testFeatureService,
193+
String testName,
194+
CsvTestCase testCase
195+
) {
192196
if (hasCapabilities(client, testCase.requiredCapabilities)) {
193197
return;
194198
}

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.io.IOException;
4444
import java.io.InputStreamReader;
4545
import java.io.OutputStream;
46+
import java.io.UncheckedIOException;
4647
import java.nio.charset.StandardCharsets;
4748
import java.time.ZoneId;
4849
import java.util.ArrayList;
@@ -54,6 +55,7 @@
5455
import java.util.Map;
5556
import java.util.Set;
5657
import java.util.concurrent.ConcurrentHashMap;
58+
import java.util.concurrent.ConcurrentMap;
5759
import java.util.function.IntFunction;
5860

5961
import static java.util.Collections.emptySet;
@@ -1423,16 +1425,17 @@ private static void prepareProfileLogger(RequestObjectBuilder requestObject, @Nu
14231425
*/
14241426
private static final ConcurrentMap<List<String>, Boolean> capabilities = new ConcurrentHashMap<>();
14251427

1426-
public static boolean hasCapabilities(RestClient client, List<String> requiredCapabilities) throws IOException {
1428+
public static boolean hasCapabilities(RestClient client, List<String> requiredCapabilities) {
14271429
if (requiredCapabilities.isEmpty()) {
14281430
return true;
14291431
}
1430-
Boolean cap = capabilities.get(requiredCapabilities);
1431-
if (cap == null) {
1432-
cap = clusterHasCapability(client, "POST", "/_query", List.of(), requiredCapabilities).orElse(false);
1433-
capabilities.put(requiredCapabilities, cap);
1434-
}
1435-
return cap;
1432+
return capabilities.computeIfAbsent(requiredCapabilities, r -> {
1433+
try {
1434+
return clusterHasCapability(client, "POST", "/_query", List.of(), requiredCapabilities).orElse(false);
1435+
} catch (IOException e) {
1436+
throw new UncheckedIOException(e);
1437+
}
1438+
});
14361439
}
14371440

14381441
private static Object removeOriginalTypesAndSuggestedCast(Object response) {

0 commit comments

Comments
 (0)