private void Work(object state) { Employee ee = null; Employer er = null; try { using (ISession s = OpenSession()) { ITransaction tx = s.BeginTransaction(); ee = new Employee(); ee.Name = ("Emmanuel"); s.Save(ee); er = new Employer(); er.Name = ("RH"); s.Save(er); tx.Commit(); } using (ISession s = OpenSession()) { ITransaction tx = s.BeginTransaction(); ee = s.Get<Employee>(ee.Id); ee.Name = ("Emmanuel2"); er = s.Get<Employer>(er.Id); er.Name = ("RH2"); tx.Commit(); } //Thread.Sleep(50); using (ISession s = OpenSession()) { ITransaction tx = s.BeginTransaction(); IFullTextSession fts = new Impl.FullTextSessionImpl(s); QueryParser parser = new QueryParser("id", new StopAnalyzer()); Lucene.Net.Search.Query query = parser.Parse("name:emmanuel2"); bool results = fts.CreateFullTextQuery(query).List().Count > 0; //don't test because in case of async, it query happens before actual saving //if ( !results ) throw new Exception( "No results!" ); tx.Commit(); } //System.Diagnostics.Debug.WriteLine("Interation " + worksCount + " completed on thread " + Thread.CurrentThread.ManagedThreadId); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); errorsCount++; } finally { worksCount++; if (ee != null || er != null) using (ISession s = OpenSession()) { ITransaction tx = s.BeginTransaction(); if (ee != null) { ee = s.Get<Employee>(ee.Id); if (ee != null) s.Delete(ee); } if (er != null) { er = s.Get<Employer>(er.Id); if (er != null) s.Delete(er); } tx.Commit(); } } }
private void ReverseWork(object state) { Employee ee = null; Employer er = null; try { using (ISession s = OpenSession()) { ITransaction tx = s.BeginTransaction(); er = new Employer(); er.Name = "RH"; s.Save(er); ee = new Employee(); ee.Name = "Emmanuel"; s.Save(ee); tx.Commit(); } using (ISession s = OpenSession()) { ITransaction tx = s.BeginTransaction(); er = s.Get<Employer>(er.Id); er.Name = ("RH2"); ee = s.Get<Employee>(ee.Id); ee.Name = ("Emmanuel2"); tx.Commit(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); errorsCount++; } finally { reverseWorksCount++; if (ee != null || er != null) using (ISession s = OpenSession()) { ITransaction tx = s.BeginTransaction(); if (ee != null) { ee = s.Get<Employee>(ee.Id); if (ee != null) s.Delete(ee); } if (er != null) { er = s.Get<Employer>(er.Id); if (er != null) s.Delete(er); } tx.Commit(); } } }