[hibernate-commits] Hibernate SVN: r19207 - in search/trunk/hibernate-search/src/test/java/org/hibernate/search/test: worker and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Apr 9 23:09:03 EDT 2010


Author: stliu
Date: 2010-04-09 23:09:01 -0400 (Fri, 09 Apr 2010)
New Revision: 19207

Modified:
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/ReaderPerfTestCase.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java
Log:
HSEARCH-496  Some hudson configurations need more time to run the testsuite

Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/ReaderPerfTestCase.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/ReaderPerfTestCase.java	2010-04-09 19:34:07 UTC (rev 19206)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/ReaderPerfTestCase.java	2010-04-10 03:09:01 UTC (rev 19207)
@@ -29,6 +29,7 @@
 import java.util.Random;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.lucene.analysis.StopAnalyzer;
 import org.apache.lucene.queryParser.MultiFieldQueryParser;
@@ -125,7 +126,7 @@
 			es.execute( work );
 			es.execute( reverseWork );
 		}
-		while ( work.count < iteration - 1 ) {
+		while ( work.count.get() < iteration - 1 ) {
 			Thread.sleep( 20 );
 		}
 		log.debug( iteration + " iterations in " + nThreads + " threads: " + ( System.currentTimeMillis() - start ) );
@@ -134,53 +135,71 @@
 	protected class Work implements Runnable {
 		private Random random = new Random();
 		private SessionFactory sf;
-		public volatile int count = 0;
+//		public volatile int count = 0;
+		public AtomicInteger count = new AtomicInteger(0);
 
 		public Work(SessionFactory sf) {
 			this.sf = sf;
 		}
 
 		public void run() {
-			Session s = sf.openSession();
-			Transaction tx = s.beginTransaction();
-			QueryParser parser = new MultiFieldQueryParser( getTargetLuceneVersion(),
-					new String[] { "name", "physicalDescription", "suspectCharge" },
-					SearchTestCase.standardAnalyzer
-			);
-			FullTextQuery query = getQuery( "John Doe", parser, s );
-			assertTrue( query.getResultSize() != 0 );
+			Session s = null;
+			Transaction tx = null;
+			try {
+				s = sf.openSession();
+				tx = s.beginTransaction();
+				QueryParser parser = new MultiFieldQueryParser( getTargetLuceneVersion(),
+						new String[] { "name", "physicalDescription", "suspectCharge" },
+						SearchTestCase.standardAnalyzer );
+				FullTextQuery query = getQuery( "John Doe", parser, s );
+				assertTrue( query.getResultSize() != 0 );
 
-			query = getQuery( "green", parser, s );
-			random.nextInt( query.getResultSize() - 15 );
-			query.setFirstResult( random.nextInt( query.getResultSize() - 15 ) );
-			query.setMaxResults( 10 );
-			query.list();
-			tx.commit();
-			s.close();
+				query = getQuery( "green", parser, s );
+				random.nextInt( query.getResultSize() - 15 );
+				query.setFirstResult( random.nextInt( query.getResultSize() - 15 ) );
+				query.setMaxResults( 10 );
+				query.list();
+				tx.commit();
+				s.close();
 
-			s = sf.openSession();
-			tx = s.beginTransaction();
+				s = sf.openSession();
+				tx = s.beginTransaction();
 
-			query = getQuery( "John Doe", parser, s );
-			assertTrue( query.getResultSize() != 0 );
+				query = getQuery( "John Doe", parser, s );
+				assertTrue( query.getResultSize() != 0 );
 
-			query = getQuery( "thief", parser, s );
-			int firstResult = random.nextInt( query.getResultSize() - 15 );
-			query.setFirstResult( firstResult );
-			query.setMaxResults( 10 );
-			List result = query.list();
-			Object object = result.get( 0 );
-			if ( insert && object instanceof Detective ) {
-				Detective detective = ( Detective ) object;
-				detective.setPhysicalDescription( detective.getPhysicalDescription() + " Eye" + firstResult );
+				query = getQuery( "thief", parser, s );
+				int firstResult = random.nextInt( query.getResultSize() - 15 );
+				query.setFirstResult( firstResult );
+				query.setMaxResults( 10 );
+				List result = query.list();
+				Object object = result.get( 0 );
+				if ( insert && object instanceof Detective ) {
+					Detective detective = (Detective) object;
+					detective.setPhysicalDescription( detective.getPhysicalDescription() + " Eye"
+							+ firstResult );
+				}
+				else if ( insert && object instanceof Suspect ) {
+					Suspect suspect = (Suspect) object;
+					suspect.setPhysicalDescription( suspect.getPhysicalDescription() + " Eye"
+							+ firstResult );
+				}
+				tx.commit();
+				s.close();
+				// count++;
+			} catch ( Throwable t ) {
+				t.printStackTrace();
+			} finally {
+				count.incrementAndGet();
+				try {
+					if ( tx != null && tx.isActive() )
+						tx.rollback();
+					if ( s != null && s.isOpen() )
+						s.close();
+				} catch ( Throwable t ) {
+					t.printStackTrace();
+				}
 			}
-			else if ( insert && object instanceof Suspect ) {
-				Suspect suspect = ( Suspect ) object;
-				suspect.setPhysicalDescription( suspect.getPhysicalDescription() + " Eye" + firstResult );
-			}
-			tx.commit();
-			s.close();
-			count++;
 		}
 
 		private FullTextQuery getQuery(String queryString, QueryParser parser, Session s) {

Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java	2010-04-09 19:34:07 UTC (rev 19206)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java	2010-04-10 03:09:01 UTC (rev 19207)
@@ -27,6 +27,7 @@
 import java.io.File;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.lucene.analysis.StopAnalyzer;
 import org.apache.lucene.queryParser.ParseException;
@@ -77,7 +78,7 @@
 			es.execute( work );
 			es.execute( reverseWork );
 		}
-		while ( work.count < iteration - 1 ) {
+		while ( work.count.get() < iteration - 1 ) {
 			Thread.sleep( 20 );
 		}
 		getSessions().close();
@@ -87,66 +88,85 @@
 
 	protected static class Work implements Runnable {
 		private SessionFactory sf;
-		public volatile int count = 0;
+		//public volatile int count = 0;
+		public AtomicInteger count = new AtomicInteger(0);
 
 		public Work(SessionFactory sf) {
 			this.sf = sf;
 		}
 
 		public void run() {
-			Session s = sf.openSession();
-			Transaction tx = s.beginTransaction();
-			Employee ee = new Employee();
-			ee.setName( "Emmanuel" );
-			s.persist( ee );
-			Employer er = new Employer();
-			er.setName( "RH" );
-			s.persist( er );
-			tx.commit();
-			s.close();
+			Session s = null;
+			Transaction tx = null;
+			try {
+				s = sf.openSession();
+				tx = s.beginTransaction();
+				Employee ee = new Employee();
+				ee.setName( "Emmanuel" );
+				s.persist( ee );
+				Employer er = new Employer();
+				er.setName( "RH" );
+				s.persist( er );
+				tx.commit();
+				s.close();
 
-			s = sf.openSession();
-			tx = s.beginTransaction();
-			ee = (Employee) s.get( Employee.class, ee.getId() );
-			ee.setName( "Emmanuel2" );
-			er = (Employer) s.get( Employer.class, er.getId() );
-			er.setName( "RH2" );
-			tx.commit();
-			s.close();
+				s = sf.openSession();
+				tx = s.beginTransaction();
+				ee = (Employee) s.get( Employee.class, ee.getId() );
+				ee.setName( "Emmanuel2" );
+				er = (Employer) s.get( Employer.class, er.getId() );
+				er.setName( "RH2" );
+				tx.commit();
+				s.close();
 
-//			try {
-//				Thread.sleep( 50 );
-//			}
-//			catch (InterruptedException e) {
-//				e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-//			}
+				// try {
+				// Thread.sleep( 50 );
+				// }
+				// catch (InterruptedException e) {
+				// e.printStackTrace(); //To change body of catch statement use
+				// File | Settings | File Templates.
+				// }
 
-			s = sf.openSession();
-			tx = s.beginTransaction();
-			FullTextSession fts = new FullTextSessionImpl( s );
-			QueryParser parser = new QueryParser( getTargetLuceneVersion(), "id", SearchTestCase.stopAnalyzer );
-			Query query;
-			try {
-				query = parser.parse( "name:emmanuel2" );
+				s = sf.openSession();
+				tx = s.beginTransaction();
+				FullTextSession fts = new FullTextSessionImpl( s );
+				QueryParser parser = new QueryParser( getTargetLuceneVersion(), "id",
+						SearchTestCase.stopAnalyzer );
+				Query query;
+				try {
+					query = parser.parse( "name:emmanuel2" );
+				} catch ( ParseException e ) {
+					throw new RuntimeException( e );
+				}
+				boolean results = fts.createFullTextQuery( query ).list().size() > 0;
+				// don't test because in case of async, it query happens before
+				// actual saving
+				// if ( !results ) throw new RuntimeException( "No results!" );
+				tx.commit();
+				s.close();
+
+				s = sf.openSession();
+				tx = s.beginTransaction();
+				ee = (Employee) s.get( Employee.class, ee.getId() );
+				s.delete( ee );
+				er = (Employer) s.get( Employer.class, er.getId() );
+				s.delete( er );
+				tx.commit();
+				s.close();
+				// count++;
+			} catch ( Throwable t ) {
+				t.printStackTrace();
+			} finally {
+				count.incrementAndGet();
+				try {
+					if ( tx != null && tx.isActive() )
+						tx.rollback();
+					if ( s != null && s.isOpen() )
+						s.close();
+				} catch ( Throwable t ) {
+					t.printStackTrace();
+				}
 			}
-			catch (ParseException e) {
-				throw new RuntimeException( e );
-			}
-			boolean results = fts.createFullTextQuery( query ).list().size() > 0;
-			//don't test because in case of async, it query happens before actual saving
-			//if ( !results ) throw new RuntimeException( "No results!" );
-			tx.commit();
-			s.close();
-
-			s = sf.openSession();
-			tx = s.beginTransaction();
-			ee = (Employee) s.get( Employee.class, ee.getId() );
-			s.delete( ee );
-			er = (Employer) s.get( Employer.class, er.getId() );
-			s.delete( er );
-			tx.commit();
-			s.close();
-			count++;
 		}
 	}
 



More information about the hibernate-commits mailing list