improve testAutoGenerateIdNoDuplicates logging on failure
Add unique doc content and log the results of the search results on failure, so we can better see what went wrong
This commit is contained in:
parent
4c62e14c50
commit
27c87ab961
|
@ -23,10 +23,10 @@ import org.elasticsearch.action.DocWriteResponse;
|
||||||
import org.elasticsearch.action.bulk.BulkResponse;
|
import org.elasticsearch.action.bulk.BulkResponse;
|
||||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||||
import org.elasticsearch.action.index.IndexResponse;
|
import org.elasticsearch.action.index.IndexResponse;
|
||||||
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaDataCreateIndexService;
|
import org.elasticsearch.cluster.metadata.MetaDataCreateIndexService;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.elasticsearch.index.VersionType;
|
import org.elasticsearch.index.VersionType;
|
||||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||||
import org.elasticsearch.indices.InvalidIndexNameException;
|
import org.elasticsearch.indices.InvalidIndexNameException;
|
||||||
|
@ -34,6 +34,8 @@ import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||||
import org.elasticsearch.test.VersionUtils;
|
import org.elasticsearch.test.VersionUtils;
|
||||||
|
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
||||||
|
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -47,7 +49,6 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicIntegerArray;
|
import java.util.concurrent.atomic.AtomicIntegerArray;
|
||||||
|
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||||
|
@ -57,6 +58,8 @@ public class IndexActionIT extends ESIntegTestCase {
|
||||||
* This test tries to simulate load while creating an index and indexing documents
|
* This test tries to simulate load while creating an index and indexing documents
|
||||||
* while the index is being created.
|
* while the index is being created.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@TestLogging("_root:DEBUG,org.elasticsearch.index.shard.IndexShard:TRACE,org.elasticsearch.action.search:TRACE")
|
||||||
public void testAutoGenerateIdNoDuplicates() throws Exception {
|
public void testAutoGenerateIdNoDuplicates() throws Exception {
|
||||||
int numberOfIterations = scaledRandomIntBetween(10, 50);
|
int numberOfIterations = scaledRandomIntBetween(10, 50);
|
||||||
for (int i = 0; i < numberOfIterations; i++) {
|
for (int i = 0; i < numberOfIterations; i++) {
|
||||||
|
@ -66,7 +69,7 @@ public class IndexActionIT extends ESIntegTestCase {
|
||||||
logger.info("indexing [{}] docs", numOfDocs);
|
logger.info("indexing [{}] docs", numOfDocs);
|
||||||
List<IndexRequestBuilder> builders = new ArrayList<>(numOfDocs);
|
List<IndexRequestBuilder> builders = new ArrayList<>(numOfDocs);
|
||||||
for (int j = 0; j < numOfDocs; j++) {
|
for (int j = 0; j < numOfDocs; j++) {
|
||||||
builders.add(client().prepareIndex("test", "type").setSource("field", "value"));
|
builders.add(client().prepareIndex("test", "type").setSource("field", "value_" + j));
|
||||||
}
|
}
|
||||||
indexRandom(true, builders);
|
indexRandom(true, builders);
|
||||||
logger.info("verifying indexed content");
|
logger.info("verifying indexed content");
|
||||||
|
@ -74,7 +77,13 @@ public class IndexActionIT extends ESIntegTestCase {
|
||||||
for (int j = 0; j < numOfChecks; j++) {
|
for (int j = 0; j < numOfChecks; j++) {
|
||||||
try {
|
try {
|
||||||
logger.debug("running search with all types");
|
logger.debug("running search with all types");
|
||||||
assertHitCount(client().prepareSearch("test").get(), numOfDocs);
|
SearchResponse response = client().prepareSearch("test").get();
|
||||||
|
if (response.getHits().totalHits() != numOfDocs) {
|
||||||
|
final String message = "Count is " + response.getHits().totalHits() + " but " + numOfDocs + " was expected. "
|
||||||
|
+ ElasticsearchAssertions.formatShardStatus(response);
|
||||||
|
logger.error("{}. search response: \n{}", message, response);
|
||||||
|
fail(message);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("search for all docs types failed", e);
|
logger.error("search for all docs types failed", e);
|
||||||
if (firstError == null) {
|
if (firstError == null) {
|
||||||
|
@ -83,7 +92,13 @@ public class IndexActionIT extends ESIntegTestCase {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
logger.debug("running search with a specific type");
|
logger.debug("running search with a specific type");
|
||||||
assertHitCount(client().prepareSearch("test").setTypes("type").get(), numOfDocs);
|
SearchResponse response = client().prepareSearch("test").setTypes("type").get();
|
||||||
|
if (response.getHits().totalHits() != numOfDocs) {
|
||||||
|
final String message = "Count is " + response.getHits().totalHits() + " but " + numOfDocs + " was expected. "
|
||||||
|
+ ElasticsearchAssertions.formatShardStatus(response);
|
||||||
|
logger.error("{}. search response: \n{}", message, response);
|
||||||
|
fail(message);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("search for all docs of a specific type failed", e);
|
logger.error("search for all docs of a specific type failed", e);
|
||||||
if (firstError == null) {
|
if (firstError == null) {
|
||||||
|
|
Loading…
Reference in New Issue