Пример #1
0
  /**
   * Test that's meant to be run with many iterations to expose a leak of SolrIndexSearcher when a
   * core is closed due to a reload. Without the fix, this test fails with most iters=1000 runs.
   */
  @Test
  public void testReloadLeak() throws Exception {
    final ExecutorService executor =
        ExecutorUtil.newMDCAwareFixedThreadPool(1, new DefaultSolrThreadFactory("testReloadLeak"));

    // Continuously open new searcher while core is not closed, and reload core to try to reproduce
    // searcher leak.
    // While in practice we never continuously open new searchers, this is trying to make up for the
    // fact that opening
    // a searcher in this empty core is very fast by opening new searchers continuously to increase
    // the likelihood
    // for race.
    SolrCore core = h.getCore();
    assertTrue("Refcount != 1", core.getOpenCount() == 1);
    executor.execute(new NewSearcherRunnable(core));

    // Since we called getCore() vs getCoreInc() and don't own a refCount, the container should
    // decRef the core
    // and close it when we call reload.
    h.reload();

    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.MINUTES);

    // Check that all cores are closed and no searcher references are leaked.
    assertTrue("SolrCore " + core + " is not closed", core.isClosed());
    assertTrue(core.areAllSearcherReferencesEmpty());
  }