Skip to content

Commit

Permalink
Aliases were already unique. Used while loop for indices to keep size
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <widdis@gmail.com>
  • Loading branch information
dbwiddis committed Aug 12, 2023
1 parent 8003bdd commit 628b885
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,37 @@

import org.opensearch.cluster.metadata.AliasMetadata;
import org.opensearch.cluster.metadata.MappingMetadata;
import org.opensearch.common.compress.CompressedXContent;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.common.bytes.BytesArray;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.common.compress.CompressedXContent;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.xcontent.DeprecationHandler;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.test.OpenSearchTestCase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.opensearch.index.RandomCreateIndexGenerator.randomIndexSettings;
import static org.opensearch.index.RandomCreateIndexGenerator.randomMappingFields;
import static org.opensearch.test.AbstractXContentTestCase.xContentTester;
import static org.hamcrest.Matchers.equalTo;

public class GetIndexTemplatesResponseTests extends OpenSearchTestCase {

Expand Down Expand Up @@ -102,12 +99,8 @@ public void testParsingFromOpenSearchResponse() throws IOException {
esIMD.settings(randomIndexSettings());
esIMD.putMapping("_doc", new CompressedXContent(BytesReference.bytes(randomMapping("_doc", xContentType))));
int numAliases = randomIntBetween(0, 8);
Set<String> uniqueAliases = new HashSet<>();
for (int j = 0; j < numAliases; j++) {
uniqueAliases.add(String.format(Locale.ROOT, "%02d ", j) + randomAlphaOfLength(4));
}
for (String uniqueAlias : uniqueAliases) {
esIMD.putAlias(randomAliasMetadata(uniqueAlias));
esIMD.putAlias(randomAliasMetadata(String.format(Locale.ROOT, "%02d ", j) + randomAlphaOfLength(4)));
}
esIMD.order(randomIntBetween(0, Integer.MAX_VALUE));
esIMD.version(randomIntBetween(0, Integer.MAX_VALUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static void randomMappingFields(XContentBuilder builder, boolean allowObj

int fieldsNo = randomIntBetween(0, 5);
Set<String> uniqueFields = new HashSet<>();
for (int i = 0; i < fieldsNo; i++) {
while (uniqueFields.size() < fieldsNo) {
uniqueFields.add(randomAlphaOfLength(5));
}
for (String uniqueField : uniqueFields) {
Expand Down

0 comments on commit 628b885

Please sign in to comment.