lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r1693786 - /lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java
Date Sun, 02 Aug 2015 05:26:25 GMT
Author: shalin
Date: Sun Aug  2 05:26:25 2015
New Revision: 1693786

URL: http://svn.apache.org/r1693786
Log:
SOLR-6273: Reset test hooks in a finally block to avoid leakage to other tests

Modified:
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java?rev=1693786&r1=1693785&r2=1693786&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java Sun
Aug  2 05:26:25 2015
@@ -432,63 +432,68 @@ public class CdcrUpdateLogTest extends S
   @Test
   public void testClosingOutputStreamAfterLogReplay() throws Exception {
     this.clearCore();
+    try {
+      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);
+          }
+        }
+      };
 
-    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_logReplayFinishHook = new Runnable() {
+        @Override
+        public void run() {
+          logReplayFinish.release();
         }
-      }
-    };
+      };
 
-    UpdateLog.testing_logReplayFinishHook = new Runnable() {
-      @Override
-      public void run() {
-        logReplayFinish.release();
-      }
-    };
-
-    Deque<Long> 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("qt", "/get", "getVersions", "" + versions.size()), "/versions==" + versions);
-
-    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");
-
-    // unblock recovery
-    logReplay.release(1000);
-
-    // wait until recovery has finished
-    assertTrue(logReplayFinish.tryAcquire(timeout, TimeUnit.SECONDS));
-
-    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);
-
-    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();
+      Deque<Long> 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("qt", "/get", "getVersions", "" + versions.size()), "/versions==" + versions);
+
+      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");
+
+      // unblock recovery
+      logReplay.release(1000);
+
+      // wait until recovery has finished
+      assertTrue(logReplayFinish.tryAcquire(timeout, TimeUnit.SECONDS));
+
+      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);
+
+      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;
+    }
   }
 
   /**



Mime
View raw message