public void TestQueryPageCache() { var query = session.CreateSQLQuery("SELECT Id FROM PeptideSpectrumMatch ORDER BY Spectrum, Id"); int rowCount = 90; // sanity check Assert.AreEqual(rowCount, session.Query <PeptideSpectrumMatch>().Count()); // test at page size of 20 (5 pages) var queryReader = new QueryPageCache(query, rowCount) { PageSize = 20, CacheSize = 2 }; Assert.AreEqual(rowCount, queryReader.RowCount); Assert.AreEqual(5, queryReader.PageCount); Assert.AreEqual(20, queryReader.PageSize); // populate the cache with 2 pages var firstQueryPage = queryReader.GetPage(0); Assert.AreEqual(0, firstQueryPage.PageIndex); Assert.AreEqual(20, firstQueryPage.Rows.Count); var lastQueryPage = queryReader.GetPage(4); Assert.AreEqual(4, lastQueryPage.PageIndex); Assert.AreEqual(10, lastQueryPage.Rows.Count); // test that these pages are cached Assert.AreSame(firstQueryPage, queryReader.GetPage(0)); Assert.AreSame(lastQueryPage, queryReader.GetPage(4)); // bump the LRU page (firstQueryPage) out of the cache var secondQueryPage = queryReader.GetPage(1); Assert.AreEqual(1, secondQueryPage.PageIndex); Assert.AreEqual(20, secondQueryPage.Rows.Count); Assert.AreSame(lastQueryPage, queryReader.GetPage(4)); Assert.AreSame(secondQueryPage, queryReader.GetPage(1)); // bump the LRU page (lastQueryPage) out of the cache Assert.AreNotSame(firstQueryPage, queryReader.GetPage(0)); Assert.AreSame(secondQueryPage, queryReader.GetPage(1)); Assert.AreNotSame(lastQueryPage, queryReader.GetPage(4)); }
public void TestQueryPageCache () { var query = session.CreateSQLQuery("SELECT Id FROM PeptideSpectrumMatch ORDER BY Spectrum, Id"); int rowCount = 90; // sanity check Assert.AreEqual(rowCount, session.Query<PeptideSpectrumMatch>().Count()); // test at page size of 20 (5 pages) var queryReader = new QueryPageCache(query, rowCount) {PageSize = 20, CacheSize = 2}; Assert.AreEqual(rowCount, queryReader.RowCount); Assert.AreEqual(5, queryReader.PageCount); Assert.AreEqual(20, queryReader.PageSize); // populate the cache with 2 pages var firstQueryPage = queryReader.GetPage(0); Assert.AreEqual(0, firstQueryPage.PageIndex); Assert.AreEqual(20, firstQueryPage.Rows.Count); var lastQueryPage = queryReader.GetPage(4); Assert.AreEqual(4, lastQueryPage.PageIndex); Assert.AreEqual(10, lastQueryPage.Rows.Count); // test that these pages are cached Assert.AreSame(firstQueryPage, queryReader.GetPage(0)); Assert.AreSame(lastQueryPage, queryReader.GetPage(4)); // bump the LRU page (firstQueryPage) out of the cache var secondQueryPage = queryReader.GetPage(1); Assert.AreEqual(1, secondQueryPage.PageIndex); Assert.AreEqual(20, secondQueryPage.Rows.Count); Assert.AreSame(lastQueryPage, queryReader.GetPage(4)); Assert.AreSame(secondQueryPage, queryReader.GetPage(1)); // bump the LRU page (lastQueryPage) out of the cache Assert.AreNotSame(firstQueryPage, queryReader.GetPage(0)); Assert.AreSame(secondQueryPage, queryReader.GetPage(1)); Assert.AreNotSame(lastQueryPage, queryReader.GetPage(4)); }