-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to test Hibernate Search?
PostPosted: Fri Mar 12, 2010 8:46 pm 
Regular
Regular

Joined: Mon Mar 10, 2008 6:40 pm
Posts: 114
How do you test search with Hibernate Search? What happens is the following:
1) I add 5 entities to the DB
2) I manually flush to indexes so that these entities get written into the index directory
3) the core of the test gets executed
4) after the test is executed the entire transaction is rolled back (I'm using Spring to write my tests)
5) the index directory never gets rolled back.

So the problem is that after the test runs and the transaction gets rolled back the indexes are not rolled back to their previous state. How can I flush to indexes/commit/rollback the transaction so that the indexes are rolled back too?


Top
 Profile  
 
 Post subject: Re: How to test Hibernate Search?
PostPosted: Sat Mar 13, 2010 9:51 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi mueller,
Lucene operations can't be rolled back; as of Lucene's API you could rollback changes you're applying to the index, but you can't search on them until a commit: so to be able to try out searches the changes need to be committed, using flush will push pending changes to the backend (IndexWriter in default conf) and commit the operation so when using rollback you won't undo flushed changes.

Quote:
How do you test search with Hibernate Search?

For example tests you can find many in the framework testsuite itself, it was designed so that most tests can be used as API usage examples;
you can start by looking around here, organized per functional areas in sub-packages:
http://fisheye.jboss.org/browse/Hiberna ... earch/test
or take a simple query example:
http://fisheye.jboss.org/browse/~raw,r= ... nTest.java

I'd suggest you checkout the code to look around in your ide, and then copy and adapt the SearchTest as you need into your project; the approach it uses is to create an in memory database and in memory index to run each test in isolation - cleaning up these resources at the end of each test, the drawback is that testsuite needs a full minute to run all 191 tests, but each test can override anything it needs: avoid the database, use a real (non-volatile) database, use a filesystem index, use a different configuration...
You don't need to use rollback strategies and can go for a complete use case scenario.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.