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
This commit is contained in:
Shalin Shekhar Mangar 2015-08-02 05:26:25 +00:00
parent 0e61da7531
commit 85347285f8
1 changed files with 49 additions and 44 deletions

View File

@ -432,63 +432,68 @@ public class CdcrUpdateLogTest extends SolrTestCaseJ4 {
@Test @Test
public void testClosingOutputStreamAfterLogReplay() throws Exception { public void testClosingOutputStreamAfterLogReplay() throws Exception {
this.clearCore(); this.clearCore();
try {
DirectUpdateHandler2.commitOnClose = false;
final Semaphore logReplay = new Semaphore(0);
final Semaphore logReplayFinish = new Semaphore(0);
DirectUpdateHandler2.commitOnClose = false; UpdateLog.testing_logReplayHook = new Runnable() {
final Semaphore logReplay = new Semaphore(0); @Override
final Semaphore logReplayFinish = new Semaphore(0); public void run() {
try {
UpdateLog.testing_logReplayHook = new Runnable() { assertTrue(logReplay.tryAcquire(timeout, TimeUnit.SECONDS));
@Override } catch (Exception e) {
public void run() { throw new RuntimeException(e);
try { }
assertTrue(logReplay.tryAcquire(timeout, TimeUnit.SECONDS));
} catch (Exception e) {
throw new RuntimeException(e);
} }
} };
};
UpdateLog.testing_logReplayFinishHook = new Runnable() { UpdateLog.testing_logReplayFinishHook = new Runnable() {
@Override @Override
public void run() { public void run() {
logReplayFinish.release(); logReplayFinish.release();
} }
}; };
Deque<Long> versions = new ArrayDeque<>(); Deque<Long> versions = new ArrayDeque<>();
versions.addFirst(addAndGetVersion(sdoc("id", "A11"), null)); versions.addFirst(addAndGetVersion(sdoc("id", "A11"), null));
versions.addFirst(addAndGetVersion(sdoc("id", "A12"), null)); versions.addFirst(addAndGetVersion(sdoc("id", "A12"), null));
versions.addFirst(addAndGetVersion(sdoc("id", "A13"), 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(); h.close();
createCore(); createCore();
// Solr should kick this off now // Solr should kick this off now
// h.getCore().getUpdateHandler().getUpdateLog().recoverFromLog(); // h.getCore().getUpdateHandler().getUpdateLog().recoverFromLog();
// verify that previous close didn't do a commit // verify that previous close didn't do a commit
// recovery should be blocked by our hook // recovery should be blocked by our hook
assertJQ(req("q", "*:*"), "/response/numFound==0"); assertJQ(req("q", "*:*"), "/response/numFound==0");
// unblock recovery // unblock recovery
logReplay.release(1000); logReplay.release(1000);
// wait until recovery has finished // wait until recovery has finished
assertTrue(logReplayFinish.tryAcquire(timeout, TimeUnit.SECONDS)); 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 // The transaction log should have written a commit and close its output stream
UpdateLog ulog = h.getCore().getUpdateHandler().getUpdateLog(); UpdateLog ulog = h.getCore().getUpdateHandler().getUpdateLog();
assertEquals(0, ulog.logs.peekLast().refcount.get()); assertEquals(0, ulog.logs.peekLast().refcount.get());
assertNull(ulog.logs.peekLast().channel); assertNull(ulog.logs.peekLast().channel);
ulog.logs.peekLast().incref(); // reopen the output stream to check if its ends with a commit ulog.logs.peekLast().incref(); // reopen the output stream to check if its ends with a commit
assertTrue(ulog.logs.peekLast().endsWithCommit()); assertTrue(ulog.logs.peekLast().endsWithCommit());
ulog.logs.peekLast().decref(); ulog.logs.peekLast().decref();
} finally {
DirectUpdateHandler2.commitOnClose = true; // reset
UpdateLog.testing_logReplayHook = null;
UpdateLog.testing_logReplayFinishHook = null;
}
} }
/** /**