From eb8cb0312a56c3e41f79e37f1382ae79f31d3d9d Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 22 May 2013 20:10:02 +0000 Subject: [PATCH] add a variant of testThreadInterruptDeadlock that uses 2 threads git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1485388 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/TestIndexWriter.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java index 02b6abbf452..67defddb4c4 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -1183,6 +1183,46 @@ public class TestIndexWriter extends LuceneTestCase { t.join(); assertFalse(t.failed); } + + /** testThreadInterruptDeadlock but with 2 indexer threads */ + public void testTwoThreadsInterruptDeadlock() throws Exception { + IndexerThreadInterrupt t1 = new IndexerThreadInterrupt(); + t1.setDaemon(true); + t1.start(); + + IndexerThreadInterrupt t2 = new IndexerThreadInterrupt(); + t2.setDaemon(true); + t2.start(); + + // Force class loader to load ThreadInterruptedException + // up front... else we can see a false failure if 2nd + // interrupt arrives while class loader is trying to + // init this class (in servicing a first interrupt): + assertTrue(new ThreadInterruptedException(new InterruptedException()).getCause() instanceof InterruptedException); + + // issue 300 interrupts to child thread + final int numInterrupts = atLeast(300); + int i = 0; + while(i < numInterrupts) { + // TODO: would be nice to also sometimes interrupt the + // CMS merge threads too ... + Thread.sleep(10); + IndexerThreadInterrupt t = random().nextBoolean() ? t1 : t2; + if (t.allowInterrupt) { + i++; + t.interrupt(); + } + if (!t1.isAlive() && !t2.isAlive()) { + break; + } + } + t1.finish = true; + t2.finish = true; + t1.join(); + t2.join(); + assertFalse(t1.failed); + assertFalse(t2.failed); + } public void testIndexStoreCombos() throws Exception {