[TEST] add a test that explicitly verifies no duplicates are created
we do this test in other places in ES, but no dedicated test for it. This test was born out of the auto generate id work, but we should have this test regardless if it gets in or not
This commit is contained in:
parent
39705aa236
commit
0a84253045
|
@ -19,6 +19,7 @@
|
|||
package org.elasticsearch.indexing;
|
||||
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
|
@ -32,6 +33,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicIntegerArray;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||
|
||||
|
@ -40,6 +42,29 @@ import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
|||
*/
|
||||
public class IndexActionTests extends ElasticsearchIntegrationTest {
|
||||
|
||||
/**
|
||||
* This test tries to simulate load while creating an index and indexing documents
|
||||
* while the index is being created.
|
||||
*/
|
||||
@Test
|
||||
public void testAutoGenerateIdNoDuplicates() throws Exception {
|
||||
int numberOfIterations = randomIntBetween(10, 50);
|
||||
for (int i = 0; i < numberOfIterations; i++) {
|
||||
createIndex("test");
|
||||
int numOfDocs = randomIntBetween(10, 100);
|
||||
List<IndexRequestBuilder> builders = new ArrayList<>(numOfDocs);
|
||||
for (int j = 0; j < numOfDocs; j++) {
|
||||
builders.add(client().prepareIndex("test", "type").setSource("field", "value"));
|
||||
}
|
||||
indexRandom(true, builders);
|
||||
int numOfChecks = randomIntBetween(5, 10);
|
||||
for (int j = 0; j < numOfChecks; j++) {
|
||||
assertHitCount(client().prepareSearch("test").get(), numOfDocs);
|
||||
}
|
||||
cluster().wipeIndices("test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatedFlag() throws Exception {
|
||||
createIndex("test");
|
||||
|
|
Loading…
Reference in New Issue