|
18 | 18 | */
|
19 | 19 | package org.elasticsearch.index.query;
|
20 | 20 |
|
| 21 | +import org.apache.lucene.search.Query; |
21 | 22 | import org.elasticsearch.Version;
|
22 | 23 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
23 | 24 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
| 25 | +import org.elasticsearch.common.io.stream.StreamOutput; |
24 | 26 | import org.elasticsearch.common.settings.Settings;
|
25 | 27 | import org.elasticsearch.common.util.BigArrays;
|
26 | 28 | import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
| 29 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
27 | 30 | import org.elasticsearch.index.IndexSettings;
|
28 | 31 | import org.elasticsearch.index.fielddata.IndexFieldData;
|
29 | 32 | import org.elasticsearch.index.fielddata.plain.AbstractAtomicOrdinalsFieldData;
|
@@ -73,6 +76,43 @@ public void testFailIfFieldMappingNotFound() {
|
73 | 76 | assertThat(result.name(), equalTo("name"));
|
74 | 77 | }
|
75 | 78 |
|
| 79 | + public void testToQueryFails() { |
| 80 | + QueryShardContext context = createQueryShardContext(IndexMetaData.INDEX_UUID_NA_VALUE, null); |
| 81 | + Exception exc = expectThrows(Exception.class, |
| 82 | + () -> context.toQuery(new AbstractQueryBuilder() { |
| 83 | + @Override |
| 84 | + public String getWriteableName() { |
| 85 | + return null; |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + protected void doWriteTo(StreamOutput out) throws IOException { |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + protected void doXContent(XContentBuilder builder, Params params) throws IOException { |
| 95 | + |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + protected Query doToQuery(QueryShardContext context) throws IOException { |
| 100 | + throw new RuntimeException("boom"); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + protected boolean doEquals(AbstractQueryBuilder other) { |
| 105 | + return false; |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + protected int doHashCode() { |
| 110 | + return 0; |
| 111 | + } |
| 112 | + })); |
| 113 | + assertThat(exc.getMessage(), equalTo("failed to create query: boom")); |
| 114 | + } |
| 115 | + |
76 | 116 | public void testClusterAlias() throws IOException {
|
77 | 117 | final String clusterAlias = randomBoolean() ? null : "remote_cluster";
|
78 | 118 | QueryShardContext context = createQueryShardContext(IndexMetaData.INDEX_UUID_NA_VALUE, clusterAlias);
|
|
0 commit comments