public void ProperCopy() { // Assert that the slave index is empty IFullTextSession fullTextSession = Search.CreateFullTextSession(GetSlaveSession()); ITransaction tx = fullTextSession.BeginTransaction(); QueryParser parser = new QueryParser(LuceneVersion.LUCENE_48, "id", new StopAnalyzer(LuceneVersion.LUCENE_48)); IList result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:texas")).List(); Assert.AreEqual(0, result.Count, "No copy yet, fresh index expected"); tx.Commit(); fullTextSession.Close(); // create an entity on the master and persist it in order to index it ISession session = CreateSession(0); tx = session.BeginTransaction(); SnowStorm sn = new SnowStorm(); sn.DateTime = DateTime.Now; sn.Location = ("Dallas, TX, USA"); session.Persist(sn); tx.Commit(); session.Close(); int waitPeriodMilli = 2 * 1 * 1000 + 10; //wait a bit more than 2 refresh (one master / one slave) Thread.Sleep(waitPeriodMilli); // assert that the master has indexed the snowstorm fullTextSession = Search.CreateFullTextSession(GetMasterSession()); tx = fullTextSession.BeginTransaction(); result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:dallas")).List(); Assert.AreEqual(1, result.Count, "Original should get one"); tx.Commit(); fullTextSession.Close(); // assert that index got copied to the slave as well fullTextSession = Search.CreateFullTextSession(GetSlaveSession()); tx = fullTextSession.BeginTransaction(); result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:dallas")).List(); Assert.AreEqual(1, result.Count, "First copy did not work out"); tx.Commit(); fullTextSession.Close(); // add a new snowstorm to the master session = GetMasterSession(); tx = session.BeginTransaction(); sn = new SnowStorm(); sn.DateTime = DateTime.Now; sn.Location = ("Chennai, India"); session.Persist(sn); tx.Commit(); session.Close(); Thread.Sleep(waitPeriodMilli); //wait a bit more than 2 refresh (one master / one slave) // assert that the new snowstorm made it into the slave fullTextSession = Search.CreateFullTextSession(GetSlaveSession()); tx = fullTextSession.BeginTransaction(); result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:chennai")).List(); Assert.AreEqual(1, result.Count, "Second copy did not work out"); tx.Commit(); fullTextSession.Close(); session = GetMasterSession(); tx = session.BeginTransaction(); sn = new SnowStorm(); sn.DateTime = DateTime.Now; sn.Location = ("Melbourne, Australia"); session.Persist(sn); tx.Commit(); session.Close(); Thread.Sleep(waitPeriodMilli); //wait a bit more than 2 refresh (one master / one slave) // once more - assert that the new snowstorm made it into the slave fullTextSession = Search.CreateFullTextSession(GetSlaveSession()); tx = fullTextSession.BeginTransaction(); result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:melbourne")).List(); Assert.AreEqual(1, result.Count, "Third copy did not work out"); tx.Commit(); fullTextSession.Close(); }
public void ProperCopy() { // Assert that the slave index is empty IFullTextSession fullTextSession = Search.CreateFullTextSession(GetSlaveSession()); ITransaction tx = fullTextSession.BeginTransaction(); QueryParser parser = new QueryParser("id", new StopAnalyzer()); IList result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:texas")).List(); Assert.AreEqual(0, result.Count, "No copy yet, fresh index expected"); tx.Commit(); fullTextSession.Close(); // create an entity on the master and persist it in order to index it ISession session = CreateSession(0); tx = session.BeginTransaction(); SnowStorm sn = new SnowStorm(); sn.DateTime = DateTime.Now; sn.Location = ("Dallas, TX, USA"); session.Persist(sn); tx.Commit(); session.Close(); int waitPeriodMilli = 2*1*1000 + 10; //wait a bit more than 2 refresh (one master / one slave) Thread.Sleep(waitPeriodMilli); // assert that the master has indexed the snowstorm fullTextSession = Search.CreateFullTextSession(GetMasterSession()); tx = fullTextSession.BeginTransaction(); result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:dallas")).List(); Assert.AreEqual(1, result.Count, "Original should get one"); tx.Commit(); fullTextSession.Close(); // assert that index got copied to the slave as well fullTextSession = Search.CreateFullTextSession(GetSlaveSession()); tx = fullTextSession.BeginTransaction(); result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:dallas")).List(); Assert.AreEqual(1, result.Count, "First copy did not work out"); tx.Commit(); fullTextSession.Close(); // add a new snowstorm to the master session = GetMasterSession(); tx = session.BeginTransaction(); sn = new SnowStorm(); sn.DateTime = DateTime.Now; sn.Location = ("Chennai, India"); session.Persist(sn); tx.Commit(); session.Close(); Thread.Sleep(waitPeriodMilli); //wait a bit more than 2 refresh (one master / one slave) // assert that the new snowstorm made it into the slave fullTextSession = Search.CreateFullTextSession(GetSlaveSession()); tx = fullTextSession.BeginTransaction(); result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:chennai")).List(); Assert.AreEqual(1, result.Count, "Second copy did not work out"); tx.Commit(); fullTextSession.Close(); session = GetMasterSession(); tx = session.BeginTransaction(); sn = new SnowStorm(); sn.DateTime = DateTime.Now; sn.Location = ("Melbourne, Australia"); session.Persist(sn); tx.Commit(); session.Close(); Thread.Sleep(waitPeriodMilli); //wait a bit more than 2 refresh (one master / one slave) // once more - assert that the new snowstorm made it into the slave fullTextSession = Search.CreateFullTextSession(GetSlaveSession()); tx = fullTextSession.BeginTransaction(); result = fullTextSession.CreateFullTextQuery(parser.Parse("Location:melbourne")).List(); Assert.AreEqual(1, result.Count, "Third copy did not work out"); tx.Commit(); fullTextSession.Close(); }
public void ProperCopy() { ISession s1 = CreateSession(0); SnowStorm sn = new SnowStorm(); sn.DateTime = DateTime.Now; sn.Location = ("Dallas, TX, USA"); IFullTextSession fts2 = Search.CreateFullTextSession(CreateSession(1)); QueryParser parser = new QueryParser("id", new StopAnalyzer()); IList result = fts2.CreateFullTextQuery(parser.Parse("Location:texas")).List(); Assert.AreEqual(0, result.Count, "No copy yet, fresh index expected"); s1.Save(sn); s1.Flush(); //we don' commit so we need to flush manually fts2.Close(); s1.Close(); int waitPeriod = 2*1*1000 + 10; //wait a bit more than 2 refresh (one master / one slave) Thread.Sleep(waitPeriod); //temp test original fts2 = Search.CreateFullTextSession(CreateSession(0)); result = fts2.CreateFullTextQuery(parser.Parse("Location:dallas")).List(); Assert.AreEqual(1, result.Count, "Original should get one"); fts2 = Search.CreateFullTextSession(CreateSession(1)); result = fts2.CreateFullTextQuery(parser.Parse("Location:dallas")).List(); Assert.AreEqual(1, result.Count, "First copy did not work out"); s1 = CreateSession(0); sn = new SnowStorm(); sn.DateTime = DateTime.Now; sn.Location = ("Chennai, India"); s1.Save(sn); s1.Flush(); //we don' commit so we need to flush manually fts2.Close(); s1.Close(); Thread.Sleep(waitPeriod); //wait a bit more than 2 refresh (one master / one slave) fts2 = Search.CreateFullTextSession(CreateSession(1)); result = fts2.CreateFullTextQuery(parser.Parse("Location:chennai")).List(); Assert.AreEqual(1, result.Count, "Second copy did not work out"); s1 = CreateSession(0); sn = new SnowStorm(); sn.DateTime = DateTime.Now; sn.Location = ("Melbourne, Australia"); s1.Save(sn); s1.Flush(); //we don' commit so we need to flush manually fts2.Close(); s1.Close(); Thread.Sleep(waitPeriod); //wait a bit more than 2 refresh (one master / one slave) fts2 = Search.CreateFullTextSession(CreateSession(1)); result = fts2.CreateFullTextQuery(parser.Parse("Location:melbourne")).List(); Assert.AreEqual(1, result.Count, "Third copy did not work out"); fts2.Close(); }