lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Hogan" ...@mikehogan.net>
Subject Re: [subscriptions] Please make org.apache.lucene.index.IndexWriter non-final
Date Sun, 05 Oct 2003 21:24:08 GMT
Erik,

Erik,

> > public class LuceneSearchService implements SearchService {
> >     private static final String INDEX_FILE_PATH = "index";
> >     private Context context = new DefaultContext();
> >
> >     public void setContext(Context c) {
> >         this.context = c;
> >     }
> >
> > public void index(String componentId, String componentDescription)
> > throws
> > SearchService.Exception {
> >         IndexWriter writer = null;
> >         try {
> >             writer = context.createIndexWriter(INDEX_FILE_PATH, new
> > StandardAnalyzer(), !indexExists());
>
> Take this a step further, and have a createDirectory instead, that can
> return a RAMDirectory.  Forget about a MockIndexWriter.  Trust me :)

I understand what you are saying here, it is a good point and I will try to
work it into what I am doing.  But installing a createDirectory() method and
using a RAMDirectory will not help me verify() that IndexWriter.close() is
called when an IOException is thrown.  MockIndexWriter gives me more
control.

> You just aren't seeing the forest from the trees here.  You need to
> refactor and just let IndexWriter be internal and not mocked, but how
> you get at a Directory be flexible for testing.  Even if you always use
> a file system directory even for testing, I highly recommend you bind
> to abstractions not concreteness.  Bind to Directory, not IndexWriter
> as your "interface".

Yes, I will do this.  Its is more flexible for sure.  But I still need
MockIndexWriter for the control I talk about above.

Cheers,
Mike.


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message