From a334ea57fc02c0a3133e78372c22d8ee1f554bd1 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 6 Jun 2016 13:04:19 -0400 Subject: [PATCH] Replace setRefresh with setRefreshPolicy setRefresh is being removed from core. Original commit: elastic/x-pack-elasticsearch@b865d06c6da863ca52389dad11e6f04b60c3785c --- .../agent/resolver/shards/ShardsTests.java | 3 +- .../shield/action/role/PutRoleRequest.java | 29 +++++++++++------ .../action/role/PutRoleRequestBuilder.java | 9 ++---- .../action/user/ChangePasswordRequest.java | 25 +++++++++++---- .../user/ChangePasswordRequestBuilder.java | 12 +++---- .../shield/action/user/PutUserRequest.java | 29 +++++++++++------ .../action/user/PutUserRequestBuilder.java | 11 +++---- .../authc/esnative/NativeUsersStore.java | 19 ++++++------ .../shield/authz/store/NativeRolesStore.java | 2 +- .../rest/action/role/RestPutRoleAction.java | 4 +-- .../action/user/RestChangePasswordAction.java | 2 +- .../rest/action/user/RestPutUserAction.java | 2 +- .../integration/ClearRolesCacheTests.java | 15 ++++----- .../DateMathExpressionIntegTests.java | 7 +++-- .../DocumentAndFieldLevelSecurityTests.java | 9 +++--- .../DocumentLevelSecurityTests.java | 31 ++++++++++--------- .../FieldLevelSecurityRandomTests.java | 3 +- .../integration/FieldLevelSecurityTests.java | 25 ++++++++------- ...onsWithAliasesWildcardsAndRegexsTests.java | 3 +- .../integration/KibanaUserRoleIntegTests.java | 3 +- .../integration/ShieldClearScrollTests.java | 3 +- .../authc/esnative/NativeRealmIntegTests.java | 7 +++-- .../input/chain/ChainIntegrationTests.java | 3 +- .../input/http/HttpInputIntegrationTests.java | 3 +- .../test/integration/BootStrapTests.java | 9 +++--- 25 files changed, 153 insertions(+), 115 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsTests.java index 970e714fd49..9c5a2ab8447 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/shards/ShardsTests.java @@ -25,6 +25,7 @@ import org.junit.After; import java.util.Map; import java.util.concurrent.TimeUnit; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -58,7 +59,7 @@ public class ShardsTests extends MarvelIntegTestCase { public void testShards() throws Exception { logger.debug("--> creating some indices so that shards collector reports data"); for (int i = 0; i < randomIntBetween(1, 5); i++) { - client().prepareIndex(INDEX_PREFIX + i, "foo").setRefresh(true).setSource("field1", "value1").get(); + client().prepareIndex(INDEX_PREFIX + i, "foo").setRefreshPolicy(IMMEDIATE).setSource("field1", "value1").get(); } securedFlush(); diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/PutRoleRequest.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/PutRoleRequest.java index b7a59d83d3d..05f45513aee 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/PutRoleRequest.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/PutRoleRequest.java @@ -7,6 +7,8 @@ package org.elasticsearch.shield.action.role; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -24,13 +26,13 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * Request object for adding a role to the shield index */ -public class PutRoleRequest extends ActionRequest { +public class PutRoleRequest extends ActionRequest implements WriteRequest { private String name; private String[] clusterPrivileges = Strings.EMPTY_ARRAY; private List indicesPrivileges = new ArrayList<>(); private String[] runAs = Strings.EMPTY_ARRAY; - private boolean refresh = true; + private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE; public PutRoleRequest() { } @@ -69,8 +71,19 @@ public class PutRoleRequest extends ActionRequest { this.runAs = usernames; } - public void refresh(boolean refresh) { - this.refresh = refresh; + @Override + public PutRoleRequest setRefreshPolicy(RefreshPolicy refreshPolicy) { + this.refreshPolicy = refreshPolicy; + return this; + } + + /** + * Should this request trigger a refresh ({@linkplain RefreshPolicy#IMMEDIATE}, the default), wait for a refresh ( + * {@linkplain RefreshPolicy#WAIT_UNTIL}), or proceed ignore refreshes entirely ({@linkplain RefreshPolicy#NONE}). + */ + @Override + public WriteRequest.RefreshPolicy getRefreshPolicy() { + return refreshPolicy; } public String name() { @@ -89,10 +102,6 @@ public class PutRoleRequest extends ActionRequest { return runAs; } - public boolean refresh() { - return refresh; - } - @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); @@ -104,7 +113,7 @@ public class PutRoleRequest extends ActionRequest { indicesPrivileges.add(RoleDescriptor.IndicesPrivileges.createFrom(in)); } runAs = in.readStringArray(); - refresh = in.readBoolean(); + refreshPolicy = RefreshPolicy.readFrom(in); } @Override @@ -117,7 +126,7 @@ public class PutRoleRequest extends ActionRequest { index.writeTo(out); } out.writeStringArray(runAs); - out.writeBoolean(refresh); + refreshPolicy.writeTo(out); } RoleDescriptor roleDescriptor() { diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/PutRoleRequestBuilder.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/PutRoleRequestBuilder.java index 8674f5ed205..8b63fc32de4 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/PutRoleRequestBuilder.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/PutRoleRequestBuilder.java @@ -6,6 +6,7 @@ package org.elasticsearch.shield.action.role; import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.support.WriteRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; @@ -14,7 +15,8 @@ import org.elasticsearch.shield.authz.RoleDescriptor; /** * Builder for requests to add a role to the administrative index */ -public class PutRoleRequestBuilder extends ActionRequestBuilder { +public class PutRoleRequestBuilder extends ActionRequestBuilder + implements WriteRequestBuilder { public PutRoleRequestBuilder(ElasticsearchClient client) { this(client, PutRoleAction.INSTANCE); @@ -54,9 +56,4 @@ public class PutRoleRequestBuilder extends ActionRequestBuilder implements UserRequest { +public class ChangePasswordRequest extends ActionRequest + implements UserRequest, WriteRequest { private String username; private char[] passwordHash; - private boolean refresh = true; + private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE; @Override public ActionRequestValidationException validate() { @@ -52,12 +56,19 @@ public class ChangePasswordRequest extends ActionRequest this.passwordHash = passwordHash; } - public boolean refresh() { - return refresh; + /** + * Should this request trigger a refresh ({@linkplain RefreshPolicy#IMMEDIATE}, the default), wait for a refresh ( + * {@linkplain RefreshPolicy#WAIT_UNTIL}), or proceed ignore refreshes entirely ({@linkplain RefreshPolicy#NONE}). + */ + @Override + public RefreshPolicy getRefreshPolicy() { + return refreshPolicy; } - public void refresh(boolean refresh) { - this.refresh = refresh; + @Override + public ChangePasswordRequest setRefreshPolicy(RefreshPolicy refreshPolicy) { + this.refreshPolicy = refreshPolicy; + return this; } @Override @@ -70,6 +81,7 @@ public class ChangePasswordRequest extends ActionRequest super.readFrom(in); username = in.readString(); passwordHash = CharArrays.utf8BytesToChars(in.readBytesReference().array()); + refreshPolicy = RefreshPolicy.readFrom(in); } @Override @@ -77,5 +89,6 @@ public class ChangePasswordRequest extends ActionRequest super.writeTo(out); out.writeString(username); out.writeBytesReference(new BytesArray(CharArrays.toUtf8Bytes(passwordHash))); + refreshPolicy.writeTo(out); } } diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/ChangePasswordRequestBuilder.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/ChangePasswordRequestBuilder.java index 994f2901eea..7177f1b56eb 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/ChangePasswordRequestBuilder.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/ChangePasswordRequestBuilder.java @@ -7,25 +7,28 @@ package org.elasticsearch.shield.action.user; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.support.WriteRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ValidationException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.shield.user.User; import org.elasticsearch.shield.authc.support.Hasher; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.support.Validation; +import org.elasticsearch.shield.user.User; import org.elasticsearch.xpack.common.xcontent.XContentUtils; import java.io.IOException; import java.util.Arrays; /** + * Request to change a user's password. */ public class ChangePasswordRequestBuilder - extends ActionRequestBuilder { + extends ActionRequestBuilder + implements WriteRequestBuilder { public ChangePasswordRequestBuilder(ElasticsearchClient client) { this(client, ChangePasswordAction.INSTANCE); @@ -81,9 +84,4 @@ public class ChangePasswordRequestBuilder } return this; } - - public ChangePasswordRequestBuilder refresh(boolean refresh) { - request.refresh(refresh); - return this; - } } diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequest.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequest.java index ce9fa89a747..bcf4891f882 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequest.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequest.java @@ -7,6 +7,8 @@ package org.elasticsearch.shield.action.user; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -22,7 +24,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * Request object to put a native user. */ -public class PutUserRequest extends ActionRequest implements UserRequest { +public class PutUserRequest extends ActionRequest implements UserRequest, WriteRequest { private String username; private String[] roles; @@ -30,7 +32,7 @@ public class PutUserRequest extends ActionRequest implements Use private String email; private Map metadata; private char[] passwordHash; - private boolean refresh = true; + private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE; public PutUserRequest() { } @@ -72,8 +74,19 @@ public class PutUserRequest extends ActionRequest implements Use this.passwordHash = passwordHash; } - public void refresh(boolean refresh) { - this.refresh = refresh; + /** + * Should this request trigger a refresh ({@linkplain RefreshPolicy#IMMEDIATE}, the default), wait for a refresh ( + * {@linkplain RefreshPolicy#WAIT_UNTIL}), or proceed ignore refreshes entirely ({@linkplain RefreshPolicy#NONE}). + */ + @Override + public RefreshPolicy getRefreshPolicy() { + return refreshPolicy; + } + + @Override + public PutUserRequest setRefreshPolicy(RefreshPolicy refreshPolicy) { + this.refreshPolicy = refreshPolicy; + return this; } public String username() { @@ -101,10 +114,6 @@ public class PutUserRequest extends ActionRequest implements Use return passwordHash; } - public boolean refresh() { - return refresh; - } - @Override public String[] usernames() { return new String[] { username }; @@ -124,7 +133,7 @@ public class PutUserRequest extends ActionRequest implements Use fullName = in.readOptionalString(); email = in.readOptionalString(); metadata = in.readBoolean() ? in.readMap() : null; - refresh = in.readBoolean(); + refreshPolicy = RefreshPolicy.readFrom(in); } @Override @@ -147,6 +156,6 @@ public class PutUserRequest extends ActionRequest implements Use out.writeBoolean(true); out.writeMap(metadata); } - out.writeBoolean(refresh); + refreshPolicy.writeTo(out); } } diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequestBuilder.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequestBuilder.java index 11f061c2d9b..3a5bf7b54d4 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequestBuilder.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequestBuilder.java @@ -7,6 +7,7 @@ package org.elasticsearch.shield.action.user; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.support.WriteRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; @@ -15,17 +16,18 @@ import org.elasticsearch.common.ValidationException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.shield.user.User; import org.elasticsearch.shield.authc.support.Hasher; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.support.Validation; +import org.elasticsearch.shield.user.User; import org.elasticsearch.xpack.common.xcontent.XContentUtils; import java.io.IOException; import java.util.Arrays; import java.util.Map; -public class PutUserRequestBuilder extends ActionRequestBuilder { +public class PutUserRequestBuilder extends ActionRequestBuilder + implements WriteRequestBuilder { private final Hasher hasher = Hasher.BCRYPT; @@ -77,11 +79,6 @@ public class PutUserRequestBuilder extends ActionRequestBuilder() { @Override public void onResponse(UpdateResponse updateResponse) { @@ -346,7 +347,7 @@ public class NativeUsersStore extends AbstractComponent implements ClusterStateL } if (docType.equals(RESERVED_USER_DOC_TYPE)) { - createReservedUser(username, request.passwordHash(), request.refresh(), listener); + createReservedUser(username, request.passwordHash(), request.getRefreshPolicy(), listener); } else { logger.debug("failed to change password for user [{}]", cause, request.username()); ValidationException validationException = new ValidationException(); @@ -357,10 +358,10 @@ public class NativeUsersStore extends AbstractComponent implements ClusterStateL }); } - private void createReservedUser(String username, char[] passwordHash, boolean refresh, ActionListener listener) { + private void createReservedUser(String username, char[] passwordHash, RefreshPolicy refresh, ActionListener listener) { client.prepareIndex(ShieldTemplateService.SECURITY_INDEX_NAME, RESERVED_USER_DOC_TYPE, username) .setSource(Fields.PASSWORD.getPreferredName(), String.valueOf(passwordHash)) - .setRefresh(refresh) + .setRefreshPolicy(refresh) .execute(new ActionListener() { @Override public void onResponse(IndexResponse indexResponse) { @@ -401,7 +402,7 @@ public class NativeUsersStore extends AbstractComponent implements ClusterStateL User.Fields.FULL_NAME.getPreferredName(), putUserRequest.fullName(), User.Fields.EMAIL.getPreferredName(), putUserRequest.email(), User.Fields.METADATA.getPreferredName(), putUserRequest.metadata()) - .setRefresh(putUserRequest.refresh()) + .setRefreshPolicy(putUserRequest.getRefreshPolicy()) .execute(new ActionListener() { @Override public void onResponse(UpdateResponse updateResponse) { @@ -441,7 +442,7 @@ public class NativeUsersStore extends AbstractComponent implements ClusterStateL User.Fields.FULL_NAME.getPreferredName(), putUserRequest.fullName(), User.Fields.EMAIL.getPreferredName(), putUserRequest.email(), User.Fields.METADATA.getPreferredName(), putUserRequest.metadata()) - .setRefresh(putUserRequest.refresh()) + .setRefreshPolicy(putUserRequest.getRefreshPolicy()) .execute(new ActionListener() { @Override public void onResponse(IndexResponse indexResponse) { diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/store/NativeRolesStore.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/store/NativeRolesStore.java index 5d02cd7a60f..46bfb0c3c71 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/store/NativeRolesStore.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/store/NativeRolesStore.java @@ -300,7 +300,7 @@ public class NativeRolesStore extends AbstractComponent implements RolesStore, C try { client.prepareIndex(ShieldTemplateService.SECURITY_INDEX_NAME, ROLE_DOC_TYPE, role.getName()) .setSource(role.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS)) - .setRefresh(request.refresh()) + .setRefreshPolicy(request.getRefreshPolicy()) .execute(new ActionListener() { @Override public void onResponse(IndexResponse indexResponse) { diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestPutRoleAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestPutRoleAction.java index 20334f56efc..d1a1a6c227d 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestPutRoleAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestPutRoleAction.java @@ -36,9 +36,7 @@ public class RestPutRoleAction extends BaseRestHandler { @Override protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception { PutRoleRequestBuilder requestBuilder = new SecurityClient(client).preparePutRole(request.param("name"), request.content()); - if (request.hasParam("refresh")) { - requestBuilder.refresh(request.paramAsBoolean("refresh", true)); - } + requestBuilder.setRefreshPolicy(request.param("refresh")); requestBuilder.execute(new RestBuilderListener(channel) { @Override public RestResponse buildResponse(PutRoleResponse putRoleResponse, XContentBuilder builder) throws Exception { diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestChangePasswordAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestChangePasswordAction.java index 9be684b4598..ce31c587e24 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestChangePasswordAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestChangePasswordAction.java @@ -47,7 +47,7 @@ public class RestChangePasswordAction extends BaseRestHandler { } new SecurityClient(client).prepareChangePassword(username, request.content()) - .refresh(request.paramAsBoolean("refresh", true)) + .setRefreshPolicy(request.param("refresh")) .execute(new RestBuilderListener(channel) { @Override public RestResponse buildResponse(ChangePasswordResponse changePasswordResponse, XContentBuilder builder) throws diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestPutUserAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestPutUserAction.java index 863a960d47e..261495f4ac1 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestPutUserAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestPutUserAction.java @@ -37,7 +37,7 @@ public class RestPutUserAction extends BaseRestHandler { protected void handleRequest(RestRequest request, final RestChannel channel, Client client) throws Exception { PutUserRequestBuilder requestBuilder = new SecurityClient(client).preparePutUser(request.param("username"), request.content()); if (request.hasParam("refresh")) { - requestBuilder.refresh(request.paramAsBoolean("refresh", true)); + requestBuilder.setRefreshPolicy(request.param("refresh")); } requestBuilder.execute(new RestBuilderListener(channel) { @Override diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRolesCacheTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRolesCacheTests.java index a2cda298e38..c2790d94f18 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRolesCacheTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRolesCacheTests.java @@ -13,10 +13,9 @@ import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.shield.action.role.PutRoleResponse; -import org.elasticsearch.shield.action.role.GetRolesResponse; import org.elasticsearch.shield.ShieldTemplateService; -import org.elasticsearch.shield.authc.esnative.NativeRealm; +import org.elasticsearch.shield.action.role.GetRolesResponse; +import org.elasticsearch.shield.action.role.PutRoleResponse; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.authc.support.UsernamePasswordToken; import org.elasticsearch.shield.authz.RoleDescriptor; @@ -31,10 +30,13 @@ import org.junit.BeforeClass; import java.util.Arrays; import java.util.List; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.NONE; import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; + /** * Test for the Shield clear roles API that changes the polling aspect of shield to only run once an hour in order to * test the cache clearing APIs. @@ -91,13 +93,12 @@ public class ClearRolesCacheTests extends NativeRealmIntegTestCase { int modifiedRolesCount = randomIntBetween(1, roles.length); List toModify = randomSubsetOf(modifiedRolesCount, roles); logger.debug("--> modifying roles {} to have run_as", toModify); - final boolean refresh = randomBoolean(); for (String role : toModify) { PutRoleResponse response = securityClient.preparePutRole(role) .cluster("none") .addIndices(new String[] { "*" }, new String[] { "ALL" }, null, null) .runAs(role) - .refresh(refresh) + .setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE) .get(); assertThat(response.isCreated(), is(false)); logger.debug("--> updated role [{}] with run_as", role); @@ -115,7 +116,7 @@ public class ClearRolesCacheTests extends NativeRealmIntegTestCase { UpdateResponse response = internalClient().prepareUpdate().setId(role).setIndex(ShieldTemplateService.SECURITY_INDEX_NAME) .setType(NativeRolesStore.ROLE_DOC_TYPE) .setDoc("run_as", new String[] { role }) - .setRefresh(refresh) + .setRefreshPolicy(refresh ? IMMEDIATE : NONE) .get(); assertThat(response.isCreated(), is(false)); logger.debug("--> updated role [{}] with run_as", role); @@ -158,7 +159,7 @@ public class ClearRolesCacheTests extends NativeRealmIntegTestCase { final boolean refresh = randomBoolean(); DeleteResponse response = internalClient() .prepareDelete(ShieldTemplateService.SECURITY_INDEX_NAME, NativeRolesStore.ROLE_DOC_TYPE, role) - .setRefresh(refresh) + .setRefreshPolicy(refresh ? IMMEDIATE : NONE) .get(); assertThat(response.isFound(), is(true)); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java index 5b626b3c2f8..36f8ff1083a 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java @@ -23,6 +23,8 @@ import org.elasticsearch.test.ShieldIntegTestCase; import java.util.Collections; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.NONE; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; @@ -64,7 +66,8 @@ public class DateMathExpressionIntegTests extends ShieldIntegTestCase { CreateIndexResponse response = client.admin().indices().prepareCreate(expression).get(); assertThat(response.isAcknowledged(), is(true)); } - IndexResponse response = client.prepareIndex(expression, "type").setSource("foo", "bar").setRefresh(refeshOnOperation).get(); + IndexResponse response = client.prepareIndex(expression, "type").setSource("foo", "bar") + .setRefreshPolicy(refeshOnOperation ? IMMEDIATE : NONE).get(); assertThat(response.isCreated(), is(true)); assertThat(response.getIndex(), containsString(expectedIndexName)); @@ -84,7 +87,7 @@ public class DateMathExpressionIntegTests extends ShieldIntegTestCase { UpdateResponse updateResponse = client.prepareUpdate(expression, "type", response.getId()) .setDoc("new", "field") - .setRefresh(refeshOnOperation) + .setRefreshPolicy(refeshOnOperation ? IMMEDIATE : NONE) .get(); assertThat(updateResponse.isCreated(), is(false)); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java index 716b58652e8..8869367b79f 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.xpack.XPackPlugin; import java.util.Collections; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -94,10 +95,10 @@ public class DocumentAndFieldLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text", "field2", "type=text") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type1", "2").setSource("field2", "value2") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); SearchResponse response = client().filterWithHeader( @@ -133,10 +134,10 @@ public class DocumentAndFieldLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text", "field2", "type=text") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type1", "2").setSource("field2", "value2") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // Both users have the same role query, but user3 has access to field2 and not field1, which should result in zero hits: diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java index f99bfef4aff..f2fd3632f5a 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java @@ -33,6 +33,7 @@ import org.elasticsearch.xpack.XPackPlugin; import java.util.Collections; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.index.query.QueryBuilders.hasChildQuery; import static org.elasticsearch.index.query.QueryBuilders.hasParentQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; @@ -108,13 +109,13 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type1", "2").setSource("field2", "value2") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type1", "3").setSource("field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); SearchResponse response = client() @@ -289,13 +290,13 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { "field3", "type=text,term_vector=with_positions_offsets_payloads") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type1", "2").setSource("field2", "value2") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type1", "3").setSource("field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); boolean realtime = randomBoolean(); @@ -354,13 +355,13 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { "field3", "type=text,term_vector=with_positions_offsets_payloads") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type1", "2").setSource("field2", "value2") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type1", "3").setSource("field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); boolean realtime = randomBoolean(); @@ -419,13 +420,13 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text", "field2", "type=text,fielddata=true", "field3", "type=text") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type1", "2").setSource("field2", "value2") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type1", "3").setSource("field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); SearchResponse response = client().prepareSearch("test") @@ -483,11 +484,11 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type2", "_parent", "type=type1", "field3", "type=text,fielddata=true") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); client().prepareIndex("test", "type2", "2").setSource("field3", "value3") .setParent("1") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); SearchResponse response = client().prepareSearch("test") @@ -705,7 +706,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type", "field1", "type=text", "field2", "type=text") ); client().prepareIndex("test", "type", "1").setSource("field1", "value1") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // With document level security enabled the update is not allowed: diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java index fc14ae859a9..541bb73623f 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; @@ -141,7 +142,7 @@ public class FieldLevelSecurityRandomTests extends ShieldIntegTestCase { assertAcked(client().admin().indices().prepareCreate("test") .addMapping("type1", (Object[])fieldMappers) ); - client().prepareIndex("test", "type1", "1").setSource(doc).setRefresh(true).get(); + client().prepareIndex("test", "type1", "1").setSource(doc).setRefreshPolicy(IMMEDIATE).get(); for (String allowedField : allowedFields) { logger.info("Checking allowed field [{}]", allowedField); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java index a887783b017..6de93265d9c 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java @@ -32,6 +32,7 @@ import org.elasticsearch.xpack.XPackPlugin; import java.util.Collections; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery; import static org.elasticsearch.index.query.QueryBuilders.hasChildQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; @@ -136,7 +137,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // user1 has access to field1, so the query should match with the document: @@ -488,7 +489,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // user1 is granted access to field1 only: @@ -622,7 +623,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); int max = scaledRandomIntBetween(4, 32); @@ -660,7 +661,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); int max = scaledRandomIntBetween(4, 32); @@ -702,7 +703,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { "field3", "type=text,store=true") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // user1 is granted access to field1 only: @@ -799,7 +800,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // user1 is granted access to field1 only: @@ -873,7 +874,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { ); client().prepareIndex("test", "type1", "1").setSource("field1", 1d, "field2", 2d) - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // user1 is granted to use field1, so it is included in the sort_values @@ -911,7 +912,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text,fielddata=true", "field2", "type=text,fielddata=true") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // user1 is authorized to use field1, so buckets are include for a term agg on field1 @@ -951,7 +952,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { "field3", "type=text,term_vector=with_positions_offsets_payloads") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); boolean realtime = randomBoolean(); @@ -1035,7 +1036,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { "field3", "type=text,term_vector=with_positions_offsets_payloads") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); boolean realtime = randomBoolean(); @@ -1155,7 +1156,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { ); client().prepareIndex("test", "type", "1") .setSource("field1", "value1", "field2", "value1") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // With field level security enabled the update is not allowed: @@ -1200,7 +1201,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase { .addMapping("type1", "field1", "type=text", "field2", "type=text") ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // user6 has access to all fields, so the query should match with the document: diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/IndicesPermissionsWithAliasesWildcardsAndRegexsTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/IndicesPermissionsWithAliasesWildcardsAndRegexsTests.java index 916321f80ba..068b3f97ef4 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/IndicesPermissionsWithAliasesWildcardsAndRegexsTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/IndicesPermissionsWithAliasesWildcardsAndRegexsTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.xpack.XPackPlugin; import java.util.Collections; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -72,7 +73,7 @@ public class IndicesPermissionsWithAliasesWildcardsAndRegexsTests extends Shield .addAlias(new Alias("an_alias")) ); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2", "field3", "value3") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); GetResponse getResponse = client() diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java index bc76aadcc1e..372426e4751 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.test.ShieldIntegTestCase; import java.util.Locale; import static java.util.Collections.singletonMap; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -183,7 +184,7 @@ public class KibanaUserRoleIntegTests extends ShieldIntegTestCase { .setIndex(index) .setType("dashboard") .setSource("foo", "bar") - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); assertThat(response.isCreated(), is(true)); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ShieldClearScrollTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ShieldClearScrollTests.java index 7c745794f1d..4d050ad6704 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ShieldClearScrollTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ShieldClearScrollTests.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.BASIC_AUTH_HEADER; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows; @@ -63,7 +64,7 @@ public class ShieldClearScrollTests extends ShieldIntegTestCase { @Before public void indexRandomDocuments() { - BulkRequestBuilder bulkRequestBuilder = client().prepareBulk().setRefresh(true); + BulkRequestBuilder bulkRequestBuilder = client().prepareBulk().setRefreshPolicy(IMMEDIATE); for (int i = 0; i < randomIntBetween(10, 50); i++) { bulkRequestBuilder.add(client().prepareIndex("index", "type", String.valueOf(i)).setSource("{ \"foo\" : \"bar\" }")); } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/esnative/NativeRealmIntegTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/esnative/NativeRealmIntegTests.java index 8ef07027eb1..f30b5b18f11 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/esnative/NativeRealmIntegTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/esnative/NativeRealmIntegTests.java @@ -44,6 +44,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.containsString; @@ -205,7 +206,7 @@ public class NativeRealmIntegTests extends NativeRealmIntegTestCase { createIndex("idx"); ensureGreen("idx"); // Index a document with the default test user - client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefresh(true).get(); + client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefreshPolicy(IMMEDIATE).get(); String token = basicAuthHeaderValue("joe", new SecuredString("s3krit".toCharArray())); SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get(); @@ -227,7 +228,7 @@ public class NativeRealmIntegTests extends NativeRealmIntegTestCase { createIndex("idx"); ensureGreen("idx"); // Index a document with the default test user - client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefresh(true).get(); + client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefreshPolicy(IMMEDIATE).get(); String token = basicAuthHeaderValue("joe", new SecuredString("s3krit".toCharArray())); SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get(); @@ -262,7 +263,7 @@ public class NativeRealmIntegTests extends NativeRealmIntegTestCase { createIndex("idx"); ensureGreen("idx"); // Index a document with the default test user - client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefresh(true).get(); + client().prepareIndex("idx", "doc", "1").setSource("body", "foo").setRefreshPolicy(IMMEDIATE).get(); String token = basicAuthHeaderValue("joe", new SecuredString("s3krit".toCharArray())); SearchResponse searchResp = client().filterWithHeader(Collections.singletonMap("Authorization", token)).prepareSearch("idx").get(); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainIntegrationTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainIntegrationTests.java index 77b2029dc44..a760116dd11 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainIntegrationTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainIntegrationTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction; @@ -42,7 +43,7 @@ public class ChainIntegrationTests extends AbstractWatcherIntegrationTestCase { public void testChainedInputsAreWorking() throws Exception { String index = "the-most-awesome-index-ever"; createIndex(index); - client().prepareIndex(index, "type", "id").setSource("{}").setRefresh(true).get(); + client().prepareIndex(index, "type", "id").setSource("{}").setRefreshPolicy(IMMEDIATE).get(); InetSocketAddress address = internalCluster().httpAddresses()[0]; HttpInput.Builder httpInputBuilder = httpInput(HttpRequestTemplate.builder(address.getHostString(), address.getPort()) diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java index 2ff6a291474..a22d6262be7 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule; import java.net.InetSocketAddress; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery; @@ -49,7 +50,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas @TestLogging("watcher.support.http:TRACE") public void testHttpInput() throws Exception { createIndex("index"); - client().prepareIndex("index", "type", "id").setSource("{}").setRefresh(true).get(); + client().prepareIndex("index", "type", "id").setSource("{}").setRefreshPolicy(IMMEDIATE).get(); InetSocketAddress address = internalCluster().httpAddresses()[0]; watcherClient().preparePutWatch("_name") diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java index 210e295db79..dcda61a5813 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java @@ -32,6 +32,7 @@ import org.joda.time.DateTimeZone; import java.util.concurrent.TimeUnit; +import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; @@ -140,7 +141,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase { .endObject() .endObject()) .setConsistencyLevel(WriteConsistencyLevel.ALL) - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // unknown condition: @@ -158,7 +159,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase { .endObject() .endObject()) .setConsistencyLevel(WriteConsistencyLevel.ALL) - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); // unknown trigger: @@ -176,7 +177,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase { .endObject() .endObject()) .setConsistencyLevel(WriteConsistencyLevel.ALL) - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); stopWatcher(); @@ -200,7 +201,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase { .endObject() .endObject()) .setConsistencyLevel(WriteConsistencyLevel.ALL) - .setRefresh(true) + .setRefreshPolicy(IMMEDIATE) .get(); stopWatcher();