|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.opensearch.indices.replication; |
| 10 | + |
| 11 | +import org.junit.Before; |
| 12 | +import org.opensearch.action.admin.indices.delete.DeleteIndexRequest; |
| 13 | +import org.opensearch.cluster.metadata.IndexMetadata; |
| 14 | +import org.opensearch.common.settings.Settings; |
| 15 | +import org.opensearch.indices.replication.common.ReplicationType; |
| 16 | +import org.opensearch.test.OpenSearchIntegTestCase; |
| 17 | + |
| 18 | +@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, minNumDataNodes = 2) |
| 19 | +public class SegmentReplicationSuiteIT extends SegmentReplicationBaseIT { |
| 20 | + |
| 21 | + @Before |
| 22 | + public void setup() { |
| 23 | + internalCluster().startClusterManagerOnlyNode(); |
| 24 | + createIndex(INDEX_NAME); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public Settings indexSettings() { |
| 29 | + final Settings.Builder builder = Settings.builder() |
| 30 | + .put(super.indexSettings()) |
| 31 | + // reset shard & replica count to random values set by OpenSearchIntegTestCase. |
| 32 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards()) |
| 33 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numberOfReplicas()) |
| 34 | + .put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT); |
| 35 | + |
| 36 | + // TODO: Randomly enable remote store on these tests. |
| 37 | + return builder.build(); |
| 38 | + } |
| 39 | + |
| 40 | + public void testBasicReplication() throws Exception { |
| 41 | + final int docCount = scaledRandomIntBetween(10, 200); |
| 42 | + for (int i = 0; i < docCount; i++) { |
| 43 | + client().prepareIndex(INDEX_NAME).setId(Integer.toString(i)).setSource("field", "value" + i).execute().get(); |
| 44 | + } |
| 45 | + refresh(); |
| 46 | + ensureGreen(INDEX_NAME); |
| 47 | + verifyStoreContent(); |
| 48 | + } |
| 49 | + |
| 50 | + public void testDropRandomNodeDuringReplication() throws Exception { |
| 51 | + internalCluster().ensureAtLeastNumDataNodes(2); |
| 52 | + internalCluster().startClusterManagerOnlyNodes(1); |
| 53 | + |
| 54 | + final int docCount = scaledRandomIntBetween(10, 200); |
| 55 | + for (int i = 0; i < docCount; i++) { |
| 56 | + client().prepareIndex(INDEX_NAME).setId(Integer.toString(i)).setSource("field", "value" + i).execute().get(); |
| 57 | + } |
| 58 | + refresh(); |
| 59 | + |
| 60 | + internalCluster().restartRandomDataNode(); |
| 61 | + |
| 62 | + ensureYellow(INDEX_NAME); |
| 63 | + client().prepareIndex(INDEX_NAME).setId(Integer.toString(docCount)).setSource("field", "value" + docCount).execute().get(); |
| 64 | + internalCluster().startDataOnlyNode(); |
| 65 | + client().admin().indices().delete(new DeleteIndexRequest(INDEX_NAME)).actionGet(); |
| 66 | + } |
| 67 | + |
| 68 | + public void testDeleteIndexWhileReplicating() throws Exception { |
| 69 | + internalCluster().startClusterManagerOnlyNode(); |
| 70 | + final int docCount = scaledRandomIntBetween(10, 200); |
| 71 | + for (int i = 0; i < docCount; i++) { |
| 72 | + client().prepareIndex(INDEX_NAME).setId(Integer.toString(i)).setSource("field", "value" + i).execute().get(); |
| 73 | + } |
| 74 | + refresh(INDEX_NAME); |
| 75 | + client().admin().indices().delete(new DeleteIndexRequest(INDEX_NAME)).actionGet(); |
| 76 | + } |
| 77 | + |
| 78 | + public void testFullRestartDuringReplication() throws Exception { |
| 79 | + internalCluster().startNode(); |
| 80 | + final int docCount = scaledRandomIntBetween(10, 200); |
| 81 | + for (int i = 0; i < docCount; i++) { |
| 82 | + client().prepareIndex(INDEX_NAME).setId(Integer.toString(i)).setSource("field", "value" + i).execute().get(); |
| 83 | + } |
| 84 | + refresh(INDEX_NAME); |
| 85 | + internalCluster().fullRestart(); |
| 86 | + ensureGreen(INDEX_NAME); |
| 87 | + } |
| 88 | +} |
0 commit comments