Skip to content

Commit f83d75d

Browse files
authored
Rename assertThrows to prevent naming clash (#52582)
This commit renames ElasticsearchAssertions#assertThrows to assertRequestBuilderThrows and assertFutureThrows to avoid a naming clash with JUnit 4.13+ and static imports of these methods. Additionally, these methods have been updated to make use of expectThrows internally to avoid duplicating the logic there. Relates #51787
1 parent ae68e4f commit f83d75d

File tree

18 files changed

+138
-141
lines changed

18 files changed

+138
-141
lines changed

server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@
8585
import static org.elasticsearch.common.unit.TimeValue.timeValueMillis;
8686
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
8787
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_MAX_HEADER_SIZE;
88+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFutureThrows;
8889
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
8990
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
90-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
9191
import static org.hamcrest.Matchers.allOf;
9292
import static org.hamcrest.Matchers.containsString;
9393
import static org.hamcrest.Matchers.empty;
@@ -786,7 +786,7 @@ public void testTaskStoringFailureResult() throws Exception {
786786
request.setShouldBlock(false);
787787

788788
// Start non-blocking test task that should fail
789-
assertThrows(
789+
assertFutureThrows(
790790
client().execute(TestTaskPlugin.TestTaskAction.INSTANCE, request),
791791
IllegalStateException.class
792792
);

server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_WAIT_FOR_ACTIVE_SHARDS;
5353
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
5454
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBlocked;
55-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
55+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
5656
import static org.hamcrest.Matchers.allOf;
5757
import static org.hamcrest.Matchers.equalTo;
5858
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -303,7 +303,7 @@ public void testFailureToCreateIndexCleansUpIndicesService() {
303303
.addAlias(new Alias("alias1").writeIndex(true))
304304
.get());
305305

306-
assertThrows(client().admin().indices().prepareCreate("test-idx-2")
306+
assertRequestBuilderThrows(client().admin().indices().prepareCreate("test-idx-2")
307307
.setSettings(settings)
308308
.addAlias(new Alias("alias1").writeIndex(true)),
309309
IllegalStateException.class);

server/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
5757
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
58-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
58+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
5959
import static org.hamcrest.Matchers.equalTo;
6060
import static org.hamcrest.Matchers.notNullValue;
6161
import static org.hamcrest.Matchers.nullValue;
@@ -368,7 +368,7 @@ public void testDuelESLucene() throws Exception {
368368
for (TestConfig test : testConfigs) {
369369
TermVectorsRequestBuilder request = getRequestForConfig(test);
370370
if (test.expectedException != null) {
371-
assertThrows(request, test.expectedException);
371+
assertRequestBuilderThrows(request, test.expectedException);
372372
continue;
373373
}
374374

server/src/test/java/org/elasticsearch/cluster/NoMasterNodeIT.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertExists;
5555
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
56-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
56+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
5757
import static org.hamcrest.Matchers.equalTo;
5858
import static org.hamcrest.Matchers.greaterThan;
5959

@@ -96,35 +96,35 @@ public void testNoMasterActions() throws Exception {
9696
assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
9797
});
9898

99-
assertThrows(clientToMasterlessNode.prepareGet("test", "1"),
99+
assertRequestBuilderThrows(clientToMasterlessNode.prepareGet("test", "1"),
100100
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
101101
);
102102

103-
assertThrows(clientToMasterlessNode.prepareGet("no_index", "1"),
103+
assertRequestBuilderThrows(clientToMasterlessNode.prepareGet("no_index", "1"),
104104
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
105105
);
106106

107-
assertThrows(clientToMasterlessNode.prepareMultiGet().add("test", "1"),
107+
assertRequestBuilderThrows(clientToMasterlessNode.prepareMultiGet().add("test", "1"),
108108
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
109109
);
110110

111-
assertThrows(clientToMasterlessNode.prepareMultiGet().add("no_index", "1"),
111+
assertRequestBuilderThrows(clientToMasterlessNode.prepareMultiGet().add("no_index", "1"),
112112
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
113113
);
114114

115-
assertThrows(clientToMasterlessNode.admin().indices().prepareAnalyze("test", "this is a test"),
115+
assertRequestBuilderThrows(clientToMasterlessNode.admin().indices().prepareAnalyze("test", "this is a test"),
116116
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
117117
);
118118

119-
assertThrows(clientToMasterlessNode.admin().indices().prepareAnalyze("no_index", "this is a test"),
119+
assertRequestBuilderThrows(clientToMasterlessNode.admin().indices().prepareAnalyze("no_index", "this is a test"),
120120
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
121121
);
122122

123-
assertThrows(clientToMasterlessNode.prepareSearch("test").setSize(0),
123+
assertRequestBuilderThrows(clientToMasterlessNode.prepareSearch("test").setSize(0),
124124
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
125125
);
126126

127-
assertThrows(clientToMasterlessNode.prepareSearch("no_index").setSize(0),
127+
assertRequestBuilderThrows(clientToMasterlessNode.prepareSearch("no_index").setSize(0),
128128
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
129129
);
130130

server/src/test/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_READ_ONLY;
4646
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
4747
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBlocked;
48-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
48+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
4949
import static org.hamcrest.Matchers.containsString;
5050
import static org.hamcrest.Matchers.equalTo;
5151
import static org.hamcrest.Matchers.greaterThan;
@@ -452,7 +452,8 @@ public void testEngineGCDeletesSetting() throws Exception {
452452
client().prepareIndex("test").setId("1").setSource("f", 1).setVersionType(VersionType.EXTERNAL).setVersion(1).get();
453453
client().prepareDelete("test", "1").setVersionType(VersionType.EXTERNAL).setVersion(2).get();
454454
// delete is still in cache this should fail
455-
assertThrows(client().prepareIndex("test").setId("1").setSource("f", 3).setVersionType(VersionType.EXTERNAL).setVersion(1),
455+
assertRequestBuilderThrows(
456+
client().prepareIndex("test").setId("1").setSource("f", 3).setVersionType(VersionType.EXTERNAL).setVersion(1),
456457
VersionConflictEngineException.class);
457458

458459
assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.gc_deletes", 0)));

server/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
5757
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
5858
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
59-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
59+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
6060
import static org.hamcrest.Matchers.anyOf;
6161
import static org.hamcrest.Matchers.containsInAnyOrder;
6262
import static org.hamcrest.Matchers.containsString;
@@ -109,7 +109,7 @@ public void testSimpleIndexTemplateTests() throws Exception {
109109
.get();
110110

111111
// test create param
112-
assertThrows(client().admin().indices().preparePutTemplate("template_2")
112+
assertRequestBuilderThrows(client().admin().indices().preparePutTemplate("template_2")
113113
.setPatterns(Collections.singletonList("test*"))
114114
.setSettings(indexSettings())
115115
.setCreate(true)
@@ -329,7 +329,7 @@ public void testThatInvalidGetIndexTemplatesFails() throws Exception {
329329
}
330330

331331
private void testExpectActionRequestValidationException(String... names) {
332-
assertThrows(client().admin().indices().prepareGetTemplates(names),
332+
assertRequestBuilderThrows(client().admin().indices().prepareGetTemplates(names),
333333
ActionRequestValidationException.class,
334334
"get template with " + Arrays.toString(names));
335335
}

server/src/test/java/org/elasticsearch/persistent/PersistentTasksExecutorIT.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
import org.elasticsearch.common.UUIDs;
2626
import org.elasticsearch.common.settings.Settings;
2727
import org.elasticsearch.common.unit.TimeValue;
28-
import org.elasticsearch.plugins.Plugin;
29-
import org.elasticsearch.tasks.TaskId;
30-
import org.elasticsearch.tasks.TaskInfo;
31-
import org.elasticsearch.test.ESIntegTestCase;
3228
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.PersistentTask;
3329
import org.elasticsearch.persistent.PersistentTasksService.WaitForPersistentTaskListener;
3430
import org.elasticsearch.persistent.TestPersistentTasksPlugin.State;
35-
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor;
3631
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestParams;
32+
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor;
3733
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestTasksRequestBuilder;
34+
import org.elasticsearch.plugins.Plugin;
35+
import org.elasticsearch.tasks.TaskId;
36+
import org.elasticsearch.tasks.TaskInfo;
37+
import org.elasticsearch.test.ESIntegTestCase;
3838
import org.junit.After;
3939
import org.junit.Before;
4040

@@ -43,7 +43,7 @@
4343
import java.util.List;
4444
import java.util.Objects;
4545

46-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
46+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFutureThrows;
4747
import static org.hamcrest.Matchers.empty;
4848
import static org.hamcrest.Matchers.equalTo;
4949
import static org.hamcrest.Matchers.hasSize;
@@ -132,7 +132,7 @@ public void testPersistentActionCompletion() throws Exception {
132132
//try sending completion request with incorrect allocation id
133133
PlainActionFuture<PersistentTask<?>> failedCompletionNotificationFuture = new PlainActionFuture<>();
134134
persistentTasksService.sendCompletionRequest(taskId, Long.MAX_VALUE, null, failedCompletionNotificationFuture);
135-
assertThrows(failedCompletionNotificationFuture, ResourceNotFoundException.class);
135+
assertFutureThrows(failedCompletionNotificationFuture, ResourceNotFoundException.class);
136136
// Make sure that the task is still running
137137
assertThat(client().admin().cluster().prepareListTasks().setActions(TestPersistentTasksExecutor.NAME + "[c]")
138138
.setDetailed(true).get().getTasks().size(), equalTo(1));
@@ -240,11 +240,11 @@ public void testPersistentActionStatusUpdate() throws Exception {
240240
persistentTasksService.waitForPersistentTaskCondition(taskId,
241241
task -> false, TimeValue.timeValueMillis(10), future1);
242242

243-
assertThrows(future1, IllegalStateException.class, "timed out after 10ms");
243+
assertFutureThrows(future1, IllegalStateException.class, "timed out after 10ms");
244244

245245
PlainActionFuture<PersistentTask<?>> failedUpdateFuture = new PlainActionFuture<>();
246246
persistentTasksService.sendUpdateStateRequest(taskId, -2, new State("should fail"), failedUpdateFuture);
247-
assertThrows(failedUpdateFuture, ResourceNotFoundException.class, "the task with id " + taskId +
247+
assertFutureThrows(failedUpdateFuture, ResourceNotFoundException.class, "the task with id " + taskId +
248248
" and allocation id -2 doesn't exist");
249249

250250
// Wait for the task to disappear
@@ -268,7 +268,7 @@ public void testCreatePersistentTaskWithDuplicateId() throws Exception {
268268

269269
PlainActionFuture<PersistentTask<TestParams>> future2 = new PlainActionFuture<>();
270270
persistentTasksService.sendStartRequest(taskId, TestPersistentTasksExecutor.NAME, new TestParams("Blah"), future2);
271-
assertThrows(future2, ResourceAlreadyExistsException.class);
271+
assertFutureThrows(future2, ResourceAlreadyExistsException.class);
272272

273273
assertBusy(() -> {
274274
// Wait for the task to start

server/src/test/java/org/elasticsearch/repositories/blobstore/BlobStoreRepositoryCleanupIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import java.util.concurrent.TimeUnit;
3636

3737
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
38-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
38+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFutureThrows;
3939
import static org.hamcrest.Matchers.is;
4040

4141
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0)
@@ -59,7 +59,7 @@ public void testRepeatCleanupsDontRemove() throws Exception {
5959
final String masterNode = startBlockedCleanup("test-repo");
6060

6161
logger.info("--> sending another cleanup");
62-
assertThrows(client().admin().cluster().prepareCleanupRepository("test-repo").execute(), IllegalStateException.class);
62+
assertFutureThrows(client().admin().cluster().prepareCleanupRepository("test-repo").execute(), IllegalStateException.class);
6363

6464
logger.info("--> ensure cleanup is still in progress");
6565
final RepositoryCleanupInProgress cleanup =

server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
5555
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
5656
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertOrderedSearchHits;
57+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
5758
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
5859
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
59-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
6060
import static org.hamcrest.Matchers.equalTo;
6161
import static org.hamcrest.Matchers.instanceOf;
6262
import static org.hamcrest.Matchers.notNullValue;
@@ -319,12 +319,12 @@ public void testNumericField() throws Exception {
319319
assertHitCount(searchResponse, 1L);
320320

321321
// Explicit list of fields including numeric fields -> fail
322-
assertThrows(client().prepareSearch().setQuery(
322+
assertRequestBuilderThrows(client().prepareSearch().setQuery(
323323
new MoreLikeThisQueryBuilder(new String[] {"string_value", "int_value"}, null,
324324
new Item[] {new Item("test", "1")}).minTermFreq(1).minDocFreq(1)), SearchPhaseExecutionException.class);
325325

326326
// mlt query with no field -> exception because _all is not enabled)
327-
assertThrows(client().prepareSearch()
327+
assertRequestBuilderThrows(client().prepareSearch()
328328
.setQuery(moreLikeThisQuery(new String[] {"index"}).minTermFreq(1).minDocFreq(1)),
329329
SearchPhaseExecutionException.class);
330330

@@ -334,12 +334,12 @@ public void testNumericField() throws Exception {
334334
assertHitCount(searchResponse, 2L);
335335

336336
// mlt query with at least a numeric field -> fail by default
337-
assertThrows(client().prepareSearch().setQuery(
337+
assertRequestBuilderThrows(client().prepareSearch().setQuery(
338338
moreLikeThisQuery(new String[] {"string_value", "int_value"}, new String[] {"index"}, null)),
339339
SearchPhaseExecutionException.class);
340340

341341
// mlt query with at least a numeric field -> fail by command
342-
assertThrows(client().prepareSearch().setQuery(
342+
assertRequestBuilderThrows(client().prepareSearch().setQuery(
343343
moreLikeThisQuery(new String[] {"string_value", "int_value"}, new String[] {"index"}, null).failOnUnsupportedField(true)),
344344
SearchPhaseExecutionException.class);
345345

@@ -351,12 +351,12 @@ public void testNumericField() throws Exception {
351351
assertHitCount(searchResponse, 2L);
352352

353353
// mlt field query on a numeric field -> failure by default
354-
assertThrows(client().prepareSearch().setQuery(
354+
assertRequestBuilderThrows(client().prepareSearch().setQuery(
355355
moreLikeThisQuery(new String[] {"int_value"}, new String[] {"42"}, null).minTermFreq(1).minDocFreq(1)),
356356
SearchPhaseExecutionException.class);
357357

358358
// mlt field query on a numeric field -> failure by command
359-
assertThrows(client().prepareSearch().setQuery(
359+
assertRequestBuilderThrows(client().prepareSearch().setQuery(
360360
moreLikeThisQuery(new String[] {"int_value"}, new String[] {"42"}, null).minTermFreq(1).minDocFreq(1)
361361
.failOnUnsupportedField(true)),
362362
SearchPhaseExecutionException.class);

0 commit comments

Comments
 (0)