Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename assertThrows to prevent naming clash #52651

Merged
merged 1 commit into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
import static org.elasticsearch.common.unit.TimeValue.timeValueMillis;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_MAX_HEADER_SIZE;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFutureThrows;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
Expand Down Expand Up @@ -785,7 +785,7 @@ public void testTaskStoringFailureResult() throws Exception {
request.setShouldBlock(false);

// Start non-blocking test task that should fail
assertThrows(
assertFutureThrows(
client().execute(TestTaskPlugin.TestTaskAction.INSTANCE, request),
IllegalStateException.class
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBlocked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
Expand Down Expand Up @@ -341,7 +341,7 @@ public void testFailureToCreateIndexCleansUpIndicesService() {
.addAlias(new Alias("alias1").writeIndex(true))
.get());

assertThrows(client().admin().indices().prepareCreate("test-idx-2")
assertRequestBuilderThrows(client().admin().indices().prepareCreate("test-idx-2")
.setSettings(settings)
.addAlias(new Alias("alias1").writeIndex(true)),
IllegalStateException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import org.elasticsearch.test.InternalTestCluster;

import java.io.IOException;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;

@ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0,
autoManageMasterNodes = false)
Expand All @@ -40,7 +41,8 @@ public void testIndexExistsWithBlocksInPlace() throws IOException {
.put(GatewayService.RECOVER_AFTER_NODES_SETTING.getKey(), 99).build();
String node = internalCluster().startNode(settings);

assertThrows(client(node).admin().indices().prepareExists("test").setMasterNodeTimeout(TimeValue.timeValueSeconds(0)),
assertRequestBuilderThrows(
client(node).admin().indices().prepareExists("test").setMasterNodeTimeout(TimeValue.timeValueSeconds(0)),
MasterNotDiscoveredException.class);

internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node)); // shut down node so that test properly cleans up
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
Expand Down Expand Up @@ -369,7 +369,7 @@ public void testDuelESLucene() throws Exception {
for (TestConfig test : testConfigs) {
TermVectorsRequestBuilder request = getRequestForConfig(test);
if (test.expectedException != null) {
assertThrows(request, test.expectedException);
assertRequestBuilderThrows(request, test.expectedException);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertExists;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;

Expand Down Expand Up @@ -96,35 +96,35 @@ public void testNoMasterActions() throws Exception {
assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
});

assertThrows(clientToMasterlessNode.prepareGet("test", "type1", "1"),
assertRequestBuilderThrows(clientToMasterlessNode.prepareGet("test", "type1", "1"),
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
);

assertThrows(clientToMasterlessNode.prepareGet("no_index", "type1", "1"),
assertRequestBuilderThrows(clientToMasterlessNode.prepareGet("no_index", "type1", "1"),
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
);

assertThrows(clientToMasterlessNode.prepareMultiGet().add("test", "type1", "1"),
assertRequestBuilderThrows(clientToMasterlessNode.prepareMultiGet().add("test", "type1", "1"),
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
);

assertThrows(clientToMasterlessNode.prepareMultiGet().add("no_index", "type1", "1"),
assertRequestBuilderThrows(clientToMasterlessNode.prepareMultiGet().add("no_index", "type1", "1"),
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
);

assertThrows(clientToMasterlessNode.admin().indices().prepareAnalyze("test", "this is a test"),
assertRequestBuilderThrows(clientToMasterlessNode.admin().indices().prepareAnalyze("test", "this is a test"),
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
);

assertThrows(clientToMasterlessNode.admin().indices().prepareAnalyze("no_index", "this is a test"),
assertRequestBuilderThrows(clientToMasterlessNode.admin().indices().prepareAnalyze("no_index", "this is a test"),
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
);

assertThrows(clientToMasterlessNode.prepareSearch("test").setSize(0),
assertRequestBuilderThrows(clientToMasterlessNode.prepareSearch("test").setSize(0),
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
);

assertThrows(clientToMasterlessNode.prepareSearch("no_index").setSize(0),
assertRequestBuilderThrows(clientToMasterlessNode.prepareSearch("no_index").setSize(0),
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_READ_ONLY;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBlocked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
Expand Down Expand Up @@ -452,7 +452,8 @@ public void testEngineGCDeletesSetting() throws Exception {
client().prepareIndex("test", "type", "1").setSource("f", 1).setVersionType(VersionType.EXTERNAL).setVersion(1).get();
client().prepareDelete("test", "type", "1").setVersionType(VersionType.EXTERNAL).setVersion(2).get();
// delete is still in cache this should fail
assertThrows(client().prepareIndex("test", "type", "1").setSource("f", 3).setVersionType(VersionType.EXTERNAL).setVersion(1),
assertRequestBuilderThrows(
client().prepareIndex("test", "type", "1").setSource("f", 3).setVersionType(VersionType.EXTERNAL).setVersion(1),
VersionConflictEngineException.class);
assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.gc_deletes", 0)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -109,7 +109,7 @@ public void testSimpleIndexTemplateTests() throws Exception {
.get();

// test create param
assertThrows(client().admin().indices().preparePutTemplate("template_2")
assertRequestBuilderThrows(client().admin().indices().preparePutTemplate("template_2")
.setPatterns(Collections.singletonList("test*"))
.setSettings(indexSettings())
.setCreate(true)
Expand Down Expand Up @@ -329,7 +329,7 @@ public void testThatInvalidGetIndexTemplatesFails() throws Exception {
}

private void testExpectActionRequestValidationException(String... names) {
assertThrows(client().admin().indices().prepareGetTemplates(names),
assertRequestBuilderThrows(client().admin().indices().prepareGetTemplates(names),
ActionRequestValidationException.class,
"get template with " + Arrays.toString(names));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.tasks.TaskInfo;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.PersistentTask;
import org.elasticsearch.persistent.PersistentTasksService.WaitForPersistentTaskListener;
import org.elasticsearch.persistent.TestPersistentTasksPlugin.State;
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor;
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestParams;
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor;
import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestTasksRequestBuilder;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.tasks.TaskInfo;
import org.elasticsearch.test.ESIntegTestCase;
import org.junit.After;
import org.junit.Before;

Expand All @@ -43,7 +43,7 @@
import java.util.List;
import java.util.Objects;

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

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

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

// Wait for the task to disappear
Expand All @@ -273,7 +273,7 @@ public void testCreatePersistentTaskWithDuplicateId() throws Exception {

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

assertBusy(() -> {
// Wait for the task to start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.concurrent.TimeUnit;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFutureThrows;
import static org.hamcrest.Matchers.is;

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

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

logger.info("--> ensure cleanup is still in progress");
final RepositoryCleanupInProgress cleanup =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertOrderedSearchHits;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertRequestBuilderThrows;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -339,12 +339,12 @@ public void testNumericField() throws Exception {
assertHitCount(searchResponse, 1L);

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

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

Expand All @@ -354,12 +354,12 @@ public void testNumericField() throws Exception {
assertHitCount(searchResponse, 2L);

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

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

Expand All @@ -371,12 +371,12 @@ public void testNumericField() throws Exception {
assertHitCount(searchResponse, 2L);

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

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