Author: stliu
Date: 2010-05-11 14:44:39 -0400 (Tue, 11 May 2010)
New Revision: 19468
Modified:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/SearchTestCase.java
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/TestCase.java
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java
Log:
JBPAPP-4289 HSEARCH-496 h-search test locks
Modified:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/SearchTestCase.java
===================================================================
---
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/SearchTestCase.java 2010-05-11
15:08:54 UTC (rev 19467)
+++
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/SearchTestCase.java 2010-05-11
18:44:39 UTC (rev 19468)
@@ -50,6 +50,7 @@
}
protected void tearDown() throws Exception {
+ super.tearDown();
SchemaExport export = new SchemaExport( cfg );
export.drop( false, true );
}
Modified:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/TestCase.java
===================================================================
---
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/TestCase.java 2010-05-11
15:08:54 UTC (rev 19467)
+++
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/TestCase.java 2010-05-11
18:44:39 UTC (rev 19468)
@@ -2,6 +2,8 @@
package org.hibernate.search.test;
import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.SQLException;
import org.apache.lucene.analysis.StopAnalyzer;
@@ -15,6 +17,7 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.event.FlushEventListener;
import org.hibernate.event.def.DefaultFlushEventListener;
+import org.hibernate.jdbc.Work;
import org.hibernate.search.event.FullTextIndexEventListener;
/**
@@ -68,13 +71,27 @@
lastTestClass = getClass();
}
}
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if ( sessions != null ) {
+ sessions.close();
+ sessions = null;
+ }
+ }
+
+ private class RollbackWork implements Work{
+ public void execute( Connection connection ) throws SQLException {
+ connection.rollback();
+ }
+
+ }
protected void runTest() throws Throwable {
try {
super.runTest();
if ( session != null && session.isOpen() ) {
if ( session.isConnected() ) {
- session.connection().rollback();
+ session.doWork( new RollbackWork() );
}
session.close();
session = null;
@@ -88,7 +105,7 @@
try {
if ( session != null && session.isOpen() ) {
if ( session.isConnected() ) {
- session.connection().rollback();
+ session.doWork( new RollbackWork() );
}
session.close();
}
Modified:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java
===================================================================
---
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java 2010-05-11
15:08:54 UTC (rev 19467)
+++
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java 2010-05-11
18:44:39 UTC (rev 19468)
@@ -4,6 +4,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;
@@ -54,7 +55,7 @@
es.execute( work );
es.execute( reverseWork );
}
- while ( work.count < iteration - 1 ) {
+ while ( work.count.get() < iteration - 1 ) {
Thread.sleep( 20 );
}
getSessions().close();
@@ -64,66 +65,75 @@
protected static class Work implements Runnable {
private SessionFactory sf;
- 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.
-// }
+ s = sf.openSession();
+ tx = s.beginTransaction();
+ FullTextSession fts = new FullTextSessionImpl( s );
+ QueryParser parser = new QueryParser( "id", new 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();
- FullTextSession fts = new FullTextSessionImpl( s );
- QueryParser parser = new QueryParser( "id", new StopAnalyzer() );
- Query query;
- try {
- query = parser.parse( "name:emmanuel2" );
+ 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();
+ } 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++;
+
}
}
@@ -172,6 +182,8 @@
cfg.setProperty( "hibernate.search.default.indexBase", sub.getAbsolutePath()
);
cfg.setProperty( "hibernate.search.Clock.directory_provider",
FSDirectoryProvider.class.getName() );
cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
+ cfg.setProperty( "hibernate.show_sql", "false" );
+ cfg.setProperty( "hibernate.format_sql", "false" );
}
@SuppressWarnings("unchecked")
Show replies by date