From ac28557228ebe4929d374709ba9114a7aea3c48e Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 20 May 2014 10:19:34 +0200 Subject: [PATCH] [TEST] Provide overloaded indexRandom to opt out of dummy documents --- .../test/ElasticsearchIntegrationTest.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index 304979cff5e..9d57bfc072a 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -973,22 +973,45 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase private static final String RANDOM_BOGUS_TYPE = "RANDOM_BOGUS_TYPE______"; + /** * Indexes the given {@link IndexRequestBuilder} instances randomly. It shuffles the given builders and either * indexes they in a blocking or async fashion. This is very useful to catch problems that relate to internal document * ids or index segment creations. Some features might have bug when a given document is the first or the last in a * segment or if only one document is in a segment etc. This method prevents issues like this by randomizing the index * layout. + * + * @param forceRefresh if true all involved indices are refreshed once the documents are indexed. Additionally if true + * some empty dummy documents are may be randomly inserted into the document list and deleted once all documents are indexed. + * This is useful to produce deleted documents on the server side. + * @param builders the documents to index. + * + * @see #indexRandom(boolean, boolean, java.util.List) */ public void indexRandom(boolean forceRefresh, List builders) throws InterruptedException, ExecutionException { + indexRandom(forceRefresh, forceRefresh, builders); + } + + /** + * Indexes the given {@link IndexRequestBuilder} instances randomly. It shuffles the given builders and either + * indexes they in a blocking or async fashion. This is very useful to catch problems that relate to internal document + * ids or index segment creations. Some features might have bug when a given document is the first or the last in a + * segment or if only one document is in a segment etc. This method prevents issues like this by randomizing the index + * layout. + * + * @param forceRefresh if true all involved indices are refreshed once the documents are indexed. + * @param dummyDocuments if true some empty dummy documents are may be randomly inserted into the document list and deleted once + * all documents are indexed. This is useful to produce deleted documents on the server side. + * @param builders the documents to index. + */ + public void indexRandom(boolean forceRefresh, boolean dummyDocuments, List builders) throws InterruptedException, ExecutionException { Random random = getRandom(); Set indicesSet = new HashSet<>(); for (IndexRequestBuilder builder : builders) { indicesSet.add(builder.request().index()); } Set> bogusIds = new HashSet<>(); - if (random.nextBoolean() && !builders.isEmpty() && forceRefresh) { - // we only do this if we forceRefresh=true since we need to refresh to reflect the deletes + if (random.nextBoolean() && !builders.isEmpty() && dummyDocuments) { builders = new ArrayList<>(builders); final String[] indices = indicesSet.toArray(new String[0]); // inject some bogus docs