From 6b39aa615e4ce2c007549e85589f9a37ebef3740 Mon Sep 17 00:00:00 2001 From: Brian Murphy Date: Thu, 31 Jul 2014 18:01:30 +0100 Subject: [PATCH] [TEST] Reduce number of updates and wait after 1st NoNodeException. --- .../org/elasticsearch/update/UpdateTests.java | 54 ++++++++++++++----- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/elasticsearch/update/UpdateTests.java b/src/test/java/org/elasticsearch/update/UpdateTests.java index 4f8df988586..e60db0afc12 100644 --- a/src/test/java/org/elasticsearch/update/UpdateTests.java +++ b/src/test/java/org/elasticsearch/update/UpdateTests.java @@ -33,6 +33,7 @@ import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.action.update.UpdateResponse; +import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.unit.TimeValue; @@ -570,7 +571,7 @@ public class UpdateTests extends ElasticsearchIntegrationTest { final int numberOfThreads = scaledRandomIntBetween(3,5); final int numberOfIdsPerThread = scaledRandomIntBetween(3,10); - final int numberOfUpdatesPerId = scaledRandomIntBetween(100,200); + final int numberOfUpdatesPerId = scaledRandomIntBetween(10,100); final int retryOnConflict = randomIntBetween(0,1); final CountDownLatch latch = new CountDownLatch(numberOfThreads); final CountDownLatch startLatch = new CountDownLatch(1); @@ -637,22 +638,49 @@ public class UpdateTests extends ElasticsearchIntegrationTest { public void run(){ try { startLatch.await(); + boolean hasWaitedForNoNode = false; for (int j = 0; j < numberOfIds; j++) { for (int k = 0; k < numberOfUpdatesPerId; ++k) { updateRequestsOutstanding.acquire(); - UpdateRequest ur = client().prepareUpdate("test", "type1", Integer.toString(j)) - .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE) - .setRetryOnConflict(retryOnConflict) - .setUpsert(jsonBuilder().startObject().field("field", 1).endObject()) - .setListenerThreaded(false) - .request(); - client().update(ur, new UpdateListener(j) ); + try { + UpdateRequest ur = client().prepareUpdate("test", "type1", Integer.toString(j)) + .setScript("ctx._source.field += 1", ScriptService.ScriptType.INLINE) + .setRetryOnConflict(retryOnConflict) + .setUpsert(jsonBuilder().startObject().field("field", 1).endObject()) + .setListenerThreaded(false) + .request(); + client().update(ur, new UpdateListener(j)); + } catch (NoNodeAvailableException nne) { + updateRequestsOutstanding.release(); + synchronized (failedMap) { + incrementMapValue(j, failedMap); + } + if (hasWaitedForNoNode) { + throw nne; + } + logger.warn("Got NoNodeException waiting for 1 second for things to recover."); + hasWaitedForNoNode = true; + Thread.sleep(1000); + } - deleteRequestsOutstanding.acquire(); - DeleteRequest dr = client().prepareDelete("test", "type1", Integer.toString(j)) - .setListenerThreaded(false) - .setOperationThreaded(false).request(); - client().delete(dr, new DeleteListener(j)); + try { + deleteRequestsOutstanding.acquire(); + DeleteRequest dr = client().prepareDelete("test", "type1", Integer.toString(j)) + .setListenerThreaded(false) + .setOperationThreaded(false).request(); + client().delete(dr, new DeleteListener(j)); + } catch (NoNodeAvailableException nne) { + deleteRequestsOutstanding.release(); + synchronized (failedMap) { + incrementMapValue(j, failedMap); + } + if (hasWaitedForNoNode) { + throw nne; + } + logger.warn("Got NoNodeException waiting for 1 second for things to recover."); + hasWaitedForNoNode = true; + Thread.sleep(1000); //Wait for no-node to clear + } } } } catch (Throwable e) {