Skip to content

Commit

Permalink
[Segment Replication] Enable test suites to run with segrep (#12307)
Browse files Browse the repository at this point in the history
* Enable test suites to run with segrep

Signed-off-by: Poojita Raj <[email protected]>

* Refactor static settings into ParameterizedStaticSettingsOpenSearchIntegTestCase

Signed-off-by: Poojita Raj <[email protected]>

---------

Signed-off-by: Poojita Raj <[email protected]>
  • Loading branch information
Poojita-Raj authored Feb 17, 2024
1 parent b19e427 commit 181b985
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,23 @@

package org.opensearch.indexing;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.opensearch.action.DocWriteResponse;
import org.opensearch.action.bulk.BulkResponse;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.index.IndexResponse;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.cluster.metadata.MetadataCreateIndexService;
import org.opensearch.common.settings.Settings;
import org.opensearch.index.VersionType;
import org.opensearch.index.mapper.MapperParsingException;
import org.opensearch.indices.InvalidIndexNameException;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;
import org.opensearch.test.hamcrest.OpenSearchAssertions;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Random;
Expand All @@ -57,7 +61,17 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;

public class IndexActionIT extends OpenSearchIntegTestCase {
public class IndexActionIT extends ParameterizedStaticSettingsOpenSearchIntegTestCase {

public IndexActionIT(Settings settings) {
super(settings);
}

@ParametersFactory
public static Collection<Object[]> parameters() {
return replicationSettings;
}

/**
* This test tries to simulate load while creating an index and indexing documents
* while the index is being created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.opensearch.ingest;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.opensearch.ExceptionsHelper;
import org.opensearch.OpenSearchException;
import org.opensearch.OpenSearchParseException;
Expand All @@ -57,6 +59,7 @@
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -73,7 +76,16 @@
import static org.hamcrest.core.Is.is;

@OpenSearchIntegTestCase.ClusterScope(minNumDataNodes = 2)
public class IngestClientIT extends OpenSearchIntegTestCase {
public class IngestClientIT extends ParameterizedStaticSettingsOpenSearchIntegTestCase {

public IngestClientIT(Settings settings) {
super(settings);
}

@ParametersFactory
public static Collection<Object[]> parameters() {
return replicationSettings;
}

@Override
protected Settings nodeSettings(int nodeOrdinal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@

package org.opensearch.ingest;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.opensearch.OpenSearchParseException;
import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.node.NodeService;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;

import java.io.IOException;
import java.util.Arrays;
Expand All @@ -52,12 +56,10 @@
import static org.hamcrest.Matchers.notNullValue;

@OpenSearchIntegTestCase.ClusterScope(numDataNodes = 0, numClientNodes = 0, scope = OpenSearchIntegTestCase.Scope.TEST)
public class IngestProcessorNotInstalledOnAllNodesIT extends OpenSearchIntegTestCase {
public class IngestProcessorNotInstalledOnAllNodesIT extends ParameterizedStaticSettingsOpenSearchIntegTestCase {

private final BytesReference pipelineSource;
private volatile boolean installPlugin;

public IngestProcessorNotInstalledOnAllNodesIT() throws IOException {
public IngestProcessorNotInstalledOnAllNodesIT(Settings settings) throws IOException {
super(settings);
pipelineSource = BytesReference.bytes(
jsonBuilder().startObject()
.startArray("processors")
Expand All @@ -70,6 +72,14 @@ public IngestProcessorNotInstalledOnAllNodesIT() throws IOException {
);
}

@ParametersFactory
public static Collection<Object[]> parameters() {
return replicationSettings;
}

private final BytesReference pipelineSource;
private volatile boolean installPlugin;

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return installPlugin ? Arrays.asList(IngestTestPlugin.class) : Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.opensearch.recovery;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.opensearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
import org.opensearch.action.admin.indices.recovery.RecoveryResponse;
Expand All @@ -44,15 +46,27 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.indices.recovery.RecoveryState;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope;
import org.opensearch.test.OpenSearchIntegTestCase.Scope;
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;

import java.util.Collection;

import static org.opensearch.index.query.QueryBuilders.matchAllQuery;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;

@ClusterScope(scope = Scope.TEST, numDataNodes = 0)
public class FullRollingRestartIT extends OpenSearchIntegTestCase {
public class FullRollingRestartIT extends ParameterizedStaticSettingsOpenSearchIntegTestCase {

public FullRollingRestartIT(Settings settings) {
super(settings);
}

@ParametersFactory
public static Collection<Object[]> parameters() {
return replicationSettings;
}

protected void assertTimeout(ClusterHealthRequestBuilder requestBuilder) {
ClusterHealthResponse clusterHealth = requestBuilder.get();
if (clusterHealth.isTimedOut()) {
Expand Down Expand Up @@ -121,7 +135,7 @@ public void testFullRollingRestart() throws Exception {
);

logger.info("--> refreshing and checking data");
refresh();
refreshAndWaitForReplication();
for (int i = 0; i < 10; i++) {
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 2000L);
}
Expand Down Expand Up @@ -154,7 +168,7 @@ public void testFullRollingRestart() throws Exception {
);

logger.info("--> stopped two nodes, verifying data");
refresh();
refreshAndWaitForReplication();
for (int i = 0; i < 10; i++) {
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 2000L);
}
Expand Down Expand Up @@ -188,7 +202,7 @@ public void testFullRollingRestart() throws Exception {
);

logger.info("--> one node left, verifying data");
refresh();
refreshAndWaitForReplication();
for (int i = 0; i < 10; i++) {
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 2000L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.opensearch.index.IndexSettings;
import org.opensearch.index.shard.DocsStats;
import org.opensearch.index.translog.Translog;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.plugins.Plugin;
import org.opensearch.search.sort.SortOrder;
import org.opensearch.test.BackgroundIndexer;
Expand All @@ -72,7 +71,6 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
import static org.opensearch.index.query.QueryBuilders.matchAllQuery;
import static org.opensearch.indices.IndicesService.CLUSTER_REPLICATION_TYPE_SETTING;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAllSuccessful;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
Expand All @@ -86,10 +84,7 @@ public RecoveryWhileUnderLoadIT(Settings settings) {

@ParametersFactory
public static Collection<Object[]> parameters() {
return Arrays.asList(
new Object[] { Settings.builder().put(CLUSTER_REPLICATION_TYPE_SETTING.getKey(), ReplicationType.DOCUMENT).build() },
new Object[] { Settings.builder().put(CLUSTER_REPLICATION_TYPE_SETTING.getKey(), ReplicationType.SEGMENT).build() }
);
return replicationSettings;
}

private final Logger logger = LogManager.getLogger(RecoveryWhileUnderLoadIT.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.opensearch.recovery;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.tests.util.English;
import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
Expand Down Expand Up @@ -73,9 +75,9 @@
import org.opensearch.test.BackgroundIndexer;
import org.opensearch.test.InternalSettingsPlugin;
import org.opensearch.test.MockIndexEventListener;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope;
import org.opensearch.test.OpenSearchIntegTestCase.Scope;
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;
import org.opensearch.test.transport.MockTransportService;
import org.opensearch.test.transport.StubbableTransport;
import org.opensearch.transport.Transport;
Expand Down Expand Up @@ -114,7 +116,17 @@
import static org.hamcrest.Matchers.startsWith;

@ClusterScope(scope = Scope.TEST, numDataNodes = 0)
public class RelocationIT extends OpenSearchIntegTestCase {
public class RelocationIT extends ParameterizedStaticSettingsOpenSearchIntegTestCase {

public RelocationIT(Settings settings) {
super(settings);
}

@ParametersFactory
public static Collection<Object[]> parameters() {
return replicationSettings;
}

private final TimeValue ACCEPTABLE_RELOCATION_TIME = new TimeValue(5, TimeUnit.MINUTES);

@Override
Expand Down Expand Up @@ -158,7 +170,7 @@ public void testSimpleRelocationNoIndexing() {
}

logger.info("--> verifying count");
client().admin().indices().prepareRefresh().execute().actionGet();
refreshAndWaitForReplication();
assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().getTotalHits().value, equalTo(20L));

logger.info("--> start another node");
Expand Down Expand Up @@ -186,7 +198,7 @@ public void testSimpleRelocationNoIndexing() {
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));

logger.info("--> verifying count again...");
client().admin().indices().prepareRefresh().execute().actionGet();
refreshAndWaitForReplication();
assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().getTotalHits().value, equalTo(20L));
}

Expand Down Expand Up @@ -265,7 +277,7 @@ public void testRelocationWhileIndexingRandom() throws Exception {
logger.info("--> indexing threads stopped");

logger.info("--> refreshing the index");
client().admin().indices().prepareRefresh("test").execute().actionGet();
refreshAndWaitForReplication("test");
logger.info("--> searching the index");
boolean ranOnce = false;
for (int i = 0; i < 10; i++) {
Expand Down Expand Up @@ -650,7 +662,7 @@ public void testRelocateWhileWaitingForRefresh() {
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));

logger.info("--> verifying count");
client().admin().indices().prepareRefresh().execute().actionGet();
refreshAndWaitForReplication();
assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().getTotalHits().value, equalTo(20L));
}

Expand Down Expand Up @@ -726,7 +738,7 @@ public void testRelocateWhileContinuouslyIndexingAndWaitingForRefresh() throws E

logger.info("--> verifying count");
assertBusy(() -> {
client().admin().indices().prepareRefresh().execute().actionGet();
refreshAndWaitForReplication();
assertTrue(pendingIndexResponses.stream().allMatch(ActionFuture::isDone));
}, 1, TimeUnit.MINUTES);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,34 @@

package org.opensearch.recovery;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.opensearch.action.admin.indices.flush.FlushResponse;
import org.opensearch.action.admin.indices.refresh.RefreshResponse;
import org.opensearch.action.get.GetResponse;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;

import java.util.Collection;

import static org.opensearch.client.Requests.flushRequest;
import static org.opensearch.client.Requests.getRequest;
import static org.opensearch.client.Requests.indexRequest;
import static org.opensearch.client.Requests.refreshRequest;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;

public class SimpleRecoveryIT extends OpenSearchIntegTestCase {
public class SimpleRecoveryIT extends ParameterizedStaticSettingsOpenSearchIntegTestCase {

public SimpleRecoveryIT(Settings settings) {
super(settings);
}

@ParametersFactory
public static Collection<Object[]> parameters() {
return replicationSettings;
}

@Override
public Settings indexSettings() {
return Settings.builder().put(super.indexSettings()).put(recoverySettings()).build();
Expand All @@ -72,7 +85,7 @@ public void testSimpleRecovery() throws Exception {
assertThat(flushResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries));
assertThat(flushResponse.getFailedShards(), equalTo(0));
client().index(indexRequest("test").id("2").source(source("2", "test"), MediaTypeRegistry.JSON)).actionGet();
RefreshResponse refreshResponse = client().admin().indices().refresh(refreshRequest("test")).actionGet();
RefreshResponse refreshResponse = refreshAndWaitForReplication("test");
assertThat(refreshResponse.getTotalShards(), equalTo(numShards.totalNumShards));
assertThat(refreshResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries));
assertThat(refreshResponse.getFailedShards(), equalTo(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.opensearch.recovery;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.apache.lucene.tests.util.English;
import org.apache.lucene.tests.util.LuceneTestCase.SuppressCodecs;
import org.opensearch.action.admin.cluster.node.stats.NodeStats;
Expand All @@ -47,6 +49,7 @@
import org.opensearch.node.RecoverySettingsChunkSizePlugin;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;
import org.opensearch.test.transport.MockTransportService;
import org.opensearch.transport.TransportService;

Expand All @@ -65,7 +68,16 @@

@OpenSearchIntegTestCase.ClusterScope(numDataNodes = 2, numClientNodes = 0, scope = OpenSearchIntegTestCase.Scope.TEST)
@SuppressCodecs("*") // test relies on exact file extensions
public class TruncatedRecoveryIT extends OpenSearchIntegTestCase {
public class TruncatedRecoveryIT extends ParameterizedStaticSettingsOpenSearchIntegTestCase {

public TruncatedRecoveryIT(Settings settings) {
super(settings);
}

@ParametersFactory
public static Collection<Object[]> parameters() {
return replicationSettings;
}

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
Expand Down
Loading

0 comments on commit 181b985

Please sign in to comment.