You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2019/05/28 08:57:16 UTC

[lucene-solr] branch branch_8x updated: LUCENE-8813: Count down latch in finally block.

This is an automated email from the ASF dual-hosted git repository.

simonw pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new 6a26ccd  LUCENE-8813: Count down latch in finally block.
6a26ccd is described below

commit 6a26ccda8a7c4bc8302a9caf927802a0dcaa3008
Author: Simon Willnauer <si...@apache.org>
AuthorDate: Tue May 28 10:55:18 2019 +0200

    LUCENE-8813: Count down latch in finally block.
    
    This test hangs until it times-out when an assertion is tripped
    in the indexing thread. Counting down the latch in a finally block
    will cause the test to fail earlier.
---
 .../apache/lucene/index/TestIndexTooManyDocs.java  | 37 ++++++++++++----------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexTooManyDocs.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexTooManyDocs.java
index 78305f4..78e05cd 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexTooManyDocs.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexTooManyDocs.java
@@ -54,27 +54,30 @@ public class TestIndexTooManyDocs extends LuceneTestCase {
           threads[i] = new Thread(() -> {
             latch.countDown();
             try {
-              latch.await();
-            } catch (InterruptedException e) {
-              throw new AssertionError(e);
-            }
-            for (int d = 0; d < 100; d++) {
-              Document doc = new Document();
-              String id = Integer.toString(random().nextInt(numMaxDoc * 2));
-              doc.add(new StringField("id", id, Field.Store.NO));
               try {
-                Term t = new Term("id", id);
-                if (random().nextInt(5) == 0) {
-                  writer.deleteDocuments(new TermQuery(t));
-                }
-                writer.updateDocument(t, doc);
-              } catch (IOException e) {
+                latch.await();
+              } catch (InterruptedException e) {
                 throw new AssertionError(e);
-              } catch (IllegalArgumentException e) {
-                assertEquals("number of documents in the index cannot exceed " + IndexWriter.getActualMaxDocs(), e.getMessage());
               }
+              for (int d = 0; d < 100; d++) {
+                Document doc = new Document();
+                String id = Integer.toString(random().nextInt(numMaxDoc * 2));
+                doc.add(new StringField("id", id, Field.Store.NO));
+                try {
+                  Term t = new Term("id", id);
+                  if (random().nextInt(5) == 0) {
+                    writer.deleteDocuments(new TermQuery(t));
+                  }
+                  writer.updateDocument(t, doc);
+                } catch (IOException e) {
+                  throw new AssertionError(e);
+                } catch (IllegalArgumentException e) {
+                  assertEquals("number of documents in the index cannot exceed " + IndexWriter.getActualMaxDocs(), e.getMessage());
+                }
+              }
+            } finally {
+              indexingDone.countDown();
             }
-            indexingDone.countDown();
           });
         } else {
           threads[i] = new Thread(() -> {