Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 82442 invoked from network); 31 Jan 2011 17:21:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 31 Jan 2011 17:21:35 -0000 Received: (qmail 99718 invoked by uid 500); 31 Jan 2011 17:21:33 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 99401 invoked by uid 500); 31 Jan 2011 17:21:30 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 99392 invoked by uid 99); 31 Jan 2011 17:21:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Jan 2011 17:21:29 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of anujshahwork@gmail.com designates 209.85.214.176 as permitted sender) Received: from [209.85.214.176] (HELO mail-iw0-f176.google.com) (209.85.214.176) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Jan 2011 17:21:22 +0000 Received: by iwn2 with SMTP id 2so6230631iwn.35 for ; Mon, 31 Jan 2011 09:21:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=R/5crQd9HYtxLAvgN/Xlhp7b2VYUYWVEJmXUH9T/Hio=; b=HLxJ5dxTIORYQ2BVtKUFnprgMMGVTzNNHcclFfurCVDd3sFPs0Rcy+siYKibu5fyvT XQZfDR/xlNlKEeiXWgv+rxmN+H7aWJXtB+vsuBsH5mDQ4QkvLaqZo4ZRfuIIU0MI0g+5 vwOFuc2RlREtexlwYZXh6eNd9NYfdnOv96LU0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=o7KojxtjI6n1DF0FqXuvODO5O/vNZLOIxLs+ou/Iw9CA+WotW4MA0brQ9MyJdJ0zcw mtLcWsp1WUKzK0Mf9MJzcuC9RIRlg3xuUhzACTPuYx5OBmut60NqcCUh8lPAbGEafSQu zc67sxFIBKX9+KPgJSXCaMy79MEhhVvOTOn6w= MIME-Version: 1.0 Received: by 10.231.16.132 with SMTP id o4mr6919108iba.154.1296494461159; Mon, 31 Jan 2011 09:21:01 -0800 (PST) Received: by 10.231.208.81 with HTTP; Mon, 31 Jan 2011 09:21:01 -0800 (PST) In-Reply-To: References: <008c01cbbcb0$2fb7c5f0$8f2751d0$@thetaphi.de> <000a01cbbd56$27811840$768348c0$@thetaphi.de> Date: Mon, 31 Jan 2011 17:21:01 +0000 Message-ID: Subject: Re: AssertionError From: Anuj Shah To: java-user@lucene.apache.org Content-Type: multipart/alternative; boundary=0022152d7e0bcf8991049b27a354 X-Virus-Checked: Checked by ClamAV on apache.org --0022152d7e0bcf8991049b27a354 Content-Type: text/plain; charset=ISO-8859-1 On this issue, I ended up writing a simple interface and delegating proxy to use for calls to IndexWriter methods. It would be nice if future versions had an interface architecture around key components to promote unit testing. On 26 January 2011 17:27, Anuj Shah wrote: > Thanks Uwe, that does explain why it fails. > > Unfortunately, modifying third party libraries is somehting that will need > a lot of justification for our management. It would be easier on my part to > change our test behaviour to not partial mock. IndexWriter was > originally difficult for us to mock for two reasons: > 1) There is no interface > 2) The commit method is final > > I'll have a deeper dig into these. > > On 26 January 2011 12:40, Uwe Schindler wrote: > >> Hi, >> >> I don't know Mockito, but the javadocs explains everything: >> >> http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html#spy(T) >> >> IndexWriter is very sensitive to locking, so when the mocked >> implementation >> does not lock on the real IndexWriter itself but instead on itself >> (because >> the mock is synchronized on itself) you would violate this asserting. I >> also >> expect that later (when assertions are disabled), your whole IndexWriter >> will deadlock. >> >> Why do you want to intercept calls to IW? The warning in the javadocs says >> everything: " Partial mock usually means that the complexity has been >> moved >> to a different method on the same object. >> In most cases, this is not the way you want to design your application. >> However, there are rare cases when partial mocks come handy: dealing with >> code you cannot change easily (3rd party interfaces, interim refactoring >> of >> legacy code etc.). However, I wouldn't use partial mocks for new, >> test-driven & well-designed code." >> >> Does any of this apply to Lucene? It's open source, so you can look into >> source code and even change it! >> >> Uwe >> >> ----- >> Uwe Schindler >> H.-H.-Meier-Allee 63, D-28213 Bremen >> http://www.thetaphi.de >> eMail: uwe@thetaphi.de >> >> > -----Original Message----- >> > From: Anuj Shah [mailto:anujshahwork@gmail.com] >> > Sent: Wednesday, January 26, 2011 1:20 PM >> > To: java-user@lucene.apache.org >> > Subject: Re: AssertionError >> > >> > It looks like Mockito is the culprit here. >> > >> > Code fragment causing error: >> > >> > final IndexWriter indexWriter = Mockito.spy(new >> > > IndexWriter(FSDirectory.open(new File("")), new >> > > StandardAnalyzer(Version.LUCENE_30), MaxFieldLength.LIMITED)); >> > > indexWriter.addDocument(new Document()); indexWriter.commit(); >> > > >> > >> > >> > Stack trace: >> > java.lang.AssertionError >> > at >> > org.apache.lucene.index.IndexWriter$ReaderPool.commit(IndexWriter.java: >> > 557) >> > at >> > org.apache.lucene.index.IndexWriter.startCommit(IndexWriter.java:4737) >> > at >> > org.apache.lucene.index.IndexWriter.prepareCommit(IndexWriter.java:3461 >> > ) >> > at org.apache.lucene.index.IndexWriter.commit(IndexWriter.java:3534) >> > at org.apache.lucene.index.IndexWriter.commit(IndexWriter.java:3505) >> > at myTestClass.test(myTestClass.java:10) >> > >> > >> > On Tue, Jan 25, 2011 at 6:37 PM, Michael McCandless < >> > lucene@mikemccandless.com> wrote: >> > >> > > ... and also the full exception? >> > > >> > > Mike >> > > >> > > On Tue, Jan 25, 2011 at 11:52 AM, Uwe Schindler >> > wrote: >> > > > Can you post your code? >> > > > >> > > > ----- >> > > > Uwe Schindler >> > > > H.-H.-Meier-Allee 63, D-28213 Bremen >> > > > http://www.thetaphi.de >> > > > eMail: uwe@thetaphi.de >> > > > >> > > > >> > > >> -----Original Message----- >> > > >> From: Anuj Shah [mailto:anujshahwork@gmail.com] >> > > >> Sent: Tuesday, January 25, 2011 5:18 PM >> > > >> To: java-user@lucene.apache.org >> > > >> Subject: AssertionError >> > > >> >> > > >> Hi, >> > > >> >> > > >> I've upgraded from 3.00 to 3.0.3 and am now hitting assertion >> errors >> > > from >> > > >> IndexWriter.ReaderPool.commit, at this line: >> > > >> >> > > >> // We invoke deleter.checkpoint below, so we must be >> > > >> > // sync'd on IW: >> > > >> > assert Thread.holdsLock(IndexWriter.this); >> > > >> > >> > > >> >> > > >> Has anyone encountered this before? I'm hoping this is a common >> > scenario >> > > >> and there is a quick fix to avoid it. >> > > >> >> > > >> Thanks >> > > >> >> > > >> Anuj >> > > > >> > > > >> > > > >> --------------------------------------------------------------------- >> > > > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org >> > > > For additional commands, e-mail: java-user-help@lucene.apache.org >> > > > >> > > > >> > > >> > > --------------------------------------------------------------------- >> > > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org >> > > For additional commands, e-mail: java-user-help@lucene.apache.org >> > > >> > > >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org >> For additional commands, e-mail: java-user-help@lucene.apache.org >> >> > --0022152d7e0bcf8991049b27a354--