Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranjith Ramachandra committed Sep 2, 2023
1 parent f8cf4c4 commit 0af7d70
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@

package org.opensearch.action.admin.indices.refresh;

import org.opensearch.action.admin.indices.settings.get.GetSettingsRequest;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope;

import java.util.Arrays;
import java.util.Objects;

import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_METADATA;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_READ;
Expand All @@ -62,10 +65,20 @@ public void testRefreshWithBlocks() {
SETTING_READ_ONLY_ALLOW_DELETE
)) {
try {
GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices("test");
String remoteStoreEnabledStr = client().admin().indices().getSettings(getSettingsRequest).actionGet().getSetting("test", IndexMetadata.SETTING_REMOTE_STORE_ENABLED);

enableIndexBlock("test", blockSetting);
RefreshResponse response = client().admin().indices().prepareRefresh("test").execute().actionGet();
assertNoFailures(response);
assertThat(response.getSuccessfulShards(), equalTo(numShards.totalNumShards));
logger.warn("IndexSettings (" + remoteStoreEnabledStr + ")");

if(Objects.equals(remoteStoreEnabledStr, "true"))
{
assertThat(response.getSuccessfulShards(), equalTo(numShards.numPrimaries));
} else {
assertThat(response.getSuccessfulShards(), equalTo(numShards.totalNumShards));
}
} finally {
disableIndexBlock("test", blockSetting);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef;
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsResponse;
import org.opensearch.action.admin.indices.alias.Alias;
Expand Down Expand Up @@ -72,6 +73,7 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

@LuceneTestCase.AwaitsFix(bugUrl = "https://hello.com")
public class GetTermVectorsIT extends AbstractTermVectorsTestCase {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void testMaxDocsLimit() throws Exception {
);
assertThat(deleteError.getMessage(), containsString("Number of documents in the index can't exceed [" + maxDocs.get() + "]"));
client().admin().indices().prepareRefresh("test").get();
SearchResponse searchResponse = client().prepareSearch("test")
SearchResponse searchResponse = client().prepareSearch("test").setPreference("_primary")
.setQuery(new MatchAllQueryBuilder())
.setTrackTotalHitsUpTo(Integer.MAX_VALUE)
.setSize(0)
Expand All @@ -142,7 +142,7 @@ public void testMaxDocsLimit() throws Exception {
internalCluster().fullRestart();
internalCluster().ensureAtLeastNumDataNodes(2);
ensureGreen("test");
searchResponse = client().prepareSearch("test")
searchResponse = client().prepareSearch("test").setPreference("_primary")
.setQuery(new MatchAllQueryBuilder())
.setTrackTotalHitsUpTo(Integer.MAX_VALUE)
.setSize(0)
Expand All @@ -160,7 +160,7 @@ public void testMaxDocsLimitConcurrently() throws Exception {
assertThat(indexingResult.numFailures, greaterThan(0));
assertThat(indexingResult.numSuccess, both(greaterThan(0)).and(lessThanOrEqualTo(maxDocs.get())));
client().admin().indices().prepareRefresh("test").get();
SearchResponse searchResponse = client().prepareSearch("test")
SearchResponse searchResponse = client().prepareSearch("test").setPreference("_primary")
.setQuery(new MatchAllQueryBuilder())
.setTrackTotalHitsUpTo(Integer.MAX_VALUE)
.setSize(0)
Expand All @@ -178,7 +178,7 @@ public void testMaxDocsLimitConcurrently() throws Exception {
assertThat(indexingResult.numSuccess, equalTo(0));
}
client().admin().indices().prepareRefresh("test").get();
searchResponse = client().prepareSearch("test")
searchResponse = client().prepareSearch("test").setPreference("_primary")
.setQuery(new MatchAllQueryBuilder())
.setTrackTotalHitsUpTo(Integer.MAX_VALUE)
.setSize(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public void testSimple() {
client().prepareIndex("test").setId("1").setSource("field", "value").get();
refresh();

SearchResponse response = client().prepareSearch("test").storedFields("_none_").setFetchSource(false).setVersion(true).get();
SearchResponse response = client().prepareSearch("test").setPreference("_primary").storedFields("_none_").setFetchSource(false).setVersion(true).get();
assertThat(response.getHits().getAt(0).getId(), nullValue());
assertThat(response.getHits().getAt(0).getSourceAsString(), nullValue());
assertThat(response.getHits().getAt(0).getVersion(), notNullValue());

response = client().prepareSearch("test").storedFields("_none_").get();
response = client().prepareSearch("test").setPreference("_primary").storedFields("_none_").get();
assertThat(response.getHits().getAt(0).getId(), nullValue());
assertThat(response.getHits().getAt(0).getSourceAsString(), nullValue());
}
Expand All @@ -74,7 +74,7 @@ public void testInnerHits() {
client().prepareIndex("test").setId("1").setSource("field", "value", "nested", Collections.singletonMap("title", "foo")).get();
refresh();

SearchResponse response = client().prepareSearch("test")
SearchResponse response = client().prepareSearch("test").setPreference("_primary")
.storedFields("_none_")
.setFetchSource(false)
.setQuery(
Expand All @@ -101,12 +101,12 @@ public void testWithRouting() {
client().prepareIndex("test").setId("1").setSource("field", "value").setRouting("toto").get();
refresh();

SearchResponse response = client().prepareSearch("test").storedFields("_none_").setFetchSource(false).get();
SearchResponse response = client().prepareSearch("test").setPreference("_primary").storedFields("_none_").setFetchSource(false).get();
assertThat(response.getHits().getAt(0).getId(), nullValue());
assertThat(response.getHits().getAt(0).field("_routing"), nullValue());
assertThat(response.getHits().getAt(0).getSourceAsString(), nullValue());

response = client().prepareSearch("test").storedFields("_none_").get();
response = client().prepareSearch("test").setPreference("_primary").storedFields("_none_").get();
assertThat(response.getHits().getAt(0).getId(), nullValue());
assertThat(response.getHits().getAt(0).getSourceAsString(), nullValue());
}
Expand All @@ -121,7 +121,7 @@ public void testInvalid() {
{
SearchPhaseExecutionException exc = expectThrows(
SearchPhaseExecutionException.class,
() -> client().prepareSearch("test").setFetchSource(true).storedFields("_none_").get()
() -> client().prepareSearch("test").setPreference("_primary").setFetchSource(true).storedFields("_none_").get()
);
Throwable rootCause = ExceptionsHelper.unwrap(exc, SearchException.class);
assertNotNull(rootCause);
Expand All @@ -131,7 +131,7 @@ public void testInvalid() {
{
SearchPhaseExecutionException exc = expectThrows(
SearchPhaseExecutionException.class,
() -> client().prepareSearch("test").storedFields("_none_").addFetchField("field").get()
() -> client().prepareSearch("test").setPreference("_primary").storedFields("_none_").addFetchField("field").get()
);
Throwable rootCause = ExceptionsHelper.unwrap(exc, SearchException.class);
assertNotNull(rootCause);
Expand All @@ -141,14 +141,14 @@ public void testInvalid() {
{
IllegalArgumentException exc = expectThrows(
IllegalArgumentException.class,
() -> client().prepareSearch("test").storedFields("_none_", "field1").setVersion(true).get()
() -> client().prepareSearch("test").setPreference("_primary").storedFields("_none_", "field1").setVersion(true).get()
);
assertThat(exc.getMessage(), equalTo("cannot combine _none_ with other fields"));
}
{
IllegalArgumentException exc = expectThrows(
IllegalArgumentException.class,
() -> client().prepareSearch("test").storedFields("_none_").storedFields("field1").setVersion(true).get()
() -> client().prepareSearch("test").setPreference("_primary").storedFields("_none_").storedFields("field1").setVersion(true).get()
);
assertThat(exc.getMessage(), equalTo("cannot combine _none_ with other fields"));
}
Expand Down

0 comments on commit 0af7d70

Please sign in to comment.