Java Mailing List Archive

http://www.gg3721.com/

Home » Hibernate Commits List »

[hibernate-commits] Hibernate SVN: r14926 - in search/trunk:
 src/test/org/hibernate/search/test and 8 other directories.

hibernate-commits

2008-07-14


Author LoginPost Reply
Author: hardy.ferentschik
Date: 2008-07-14 09:41:14 -0400 (Mon, 14 Jul 2008)
New Revision: 14926

Modified:
 search/trunk/build.xml
 search/trunk/src/test/org/hibernate/search/test/FSDirectoryTest.java
 search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
 search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java
 search/trunk/src/test/org/hibernate/search/test/directoryProvider/FSSlaveAndMasterDPTest.java
 search/trunk/src/test/org/hibernate/search/test/optimizer/OptimizerTestCase.java
 search/trunk/src/test/org/hibernate/search/test/reader/ReaderPerfTestCase.java
 search/trunk/src/test/org/hibernate/search/test/reader/performance/ReaderPerformance.java
 search/trunk/src/test/org/hibernate/search/test/session/OptimizeTest.java
 search/trunk/src/test/org/hibernate/search/test/shards/ShardsTest.java
 search/trunk/src/test/org/hibernate/search/test/worker/WorkerTestCase.java
Log:
- Refactored build and tests so that test indexes get created in the 'build' directory.
- Added getBaseIndexDir() to SearchTestCase
- cleanup of build.xml

Modified: search/trunk/build.xml
===================================================================
--- search/trunk/build.xml  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/build.xml  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
     <fileset dir="${lib.dir}">
        <include name="*.jar"/>
     </fileset>
-    <path refid="lib.moduleclass.path"/>
   <pathelement path="${clover.jar}"/>
  </path>
-
-   <path id="lib.moduleclass.path">
-    <!-- pathelement location="${jpa-api.jar}"/>
-    <pathelement location="${commons-annotations.jar}"/ -->
-     <!-- fileset dir="${ivy.dep.dir}/core">
-      <include name="*.jar"/>
-    </fileset -->
-   </path>
 
 <path id="junit.moduleclasspath">
     <!-- order matters for JBoss XB proper bootstrap -->
@@(protected) @@
             <include name="**/*.zip"/>
          </fileset>
        </classpath>
+      <sysproperty key="build.dir" value="${build.dir}"/>
        <formatter type="plain"/>
        <formatter type="xml"/>
        <batchtest fork="yes" todir="${testreports.dir}" haltonfailure="no">
@@(protected) @@
             <include name="**/*.zip"/>
          </fileset>
        </classpath>
+      <sysproperty key="build.dir" value="${build.dir}"/>
        <formatter type="plain"/>
     <formatter type="xml"/>
     <test fork="yes" todir="${testreports.dir}" haltonfailure="no" name="${testname}"/>
@@(protected) @@
     />
  </target>

-  <!-- target name="javadoc" description="Compile the Javadoc API documentation to dist dir">
-        <echo>Skipping java doc since ant's javadoc task cannot handle an alternative javadoc</echo>
-     </target -->
-
-
 <!-- Some of this can probably be moved to common-build... -->
 <target name="dist" depends="get.deps.core,get.deps.test,jar,jar,javadoc,copysource,copytest,copylib,extras"
     description="Build everything">


Property changes on: search/trunk/build.xml
___________________________________________________________________
Name: svn:keywords
 + Id

Modified: search/trunk/src/test/org/hibernate/search/test/FSDirectoryTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/FSDirectoryTest.java  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/src/test/org/hibernate/search/test/FSDirectoryTest.java  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
   buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
 }

-  private File getBaseIndexDir() {
-    File current = new File( "." );
-    return new File( current, "indextemp" );
-  }
-
 protected void tearDown() throws Exception {
   super.tearDown();
   File sub = getBaseIndexDir();

Modified: search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
//$Id$
package org.hibernate.search.test;

+import java.io.File;
+
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.store.Directory;
import org.hibernate.HibernateException;
@@(protected) @@
import org.hibernate.search.Environment;
import org.hibernate.search.event.FullTextIndexEventListener;
import org.hibernate.search.store.RAMDirectoryProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;

/**
+ * Base class for Hibernate Search unit tests.
+ *
* @author Emmanuel Bernard
*/
public abstract class SearchTestCase extends HANTestCase {
+  
+  private static final Logger log = LoggerFactory
+      .getLogger(SearchTestCase.class);
+  
+  private static File indexDir;
+  static {
+    String buildDir = System.getProperty("build.dir");
+    if (buildDir == null) {
+      buildDir = ".";
+    }
+    File current = new File( buildDir );
+    indexDir = new File( current, "indextemp" );
+    log.debug("Using {} as index directory.", indexDir.getAbsolutePath());
+  }
+  
 protected void setUp() throws Exception {
   //super.setUp(); //we need a fresh session factory each time for index set up
   buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
 }

+  @SuppressWarnings("unchecked")
 protected Directory getDirectory(Class clazz) {
   return getLuceneEventListener().getSearchFactoryImplementor().getDirectoryProviders( clazz )[0].getDirectory();
 }
@@(protected) @@
   cfg.setProperty( "hibernate.search.default.transaction.merge_factor", "100" );
   cfg.setProperty( "hibernate.search.default.batch.max_buffered_docs", "1000" );
 }
+  
+  protected File getBaseIndexDir() {
+    return indexDir;
+  }
}

Modified: search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
package org.hibernate.search.test.configuration;

-import java.io.File;
-
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.backend.configuration.IndexWriterSetting;
@@(protected) @@
* @author Sanne Grinovero
*/
public abstract class ConfigurationReadTestCase extends SearchTestCase {
-  
-  private static final File INDEX_DIR = new File( new File( "." ), "indextemp" );

 private SearchFactoryImplementor searchFactory;

 protected enum TransactionType {
   TRANSACTION, BATCH
 }
+  
+  public ConfigurationReadTestCase() {
+    
+  }

 @Override
 protected void setUp() throws Exception {
@@(protected) @@
   FullTextSession fullTextSession = Search.getFullTextSession( openSession() );
   searchFactory = (SearchFactoryImpl) fullTextSession.getSearchFactory();
   fullTextSession.close();
-    FileHelper.delete( INDEX_DIR );
-    INDEX_DIR.mkdirs();
+    FileHelper.delete( getBaseIndexDir() );
+    getBaseIndexDir().mkdirs();
 }

 protected final void assertValueIsDefault(Class testEntity, TransactionType parmGroup, IndexWriterSetting setting) {
@@(protected) @@
 
 protected void configure(org.hibernate.cfg.Configuration cfg) {
   super.configure( cfg );
-    cfg.setProperty( "hibernate.search.default.indexBase", INDEX_DIR.getAbsolutePath() );
+    cfg.setProperty( "hibernate.search.default.indexBase", getBaseIndexDir().getAbsolutePath() );
 }
 
 protected void tearDown() throws Exception {
   super.tearDown();
-    FileHelper.delete( INDEX_DIR );
+    FileHelper.delete( getBaseIndexDir() );
 }

}


Property changes on: search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java
___________________________________________________________________
Name: svn:keywords
 + Id

Modified: search/trunk/src/test/org/hibernate/search/test/directoryProvider/FSSlaveAndMasterDPTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/directoryProvider/FSSlaveAndMasterDPTest.java  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/src/test/org/hibernate/search/test/directoryProvider/FSSlaveAndMasterDPTest.java  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
* @author Emmanuel Bernard
*/
public class FSSlaveAndMasterDPTest extends MultipleSFTestCase {
+  
+  private static File root;
+  static {
+    String buildDir = System.getProperty("build.dir");
+    if (buildDir == null) {
+      buildDir = ".";
+    }
+    root = new File(buildDir, "lucenedirs");
+  }

 @SuppressWarnings( { "PointlessArithmeticExpression" } )
 public void testProperCopy() throws Exception {
@@(protected) @@
 }

 protected void setUp() throws Exception {
-    File base = new File(".");
-    File root = new File(base, "lucenedirs");
   root.mkdir();

   File master = new File(root, "master/main");
@@(protected) @@

 protected void tearDown() throws Exception {
   super.tearDown();
-    File base = new File(".");
-    File root = new File(base, "lucenedirs");
   FileHelper.delete( root );
 }

@@(protected) @@
   return 2;
 }

+  @SuppressWarnings("unchecked")
 protected Class[] getMappings() {
   return new Class[] {
       SnowStorm.class
@@(protected) @@

 protected void configure(Configuration[] cfg) {
   //master
-    cfg[0].setProperty( "hibernate.search.default.sourceBase", "./lucenedirs/master/copy");
-    cfg[0].setProperty( "hibernate.search.default.indexBase", "./lucenedirs/master/main");
+    cfg[0].setProperty( "hibernate.search.default.sourceBase", root.getAbsolutePath() + "/master/copy");
+    cfg[0].setProperty( "hibernate.search.default.indexBase", root.getAbsolutePath() + "/master/main");
   cfg[0].setProperty( "hibernate.search.default.refresh", "1"); //every minute
   cfg[0].setProperty( "hibernate.search.default.directory_provider", "org.hibernate.search.store.FSMasterDirectoryProvider");

   //slave(s)
-    cfg[1].setProperty( "hibernate.search.default.sourceBase", "./lucenedirs/master/copy");
-    cfg[1].setProperty( "hibernate.search.default.indexBase", "./lucenedirs/slave");
+    cfg[1].setProperty( "hibernate.search.default.sourceBase", root.getAbsolutePath() + "/master/copy");
+    cfg[1].setProperty( "hibernate.search.default.indexBase", root.getAbsolutePath() + "/slave");
   cfg[1].setProperty( "hibernate.search.default.refresh", "1"); //every minute
   cfg[1].setProperty( "hibernate.search.default.directory_provider", "org.hibernate.search.store.FSSlaveDirectoryProvider");
 }

Modified: search/trunk/src/test/org/hibernate/search/test/optimizer/OptimizerTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/optimizer/OptimizerTestCase.java  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/src/test/org/hibernate/search/test/optimizer/OptimizerTestCase.java  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
-//$Id$
+// $Id:$
package org.hibernate.search.test.optimizer;

import java.io.File;
@@(protected) @@
   buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
 }

-  @SuppressWarnings( { "UnnecessaryLocalVariable" } )
-  private File getBaseIndexDir() {
-    File current = new File( "." );
-    File sub = new File( current, "indextemp" );
-    return sub;
-  }
-
 protected void tearDown() throws Exception {
   super.tearDown();
   File sub = getBaseIndexDir();


Property changes on: search/trunk/src/test/org/hibernate/search/test/optimizer/OptimizerTestCase.java
___________________________________________________________________
Name: svn:keywords
 + Id

Modified: search/trunk/src/test/org/hibernate/search/test/reader/ReaderPerfTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/reader/ReaderPerfTestCase.java  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/src/test/org/hibernate/search/test/reader/ReaderPerfTestCase.java  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
   buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
 }

+  @SuppressWarnings("unchecked")
 protected Class[] getMappings() {
   return new Class[] {
       Detective.class,
@@(protected) @@
   };
 }

-  private File getBaseIndexDir() {
-    File current = new File( "." );
-    return new File( current, "indextemp" );
-  }
-
 protected void tearDown() throws Exception {
   super.tearDown();
   File sub = getBaseIndexDir();

Modified: search/trunk/src/test/org/hibernate/search/test/reader/performance/ReaderPerformance.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/reader/performance/ReaderPerformance.java  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/src/test/org/hibernate/search/test/reader/performance/ReaderPerformance.java  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
* @author Sanne Grinovero
*/
public abstract class ReaderPerformance extends SearchTestCase {
-  
-  private static final File baseIndexDir = new File( new File( "." ), "indextemp" );
-  
+    
 //more iterations for more reliable measures:
 private static final int TOTAL_WORK_BATCHES = 10;
 //the next 3 define the kind of workload mix to test on:
@@(protected) @@
 private static final int WARMUP_CYCLES = 6;
 
 protected void setUp() throws Exception {
+    File baseIndexDir = getBaseIndexDir();
   baseIndexDir.mkdir();
   File[] files = baseIndexDir.listFiles();
   for ( File file : files ) {
@@(protected) @@

 private void buildBigIndex() throws InterruptedException, CorruptIndexException, LockObtainFailedException, IOException {
   System.out.println( "Going to create fake index..." );
-    FSDirectory directory = FSDirectory.getDirectory(new File(baseIndexDir, Detective.class.getCanonicalName()));
+    FSDirectory directory = FSDirectory.getDirectory(new File(getBaseIndexDir(), Detective.class.getCanonicalName()));
   IndexWriter iw = new IndexWriter( directory, new SimpleAnalyzer(), true );
   IndexFillRunnable filler = new IndexFillRunnable( iw );
   ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool( WORKER_THREADS );
@@(protected) @@
   System.out.println( "Index created." );
 }

+  @SuppressWarnings("unchecked")
 protected Class[] getMappings() {
   return new Class[] {
       Detective.class,
@@(protected) @@

 protected void tearDown() throws Exception {
   super.tearDown();
-    FileHelper.delete( baseIndexDir );
+    FileHelper.delete( getBaseIndexDir() );
 }
 
 protected void configure(org.hibernate.cfg.Configuration cfg) {
   super.configure( cfg );
   cfg.setProperty( "hibernate.search.default.directory_provider", FSDirectoryProvider.class.getName() );
-    cfg.setProperty( "hibernate.search.default.indexBase", baseIndexDir.getAbsolutePath() );
+    cfg.setProperty( "hibernate.search.default.indexBase", getBaseIndexDir().getAbsolutePath() );
   cfg.setProperty( "hibernate.search.default.optimizer.transaction_limit.max", "10" ); // workaround too many open files
   cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
   cfg.setProperty( Environment.READER_STRATEGY, getReaderStrategyName() );


Property changes on: search/trunk/src/test/org/hibernate/search/test/reader/performance/ReaderPerformance.java
___________________________________________________________________
Name: svn:keywords
 + Id

Modified: search/trunk/src/test/org/hibernate/search/test/session/OptimizeTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/session/OptimizeTest.java  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/src/test/org/hibernate/search/test/session/OptimizeTest.java  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
-//$Id$
+// $Id:$
package org.hibernate.search.test.session;

import java.io.File;
@@(protected) @@
   buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
 }

-  private File getBaseIndexDir() {
-    File current = new File( "." );
-    return new File( current, "indextemp" );
-  }
-
 protected void tearDown() throws Exception {
   super.tearDown();
   File sub = getBaseIndexDir();
   FileHelper.delete( sub );
 }

+  @SuppressWarnings("unchecked")
 protected Class[] getMappings() {
   return new Class[] {
       Email.class,


Property changes on: search/trunk/src/test/org/hibernate/search/test/session/OptimizeTest.java
___________________________________________________________________
Name: svn:keywords
 + Id

Modified: search/trunk/src/test/org/hibernate/search/test/shards/ShardsTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/shards/ShardsTest.java  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/src/test/org/hibernate/search/test/shards/ShardsTest.java  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
-//$Id$
+// $Id:$
package org.hibernate.search.test.shards;

import java.io.File;
@@(protected) @@
   buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
 }

-  private File getBaseIndexDir() {
-    File current = new File( "." );
-    return new File( current, "indextemp" );
-  }
-
 protected void tearDown() throws Exception {
   super.tearDown();
   File sub = getBaseIndexDir();
   FileHelper.delete( sub );
 }

+  @SuppressWarnings("unchecked")
 protected Class[] getMappings() {
   return new Class[] {
       Animal.class,


Property changes on: search/trunk/src/test/org/hibernate/search/test/shards/ShardsTest.java
___________________________________________________________________
Name: svn:keywords
 + Id

Modified: search/trunk/src/test/org/hibernate/search/test/worker/WorkerTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/worker/WorkerTestCase.java  2008-07-14 09:03:49 UTC (rev 14925)
+++ search/trunk/src/test/org/hibernate/search/test/worker/WorkerTestCase.java  2008-07-14 13:41:14 UTC (rev 14926)
@@(protected) @@
   buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
 }

-  private File getBaseIndexDir() {
-    File current = new File( "." );
-    return new File( current, "indextemp" );
-  }
-
 protected void tearDown() throws Exception {
   super.tearDown();
   File sub = getBaseIndexDir();
@@(protected) @@
   cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
 }

+  @SuppressWarnings("unchecked")
 protected Class[] getMappings() {
   return new Class[]{
       Employee.class,

_______________________________________________
hibernate-commits mailing list
hibernate-commits@(protected)
https://lists.jboss.org/mailman/listinfo/hibernate-commits
©2008 gg3721.com - Jax Systems, LLC, U.S.A.