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: u...@thetaphi.de

> -----Original Message-----
> From: Anuj Shah [mailto:anujshahw...@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 <
> luc...@mikemccandless.com> wrote:
> 
> > ... and also the full exception?
> >
> > Mike
> >
> > On Tue, Jan 25, 2011 at 11:52 AM, Uwe Schindler <u...@thetaphi.de>
> wrote:
> > > Can you post your code?
> > >
> > > -----
> > > Uwe Schindler
> > > H.-H.-Meier-Allee 63, D-28213 Bremen
> > > http://www.thetaphi.de
> > > eMail: u...@thetaphi.de
> > >
> > >
> > >> -----Original Message-----
> > >> From: Anuj Shah [mailto:anujshahw...@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-unsubscr...@lucene.apache.org
> > > For additional commands, e-mail: java-user-h...@lucene.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
> > For additional commands, e-mail: java-user-h...@lucene.apache.org
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to