Return-Path: Delivered-To: apmail-lucene-java-dev-archive@www.apache.org Received: (qmail 83175 invoked from network); 15 Nov 2009 21:29:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Nov 2009 21:29:44 -0000 Received: (qmail 86022 invoked by uid 500); 15 Nov 2009 21:29:43 -0000 Delivered-To: apmail-lucene-java-dev-archive@lucene.apache.org Received: (qmail 85948 invoked by uid 500); 15 Nov 2009 21:29:43 -0000 Mailing-List: contact java-dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@lucene.apache.org Delivered-To: mailing list java-dev@lucene.apache.org Received: (qmail 85940 invoked by uid 99); 15 Nov 2009 21:29:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Nov 2009 21:29:43 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [85.25.71.29] (HELO mail.troja.net) (85.25.71.29) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Nov 2009 21:29:32 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.troja.net (Postfix) with ESMTP id 88A36D36005 for ; Sun, 15 Nov 2009 22:29:12 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.troja.net Received: from mail.troja.net ([127.0.0.1]) by localhost (megaira.troja.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c55QmuTP2uaJ for ; Sun, 15 Nov 2009 22:29:02 +0100 (CET) Received: from VEGA (port-83-236-62-54.dynamic.qsc.de [83.236.62.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.troja.net (Postfix) with ESMTPSA id 3698CD36002 for ; Sun, 15 Nov 2009 22:29:02 +0100 (CET) From: "Uwe Schindler" To: References: <20091115183507.09A5C23888C2@eris.apache.org> Subject: RE: svn commit: r836387 - in /lucene/java/branches/lucene_2_9_back_compat_tests/src: java/org/apache/lucene/util/ThreadInterruptedException.java test/org/apache/lucene/index/TestIndexWriter.java Date: Sun, 15 Nov 2009 22:29:01 +0100 Message-ID: <5AC0168E0E6B4D4FB8B1AB3DC0AAF301@VEGA> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcpmIm71AgsMyoC5QUKJo/IWns+cQQAF/ZDw In-Reply-To: <20091115183507.09A5C23888C2@eris.apache.org> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Checked: Checked by ClamAV on apache.org In the backwards branch there was no need to add the there not existing ThreadInterruptedException class (in the BW branch only src/test, but never src/java should be updated). Catching RuntimeException would have been enough. But it doesn't matter, that was only what I thought first - don't touch it. Uwe ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: uwe@thetaphi.de > -----Original Message----- > From: mikemccand@apache.org [mailto:mikemccand@apache.org] > Sent: Sunday, November 15, 2009 7:35 PM > To: java-commits@lucene.apache.org > Subject: svn commit: r836387 - in > /lucene/java/branches/lucene_2_9_back_compat_tests/src: > java/org/apache/lucene/util/ThreadInterruptedException.java > test/org/apache/lucene/index/TestIndexWriter.java > > Author: mikemccand > Date: Sun Nov 15 18:35:06 2009 > New Revision: 836387 > > URL: http://svn.apache.org/viewvc?rev=836387&view=rev > Log: > LUCENE-2053 (on back compat branch): fix intermittent bug in unit test > > Added: > > lucene/java/branches/lucene_2_9_back_compat_tests/src/java/org/apache/luce > ne/util/ThreadInterruptedException.java (with props) > Modified: > > lucene/java/branches/lucene_2_9_back_compat_tests/src/test/org/apache/luce > ne/index/TestIndexWriter.java > > Added: > lucene/java/branches/lucene_2_9_back_compat_tests/src/java/org/apache/luce > ne/util/ThreadInterruptedException.java > URL: > http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9_back_compat_t > ests/src/java/org/apache/lucene/util/ThreadInterruptedException.java?rev=8 > 36387&view=auto > ========================================================================== > ==== > --- > lucene/java/branches/lucene_2_9_back_compat_tests/src/java/org/apache/luce > ne/util/ThreadInterruptedException.java (added) > +++ > lucene/java/branches/lucene_2_9_back_compat_tests/src/java/org/apache/luce > ne/util/ThreadInterruptedException.java Sun Nov 15 18:35:06 2009 > @@ -0,0 +1,30 @@ > +package org.apache.lucene.util; > + > +/** > + * Licensed to the Apache Software Foundation (ASF) under one or more > + * contributor license agreements. See the NOTICE file distributed with > + * this work for additional information regarding copyright ownership. > + * The ASF licenses this file to You under the Apache License, Version > 2.0 > + * (the "License"); you may not use this file except in compliance with > + * the License. You may obtain a copy of the License at > + *

> + * http://www.apache.org/licenses/LICENSE-2.0 > + *

> + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or > implied. > + * See the License for the specific language governing permissions and > + * limitations under the License. > + */ > + > +/** > + * Thrown by lucene on detecting that Thread.interrupt() had > + * been called. Unlike Java's InterruptedException, this > + * exception is not checked.. > + */ > + > +public final class ThreadInterruptedException extends RuntimeException { > + public ThreadInterruptedException(InterruptedException ie) { > + super(ie); > + } > +} > > Propchange: > lucene/java/branches/lucene_2_9_back_compat_tests/src/java/org/apache/luce > ne/util/ThreadInterruptedException.java > -------------------------------------------------------------------------- > ---- > svn:eol-style = native > > Modified: > lucene/java/branches/lucene_2_9_back_compat_tests/src/test/org/apache/luce > ne/index/TestIndexWriter.java > URL: > http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9_back_compat_t > ests/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=836387&r1=8 > 36386&r2=836387&view=diff > ========================================================================== > ==== > --- > lucene/java/branches/lucene_2_9_back_compat_tests/src/test/org/apache/luce > ne/index/TestIndexWriter.java (original) > +++ > lucene/java/branches/lucene_2_9_back_compat_tests/src/test/org/apache/luce > ne/index/TestIndexWriter.java Sun Nov 15 18:35:06 2009 > @@ -67,6 +67,7 @@ > import org.apache.lucene.util.UnicodeUtil; > import org.apache.lucene.util._TestUtil; > import org.apache.lucene.util.Version; > +import org.apache.lucene.util.ThreadInterruptedException; > > /** > * > @@ -4347,26 +4348,61 @@ > private class IndexerThreadInterrupt extends Thread { > volatile boolean failed; > volatile boolean finish; > + > + boolean allowInterrupt = false; > + > public void run() { > RAMDirectory dir = new RAMDirectory(); > IndexWriter w = null; > + boolean first = true; > while(!finish) { > try { > - //IndexWriter.unlock(dir); > - w = new IndexWriter(dir, new WhitespaceAnalyzer(), > IndexWriter.MaxFieldLength.UNLIMITED); > - ((ConcurrentMergeScheduler) > w.getMergeScheduler()).setSuppressExceptions(); > - //w.setInfoStream(System.out); > - w.setMaxBufferedDocs(2); > - w.setMergeFactor(2); > - Document doc = new Document(); > - doc.add(new Field("field", "some text contents", > Field.Store.YES, Field.Index.ANALYZED)); > - for(int i=0;i<100;i++) { > - w.addDocument(doc); > - w.commit(); > + > + while(true) { > + if (w != null) { > + w.close(); > + } > + w = new IndexWriter(dir, new WhitespaceAnalyzer(), > IndexWriter.MaxFieldLength.UNLIMITED); > + > + //((ConcurrentMergeScheduler) > w.getMergeScheduler()).setSuppressExceptions(); > + if (!first && !allowInterrupt) { > + // tell main thread it can interrupt us any time, > + // starting now > + allowInterrupt = true; > + } > + > + w.setMaxBufferedDocs(2); > + w.setMergeFactor(2); > + Document doc = new Document(); > + doc.add(new Field("field", "some text contents", > Field.Store.YES, Field.Index.ANALYZED)); > + for(int i=0;i<100;i++) { > + w.addDocument(doc); > + w.commit(); > + } > + w.close(); > + _TestUtil.checkIndex(dir); > + IndexReader.open(dir, true).close(); > + > + if (first && !allowInterrupt) { > + // Strangely, if we interrupt a thread before > + // all classes are loaded, the class loader > + // seems to do scary things with the interrupt > + // status. In java 1.5, it'll throw an > + // incorrect ClassNotFoundException. In java > + // 1.6, it'll silently clear the interrupt. > + // So, on first iteration through here we > + // don't open ourselves up for interrupts > + // until we've done the above loop. > + allowInterrupt = true; > + first = false; > + } > } > - } catch (RuntimeException re) { > + } catch (ThreadInterruptedException re) { > Throwable e = re.getCause(); > assertTrue(e instanceof InterruptedException); > + if (finish) { > + break; > + } > > // Make sure IW cleared the interrupted bit > if (interrupted()) { > @@ -4375,26 +4411,12 @@ > failed = true; > break; > } > + > } catch (Throwable t) { > System.out.println("FAILED; unexpected exception"); > t.printStackTrace(System.out); > failed = true; > break; > - } finally { > - try { > - // Clear interrupt if pending > - synchronized(this) { > - interrupted(); > - if (w != null) { > - w.close(); > - } > - } > - } catch (Throwable t) { > - System.out.println("FAILED; unexpected exception during > close"); > - t.printStackTrace(System.out); > - failed = true; > - break; > - } > } > } > > @@ -4423,21 +4445,28 @@ > IndexerThreadInterrupt t = new IndexerThreadInterrupt(); > t.setDaemon(true); > t.start(); > - for(int i=0;i<100;i++) { > + > + // issue 100 interrupts to child thread > + int i = 0; > + while(i < 100) { > Thread.sleep(1); > - synchronized(t) { > + > + if (t.allowInterrupt) { > + i++; > + t.allowInterrupt = false; > t.interrupt(); > } > + if (!t.isAlive()) { > + break; > + } > } > + t.allowInterrupt = false; > t.finish = true; > - synchronized(t) { > - t.interrupt(); > - } > + t.interrupt(); > t.join(); > assertFalse(t.failed); > } > > - > public void testIndexStoreCombos() throws Exception { > MockRAMDirectory dir = new MockRAMDirectory(); > IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), true, > IndexWriter.MaxFieldLength.UNLIMITED); > --------------------------------------------------------------------- To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org For additional commands, e-mail: java-dev-help@lucene.apache.org