lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anuj Shah <anujshahw...@gmail.com>
Subject Re: AssertionError
Date Mon, 31 Jan 2011 17:21:01 GMT
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 <anujshahwork@gmail.com> 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 <uwe@thetaphi.de> wrote:
>
>> Hi,
>>
>> I don't know Mockito, but the javadocs explains everything:
>>
>> http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html#spy(T)<http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html#spy%28T%29>
>>
>> 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 <uwe@thetaphi.de>
>> > 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
>>
>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message