Skip to content

Commit

Permalink
Cleanup IndexActionIT (elastic#116554)
Browse files Browse the repository at this point in the history
We can use the hit count assertion here, no need to be tricky. Also,
this can be a single loop nowadays, the two loops are a leftover from
when this was testing with types.
  • Loading branch information
original-brownbear authored Nov 11, 2024
1 parent 3f6fda6 commit 60de8ed
Showing 1 changed file with 9 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.elasticsearch.index.mapper.DocumentParsingException;
import org.elasticsearch.indices.InvalidIndexNameException;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -28,7 +27,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicIntegerArray;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
Expand All @@ -42,7 +41,6 @@ public class IndexActionIT extends ESIntegTestCase {
public void testAutoGenerateIdNoDuplicates() throws Exception {
int numberOfIterations = scaledRandomIntBetween(10, 50);
for (int i = 0; i < numberOfIterations; i++) {
Exception firstError = null;
createIndex("test");
int numOfDocs = randomIntBetween(10, 100);
logger.info("indexing [{}] docs", numOfDocs);
Expand All @@ -52,51 +50,9 @@ public void testAutoGenerateIdNoDuplicates() throws Exception {
}
indexRandom(true, builders);
logger.info("verifying indexed content");
int numOfChecks = randomIntBetween(8, 12);
int numOfChecks = randomIntBetween(16, 24);
for (int j = 0; j < numOfChecks; j++) {
try {
logger.debug("running search with all types");
assertResponse(prepareSearch("test"), response -> {
if (response.getHits().getTotalHits().value() != numOfDocs) {
final String message = "Count is "
+ response.getHits().getTotalHits().value()
+ " but "
+ numOfDocs
+ " was expected. "
+ ElasticsearchAssertions.formatShardStatus(response);
logger.error("{}. search response: \n{}", message, response);
fail(message);
}
});
} catch (Exception e) {
logger.error("search for all docs types failed", e);
if (firstError == null) {
firstError = e;
}
}
try {
logger.debug("running search with a specific type");
assertResponse(prepareSearch("test"), response -> {
if (response.getHits().getTotalHits().value() != numOfDocs) {
final String message = "Count is "
+ response.getHits().getTotalHits().value()
+ " but "
+ numOfDocs
+ " was expected. "
+ ElasticsearchAssertions.formatShardStatus(response);
logger.error("{}. search response: \n{}", message, response);
fail(message);
}
});
} catch (Exception e) {
logger.error("search for all docs of a specific type failed", e);
if (firstError == null) {
firstError = e;
}
}
}
if (firstError != null) {
fail(firstError.getMessage());
assertHitCount(prepareSearch("test"), numOfDocs);
}
internalCluster().wipeIndices("test");
}
Expand Down Expand Up @@ -147,16 +103,13 @@ public void testCreatedFlagParallelExecution() throws Exception {
List<Callable<Void>> tasks = new ArrayList<>(taskCount);
final Random random = random();
for (int i = 0; i < taskCount; i++) {
tasks.add(new Callable<Void>() {
@Override
public Void call() throws Exception {
int docId = random.nextInt(docCount);
DocWriteResponse indexResponse = indexDoc("test", Integer.toString(docId), "field1", "value");
if (indexResponse.getResult() == DocWriteResponse.Result.CREATED) {
createdCounts.incrementAndGet(docId);
}
return null;
tasks.add(() -> {
int docId = random.nextInt(docCount);
DocWriteResponse indexResponse = indexDoc("test", Integer.toString(docId), "field1", "value");
if (indexResponse.getResult() == DocWriteResponse.Result.CREATED) {
createdCounts.incrementAndGet(docId);
}
return null;
});
}

Expand Down

0 comments on commit 60de8ed

Please sign in to comment.