|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +package org.elasticsearch.xpack.esql.action; |
| 9 | + |
| 10 | +import org.elasticsearch.action.search.ShardSearchFailure; |
| 11 | +import org.elasticsearch.test.ESTestCase; |
| 12 | +import org.elasticsearch.transport.RemoteClusterService; |
| 13 | + |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +public class EsqlExecutionInfoTests extends ESTestCase { |
| 17 | + |
| 18 | + static final EsqlExecutionInfo.Cluster localCluster = new EsqlExecutionInfo.Cluster( |
| 19 | + RemoteClusterService.LOCAL_CLUSTER_GROUP_KEY, |
| 20 | + "test" |
| 21 | + ); |
| 22 | + static final EsqlExecutionInfo.Cluster remoteCluster = new EsqlExecutionInfo.Cluster("remote", "test"); |
| 23 | + |
| 24 | + public void testHasMetadataInclude() { |
| 25 | + // includeCCSMetadata + non-local clusters will produce true |
| 26 | + EsqlExecutionInfo info = new EsqlExecutionInfo(true); |
| 27 | + assertFalse(info.hasMetadataToReport()); |
| 28 | + info.swapCluster(RemoteClusterService.LOCAL_CLUSTER_GROUP_KEY, (k, v) -> localCluster); |
| 29 | + assertFalse(info.hasMetadataToReport()); |
| 30 | + info.swapCluster("remote", (k, v) -> remoteCluster); |
| 31 | + assertTrue(info.hasMetadataToReport()); |
| 32 | + // Only remote is enough |
| 33 | + info = new EsqlExecutionInfo(true); |
| 34 | + info.swapCluster("remote", (k, v) -> remoteCluster); |
| 35 | + assertTrue(info.hasMetadataToReport()); |
| 36 | + } |
| 37 | + |
| 38 | + public void testHasMetadataIncludeFalse() { |
| 39 | + // If includeCCSMetadata is false, then it should always return false |
| 40 | + EsqlExecutionInfo info = new EsqlExecutionInfo(false); |
| 41 | + assertFalse(info.hasMetadataToReport()); |
| 42 | + assertFalse(info.hasMetadataToReport()); |
| 43 | + info.swapCluster(RemoteClusterService.LOCAL_CLUSTER_GROUP_KEY, (k, v) -> localCluster); |
| 44 | + assertFalse(info.hasMetadataToReport()); |
| 45 | + info.swapCluster("remote", (k, v) -> remoteCluster); |
| 46 | + assertFalse(info.hasMetadataToReport()); |
| 47 | + } |
| 48 | + |
| 49 | + public void testHasMetadataPartial() { |
| 50 | + EsqlExecutionInfo info = new EsqlExecutionInfo(false); |
| 51 | + String key = randomFrom(RemoteClusterService.LOCAL_CLUSTER_GROUP_KEY, "remote"); |
| 52 | + info.swapCluster(key, (k, v) -> new EsqlExecutionInfo.Cluster(k, "test", false, EsqlExecutionInfo.Cluster.Status.SUCCESSFUL)); |
| 53 | + assertFalse(info.isPartial()); |
| 54 | + assertFalse(info.hasMetadataToReport()); |
| 55 | + info.swapCluster(key, (k, v) -> new EsqlExecutionInfo.Cluster(k, "test", false, EsqlExecutionInfo.Cluster.Status.PARTIAL)); |
| 56 | + assertTrue(info.isPartial()); |
| 57 | + assertFalse(info.hasMetadataToReport()); |
| 58 | + info.swapCluster(key, (k, v) -> { |
| 59 | + EsqlExecutionInfo.Cluster.Builder builder = new EsqlExecutionInfo.Cluster.Builder(v); |
| 60 | + builder.setFailures(List.of(new ShardSearchFailure(new IllegalStateException("shard failure")))); |
| 61 | + return builder.build(); |
| 62 | + }); |
| 63 | + assertTrue(info.hasMetadataToReport()); |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments