From 85347285f833599e9fe5e85e50aa9c8a6b9fd910 Mon Sep 17 00:00:00 2001 From: Shalin Shekhar Mangar Date: Sun, 2 Aug 2015 05:26:25 +0000 Subject: [PATCH] SOLR-6273: Reset test hooks in a finally block to avoid leakage to other tests git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1693786 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/solr/update/CdcrUpdateLogTest.java | 93 ++++++++++--------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java b/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java index b61afff82fb..434586bfab6 100644 --- a/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java +++ b/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java @@ -432,63 +432,68 @@ public class CdcrUpdateLogTest extends SolrTestCaseJ4 { @Test public void testClosingOutputStreamAfterLogReplay() throws Exception { this.clearCore(); + try { + DirectUpdateHandler2.commitOnClose = false; + final Semaphore logReplay = new Semaphore(0); + final Semaphore logReplayFinish = new Semaphore(0); - DirectUpdateHandler2.commitOnClose = false; - final Semaphore logReplay = new Semaphore(0); - final Semaphore logReplayFinish = new Semaphore(0); - - UpdateLog.testing_logReplayHook = new Runnable() { - @Override - public void run() { - try { - assertTrue(logReplay.tryAcquire(timeout, TimeUnit.SECONDS)); - } catch (Exception e) { - throw new RuntimeException(e); + UpdateLog.testing_logReplayHook = new Runnable() { + @Override + public void run() { + try { + assertTrue(logReplay.tryAcquire(timeout, TimeUnit.SECONDS)); + } catch (Exception e) { + throw new RuntimeException(e); + } } - } - }; + }; - UpdateLog.testing_logReplayFinishHook = new Runnable() { - @Override - public void run() { - logReplayFinish.release(); - } - }; + UpdateLog.testing_logReplayFinishHook = new Runnable() { + @Override + public void run() { + logReplayFinish.release(); + } + }; - Deque versions = new ArrayDeque<>(); - versions.addFirst(addAndGetVersion(sdoc("id", "A11"), null)); - versions.addFirst(addAndGetVersion(sdoc("id", "A12"), null)); - versions.addFirst(addAndGetVersion(sdoc("id", "A13"), null)); + Deque versions = new ArrayDeque<>(); + versions.addFirst(addAndGetVersion(sdoc("id", "A11"), null)); + versions.addFirst(addAndGetVersion(sdoc("id", "A12"), null)); + versions.addFirst(addAndGetVersion(sdoc("id", "A13"), null)); - assertJQ(req("q", "*:*"), "/response/numFound==0"); + assertJQ(req("q", "*:*"), "/response/numFound==0"); - assertJQ(req("qt", "/get", "getVersions", "" + versions.size()), "/versions==" + versions); + assertJQ(req("qt", "/get", "getVersions", "" + versions.size()), "/versions==" + versions); - h.close(); - createCore(); - // Solr should kick this off now - // h.getCore().getUpdateHandler().getUpdateLog().recoverFromLog(); + h.close(); + createCore(); + // Solr should kick this off now + // h.getCore().getUpdateHandler().getUpdateLog().recoverFromLog(); - // verify that previous close didn't do a commit - // recovery should be blocked by our hook - assertJQ(req("q", "*:*"), "/response/numFound==0"); + // verify that previous close didn't do a commit + // recovery should be blocked by our hook + assertJQ(req("q", "*:*"), "/response/numFound==0"); - // unblock recovery - logReplay.release(1000); + // unblock recovery + logReplay.release(1000); - // wait until recovery has finished - assertTrue(logReplayFinish.tryAcquire(timeout, TimeUnit.SECONDS)); + // wait until recovery has finished + assertTrue(logReplayFinish.tryAcquire(timeout, TimeUnit.SECONDS)); - assertJQ(req("q", "*:*"), "/response/numFound==3"); + assertJQ(req("q", "*:*"), "/response/numFound==3"); - // The transaction log should have written a commit and close its output stream - UpdateLog ulog = h.getCore().getUpdateHandler().getUpdateLog(); - assertEquals(0, ulog.logs.peekLast().refcount.get()); - assertNull(ulog.logs.peekLast().channel); + // The transaction log should have written a commit and close its output stream + UpdateLog ulog = h.getCore().getUpdateHandler().getUpdateLog(); + assertEquals(0, ulog.logs.peekLast().refcount.get()); + assertNull(ulog.logs.peekLast().channel); - ulog.logs.peekLast().incref(); // reopen the output stream to check if its ends with a commit - assertTrue(ulog.logs.peekLast().endsWithCommit()); - ulog.logs.peekLast().decref(); + ulog.logs.peekLast().incref(); // reopen the output stream to check if its ends with a commit + assertTrue(ulog.logs.peekLast().endsWithCommit()); + ulog.logs.peekLast().decref(); + } finally { + DirectUpdateHandler2.commitOnClose = true; // reset + UpdateLog.testing_logReplayHook = null; + UpdateLog.testing_logReplayFinishHook = null; + } } /**