Author: epbernard
Date: 2009-11-20 06:21:01 -0500 (Fri, 20 Nov 2009)
New Revision: 18014
Added:
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ManualTransactionContext.java
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/StandaloneConf.java
Modified:
search/trunk/src/main/java/org/hibernate/search/backend/WorkQueue.java
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java
Log:
HSEARCH-419 proper provided id test not using the Hibernate Core backend.
Modified: search/trunk/src/main/java/org/hibernate/search/backend/WorkQueue.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/WorkQueue.java 2009-11-20
09:57:30 UTC (rev 18013)
+++ search/trunk/src/main/java/org/hibernate/search/backend/WorkQueue.java 2009-11-20
11:21:01 UTC (rev 18014)
@@ -26,6 +26,7 @@
import java.util.List;
import java.util.ArrayList;
+import java.util.Collections;
import org.hibernate.annotations.common.AssertionFailure;
@@ -73,7 +74,7 @@
public void setSealedQueue(List<LuceneWork> sealedQueue) {
//invalidate the working queue for serializability
- queue = null;
+ queue = Collections.EMPTY_LIST;
this.sealedQueue = sealedQueue;
}
Added:
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ManualTransactionContext.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ManualTransactionContext.java
(rev 0)
+++
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ManualTransactionContext.java 2009-11-20
11:21:01 UTC (rev 18014)
@@ -0,0 +1,39 @@
+package org.hibernate.search.test.id.providedId;
+
+import java.util.List;
+import java.util.ArrayList;
+import javax.transaction.Synchronization;
+import javax.transaction.Status;
+
+import org.hibernate.search.backend.TransactionContext;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ManualTransactionContext implements TransactionContext {
+ private boolean progress = true;
+ private List<Synchronization> syncs = new ArrayList<Synchronization>();
+
+ public boolean isTransactionInProgress() {
+ return progress;
+ }
+
+ public Object getTransactionIdentifier() {
+ return this;
+ }
+
+ public void registerSynchronization(Synchronization synchronization) {
+ syncs.add(synchronization);
+ }
+
+ public void end() {
+ this.progress = false;
+ for (Synchronization sync : syncs) {
+ sync.beforeCompletion();
+ }
+
+ for (Synchronization sync : syncs) {
+ sync.afterCompletion( Status.STATUS_COMMITTED );
+ }
+ }
+}
Modified:
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java 2009-11-20
09:57:30 UTC (rev 18013)
+++
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java 2009-11-20
11:21:01 UTC (rev 18014)
@@ -41,13 +41,13 @@
/**
* @author Navin Surtani
*/
-@Entity
+//@Entity
@ProvidedId(bridge = @FieldBridge(impl = LongBridge.class) )
@Indexed
public class ProvidedIdPerson implements Serializable {
- @Id
- @GeneratedValue
+// @Id
+// @GeneratedValue
private long id;
@Field(index = Index.TOKENIZED, store = Store.YES)
Modified:
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java 2009-11-20
09:57:30 UTC (rev 18013)
+++
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPersonSub.java 2009-11-20
11:21:01 UTC (rev 18014)
@@ -32,6 +32,5 @@
* @author Navin Surtani (<a
href="mailto:nsurtani@redhat.com">nsurtani@redhat.com</a>)
*/
@Indexed
-@Entity
public class ProvidedIdPersonSub extends ProvidedIdPerson {
}
Modified:
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java 2009-11-20
09:57:30 UTC (rev 18013)
+++
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java 2009-11-20
11:21:01 UTC (rev 18014)
@@ -34,22 +34,22 @@
import org.hibernate.Transaction;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
+import org.hibernate.search.SearchFactory;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkType;
+import org.hibernate.search.cfg.SearchConfiguration;
+import org.hibernate.search.impl.SearchFactoryImpl;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.test.SearchTestCase;
/**
* @author Navin Surtani
*/
-public class ProvidedIdTest extends SearchTestCase {
+public class ProvidedIdTest extends junit.framework.TestCase {
- protected Class[] getMappings() {
- return new Class[] {
- ProvidedIdPerson.class,
- ProvidedIdPersonSub.class
- };
- }
-
public void testProvidedId() throws Exception {
+ SearchFactoryImplementor sf = new SearchFactoryImpl( new StandaloneConf() );
ProvidedIdPerson person1 = new ProvidedIdPerson();
person1.setName( "Big Goat" );
@@ -63,17 +63,16 @@
person3.setName( "Regular goat" );
person3.setBlurb( "Is anorexic" );
- Session session = openSession();
- FullTextSession fullTextSession = Search.getFullTextSession( session );
- Transaction transaction = session.beginTransaction();
- session.persist( person1 );
- session.persist( person2 );
- session.persist( person3 );
+ ManualTransactionContext tc = new ManualTransactionContext();
- transaction.commit();
- session.clear();
+ Work<ProvidedIdPerson> work = new Work<ProvidedIdPerson>( person1, 1,
WorkType.INDEX );
+ sf.getWorker().performWork( work, tc );
+ work = new Work<ProvidedIdPerson>( person2, 2, WorkType.INDEX );
+ sf.getWorker().performWork( work, tc );
+ Work<ProvidedIdPersonSub> work2 = new Work<ProvidedIdPersonSub>( person3,
3, WorkType.INDEX );
+ sf.getWorker().performWork( work2, tc );
- transaction = fullTextSession.beginTransaction();
+ tc.end();
QueryParser parser = new QueryParser( "name", new StandardAnalyzer() );
Query luceneQuery = parser.parse( "Goat" );
@@ -82,15 +81,12 @@
//needs it. So we use plain Lucene
//we know there is only one DP
- DirectoryProvider provider = fullTextSession.getSearchFactory()
+ DirectoryProvider provider = sf
.getDirectoryProviders( ProvidedIdPerson.class )[0];
IndexSearcher searcher = new IndexSearcher( provider.getDirectory() );
TopDocs hits = searcher.search( luceneQuery, 1000 );
- searcher.close();
- transaction.commit();
- session.close();
-
assertEquals( 3, hits.totalHits );
+ searcher.close();
}
Added:
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/StandaloneConf.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/StandaloneConf.java
(rev 0)
+++
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/StandaloneConf.java 2009-11-20
11:21:01 UTC (rev 18014)
@@ -0,0 +1,60 @@
+package org.hibernate.search.test.id.providedId;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+
+import org.apache.lucene.analysis.StopAnalyzer;
+
+import org.hibernate.search.cfg.SearchConfiguration;
+import org.hibernate.search.cfg.SearchMapping;
+import org.hibernate.search.store.RAMDirectoryProvider;
+import org.hibernate.search.Environment;
+import org.hibernate.annotations.common.reflection.ReflectionManager;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class StandaloneConf implements SearchConfiguration {
+ final Map<String,Class<?>> classes;
+ final Properties properties;
+
+ public StandaloneConf() {
+ classes = new HashMap<String,Class<?>>(2);
+ classes.put( ProvidedIdPerson.class.getName(), ProvidedIdPerson.class );
+ classes.put( ProvidedIdPersonSub.class.getName(), ProvidedIdPersonSub.class );
+
+ properties = new Properties( );
+ properties.setProperty( "hibernate.search.default.directory_provider",
RAMDirectoryProvider.class.getName() );
+ properties.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
+ properties.setProperty( "hibernate.search.default.transaction.merge_factor",
"100" );
+ properties.setProperty( "hibernate.search.default.batch.max_buffered_docs",
"1000" );
+ }
+
+ public Iterator<Class<?>> getClassMappings() {
+ return classes.values().iterator();
+ }
+
+ public Class<?> getClassMapping(String name) {
+ return classes.get( name );
+ }
+
+ public String getProperty(String propertyName) {
+ return properties.getProperty( propertyName );
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ public ReflectionManager getReflectionManager() {
+ return null;
+ }
+
+ public SearchMapping getProgrammaticMapping() {
+ return null;
+ }
+}
Show replies by date