From 9423378f2735e9b929d7856fb763229889057972 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 4 Jan 2011 17:44:33 +0200 Subject: [PATCH] add heavy concurrent updates to same doc, and make sure it has the same data on all replicas --- ...nsportShardReplicationOperationAction.java | 1 + .../ConcurrentDocumentOperationTests.java | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 modules/test/integration/src/test/java/org/elasticsearch/test/integration/load/ConcurrentDocumentOperationTests.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java index 505cd27763a..8cab0be69bf 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java @@ -372,6 +372,7 @@ public abstract class TransportShardReplicationOperationAction create an index with 1 shard and max replicas based on nodes"); + nodes[0].client().admin().indices().prepareCreate("test") + .setSettings(settingsBuilder().put("number_of_shards", 1).put("number_of_replicas", nodes.length - 1)) + .execute().actionGet(); + + logger.info("execute concurrent updates on the same doc"); + int numberOfUpdates = 100; + final AtomicReference failure = new AtomicReference(); + final CountDownLatch latch = new CountDownLatch(numberOfUpdates); + for (int i = 0; i < numberOfUpdates; i++) { + nodes[0].client().prepareIndex("test", "type1", "1").setSource("field1", i).execute(new ActionListener() { + @Override public void onResponse(IndexResponse response) { + latch.countDown(); + } + + @Override public void onFailure(Throwable e) { + e.printStackTrace(); + failure.set(e); + latch.countDown(); + } + }); + } + + latch.await(); + + assertThat(failure.get(), nullValue()); + + nodes[0].client().admin().indices().prepareRefresh().execute().actionGet(); + + logger.info("done indexing, check all have the same field value"); + Map masterSource = nodes[0].client().prepareGet("test", "type1", "1").execute().actionGet().sourceAsMap(); + for (int i = 0; i < (nodes.length * 5); i++) { + assertThat(nodes[0].client().prepareGet("test", "type1", "1").execute().actionGet().sourceAsMap(), equalTo(masterSource)); + } + } +}