Skip to content

Commit

Permalink
Signed-off-by: Neetika Singhal <[email protected]>
Browse files Browse the repository at this point in the history
update the indexRandom function to create more segments
  • Loading branch information
neetikasinghal committed Sep 27, 2023
1 parent 8807d7a commit 8643f74
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,9 @@ public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean ma
}
}
assertThat(actualErrors, emptyIterable());

bogusIds.addAll(indexRandomForMultipleSlices(indicesArray));

if (!bogusIds.isEmpty()) {
// delete the bogus types again - it might trigger merges or at least holes in the segments and enforces deleted docs!
for (List<String> doc : bogusIds) {
Expand All @@ -1659,6 +1662,27 @@ public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean ma
}
}

/*
* This method ingests bogus documents for the given indices such that multiple slices
* are formed. This is greatly useful for testing with the concurrent search use-case.
* */
public Set<List<String>> indexRandomForMultipleSlices(String... indices) {
Set<List<String>> bogusIds = new HashSet<>();
for (String index : indices) {
int slices = 2;
int numDocs = getNumShards(index).totalNumShards * slices;
while (slices-- > 0) {
for (int i = 0; i < numDocs; i++) {
String id = "bogus_doc_" + randomRealisticUnicodeOfLength(between(1, 10)) + dummmyDocIdGenerator.incrementAndGet();
client().prepareIndex().setIndex(index).setId(id).setSource("{}", MediaTypeRegistry.JSON).setRouting(id).get();
bogusIds.add(Arrays.asList(index, id));
}
refresh();
}
}
return bogusIds;
}

private final AtomicInteger dummmyDocIdGenerator = new AtomicInteger();

/** Disables an index block for the specified index */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.junit.After;
import org.junit.Before;

import static org.opensearch.search.SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING;

/**
* Base class for running the tests with parameterization of the dynamic settings
* For any class that wants to use parameterization, use @ParametersFactory to generate
Expand Down Expand Up @@ -44,4 +46,10 @@ public void afterTests() {
dynamicSettings.keySet().forEach(settingsToUnset::putNull);
client().admin().cluster().prepareUpdateSettings().setPersistentSettings(settingsToUnset).get();
}

public void indexRandomForConcurrentSearch(String... indices) {
if (dynamicSettings.get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey()).equals("true")) {
indexRandomForMultipleSlices(indices);
}
}
}

0 comments on commit 8643f74

Please sign in to comment.