private static void populateIndexes(final SessionFactoryImplementor sessionFactory, final int nbOfThreadLoad, final int nbOfThreadFetching) throws InterruptedException { FullTextSession fullTextSession = null; try { final Session session = sessionFactory.openSession(); fullTextSession = Search.getFullTextSession(session); final Transaction tx = fullTextSession.beginTransaction(); final MassIndexer indexer = fullTextSession.createIndexer(); indexer.batchSizeToLoadObjects(25).cacheMode(CacheMode.NORMAL).optimizeOnFinish(true); indexer.threadsToLoadObjects(nbOfThreadLoad).threadsForSubsequentFetching(nbOfThreadFetching).startAndWait(); fullTextSession.createIndexer(); tx.commit(); } finally { if (fullTextSession != null) { fullTextSession.close(); } } }
@Test public void writeThenPurge() throws Exception { flush(); List<Level1> all = getAll(); assertEquals( "Wrong total number of entries", 3, all.size() ); // Expect 0 failure in the backend threads logged.expectLevelMissing( Level.ERROR ); Transaction tx = fullTextSession.beginTransaction(); fullTextSession.index( fullTextSession.get( Level1.class, 1L ) ); tx.commit(); tx = fullTextSession.beginTransaction(); fullTextSession.purgeAll( Level1.class ); tx.commit(); flush(); all = getAll(); assertEquals( "Wrong total number of entries. Index should be empty after purge.", 0, all.size() ); tx = fullTextSession.beginTransaction(); fullTextSession.createIndexer() .batchSizeToLoadObjects( 25 ) .threadsToLoadObjects( 1 ) .optimizeOnFinish( true ) .startAndWait(); tx.commit(); flush(); all = getAll(); assertEquals( "Wrong total number of entries.", 3, all.size() ); }
@Test @TestForIssue(jiraKey = "HSEARCH-2761") public void multiplePurges() throws Exception { flush(); List<Level1> all = getAll(); assertEquals( "Wrong total number of entries", 3, all.size() ); // Expect 0 failure in the backend threads logged.expectLevelMissing( Level.ERROR ); Transaction tx = fullTextSession.beginTransaction(); // Order is significant to reproduce the issue, see HSEARCH-2761 fullTextSession.purgeAll( Level2.class ); fullTextSession.purgeAll( Level3.class ); fullTextSession.purgeAll( Level1.class ); tx.commit(); flush(); all = getAll(); assertEquals( "Wrong total number of entries. Index should be empty after purge.", 0, all.size() ); tx = fullTextSession.beginTransaction(); fullTextSession.createIndexer() .batchSizeToLoadObjects( 25 ) .threadsToLoadObjects( 1 ) .optimizeOnFinish( true ) .startAndWait(); tx.commit(); flush(); all = getAll(); assertEquals( "Wrong total number of entries.", 3, all.size() ); }
@SuppressWarnings("unchecked") @Test public void testInterceptorWithMassIndexer() throws Exception { setAllBlogEntriesToStatus( BlogStatus.PUBLISHED ); List<Blog> blogEntries = getBlogEntries(); assertEquals( "Wrong total number of entries", 3, blogEntries.size() ); for ( Blog blog : blogEntries ) { assertTrue( blog.getStatus().equals( BlogStatus.PUBLISHED ) ); } Transaction tx = fullTextSession.beginTransaction(); fullTextSession.purgeAll( Blog.class ); fullTextSession.purgeAll( Article.class ); fullTextSession.purgeAll( TotalArticle.class ); tx.commit(); blogEntries = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ).list(); assertEquals( "Wrong total number of entries. Index should be empty after purge.", 0, blogEntries.size() ); tx = fullTextSession.beginTransaction(); fullTextSession.createIndexer() .batchSizeToLoadObjects( 25 ) .threadsToLoadObjects( 1 ) .threadsForSubsequentFetching( 2 ) .optimizeOnFinish( true ) .startAndWait(); tx.commit(); blogEntries = getBlogEntries(); assertEquals( "Wrong total number of entries.", 3, blogEntries.size() ); }
.optimizeOnFinish( true ) .startAndWait();