Skip to content

Commit

Permalink
nit: a few more test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
salvatore-campagna committed Dec 13, 2024
1 parent 8023d0b commit 657e11f
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.ClassRule;

import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

public class ShardChangesRestIT extends ESRestTestCase {
private static final String SHARD_CHANGES_ENDPOINT = "/{index}/ccr/shard_changes";
private static final String[] NAMES = { "skywalker", "leia", "obi-wan", "yoda", "chewbacca", "r2-d2", "c-3po", "darth-vader" };
private static final String CCR_SHARD_CHANGES_ENDPOINT = "/%s/ccr/shard_changes";
private static final String BULK_INDEX_ENDPOINT = "/%s/_bulk";
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
Expand All @@ -40,8 +42,12 @@ protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}

public void testShardChangesNoOperation() throws IOException {
@Before
public void assumeSnapshotBuild() {
assumeTrue("/{index}/ccr/shard_changes endpoint only available in snapshot builds", Build.current().isSnapshot());
}

public void testShardChangesNoOperation() throws IOException {
final String indexName = randomAlphanumericOfLength(10).toLowerCase(Locale.ROOT);
createIndex(
indexName,
Expand All @@ -60,7 +66,6 @@ public void testShardChangesNoOperation() throws IOException {
}

public void testShardChangesDefaultParams() throws IOException {
assumeTrue("/{index}/ccr/shard_changes endpoint only available in snapshot builds", Build.current().isSnapshot());
final String indexName = randomAlphanumericOfLength(10).toLowerCase(Locale.ROOT);
final Settings settings = Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
Expand All @@ -86,7 +91,6 @@ public void testShardChangesDefaultParams() throws IOException {
}

public void testShardChangesWithAllParameters() throws IOException {
assumeTrue("/{index}/ccr/shard_changes endpoint only available in snapshot builds", Build.current().isSnapshot());
final String indexName = randomAlphanumericOfLength(10).toLowerCase(Locale.ROOT);
createIndex(
indexName,
Expand All @@ -110,7 +114,6 @@ public void testShardChangesWithAllParameters() throws IOException {
}

public void testShardChangesMultipleRequests() throws IOException {
assumeTrue("/{index}/ccr/shard_changes endpoint only available in snapshot builds", Build.current().isSnapshot());
final String indexName = randomAlphanumericOfLength(10).toLowerCase(Locale.ROOT);
createIndex(
indexName,
Expand Down Expand Up @@ -140,7 +143,6 @@ public void testShardChangesMultipleRequests() throws IOException {
}

public void testShardChangesInvalidFromSeqNo() throws IOException {
assumeTrue("/{index}/ccr/shard_changes endpoint only available in snapshot builds", Build.current().isSnapshot());
final String indexName = randomAlphanumericOfLength(10).toLowerCase(Locale.ROOT);
createIndex(indexName);
assertTrue(indexExists(indexName));
Expand All @@ -152,7 +154,6 @@ public void testShardChangesInvalidFromSeqNo() throws IOException {
}

public void testShardChangesInvalidMaxOperationsCount() throws IOException {
assumeTrue("/{index}/ccr/shard_changes endpoint only available in snapshot builds", Build.current().isSnapshot());
final String indexName = randomAlphanumericOfLength(10).toLowerCase(Locale.ROOT);
createIndex(indexName);
assertTrue(indexExists(indexName));
Expand All @@ -164,7 +165,6 @@ public void testShardChangesInvalidMaxOperationsCount() throws IOException {
}

public void testShardChangesInvalidPollTimeout() throws IOException {
assumeTrue("/{index}/ccr/shard_changes endpoint only available in snapshot builds", Build.current().isSnapshot());
final String indexName = randomAlphanumericOfLength(10).toLowerCase(Locale.ROOT);
createIndex(indexName);
assertTrue(indexExists(indexName));
Expand All @@ -175,7 +175,6 @@ public void testShardChangesInvalidPollTimeout() throws IOException {
}

public void testShardChangesInvalidMaxBatchSize() throws IOException {
assumeTrue("/{index}/ccr/shard_changes endpoint only available in snapshot builds", Build.current().isSnapshot());
final String indexName = randomAlphanumericOfLength(10).toLowerCase(Locale.ROOT);
createIndex(indexName);
assertTrue(indexExists(indexName));
Expand All @@ -191,7 +190,6 @@ public void testShardChangesInvalidMaxBatchSize() throws IOException {
}

public void testShardChangesMissingIndex() throws IOException {
assumeTrue("/{index}/ccr/shard_changes endpoint only available in snapshot builds", Build.current().isSnapshot());
final String indexName = randomAlphanumericOfLength(10).toLowerCase(Locale.ROOT);
assertFalse(indexExists(indexName));

Expand All @@ -214,11 +212,11 @@ private static Request bulkRequest(final String indexName, int numberOfDocuments
}

private static String shardChangesEndpoint(final String indexName) {
return String.format("/%s/ccr/shard_changes", indexName);
return String.format(CCR_SHARD_CHANGES_ENDPOINT, indexName);
}

private static String bulkEndpoint(final String indexName) {
return String.format("/%s/_bulk", indexName);
return String.format(BULK_INDEX_ENDPOINT, indexName);
}

private void assertResponseException(final ResponseException ex, final RestStatus restStatus, final String error) {
Expand Down

0 comments on commit 657e11f

Please sign in to comment.