Apache Solr open-source search software
tests: additional corrupt tlog test
Yonik Seeley6104078c44cb
diff --git a/solr/core/src/test/org/apache/solr/search/TestRecovery.java b/solr/core/src/test/org/apache/solr/search/TestRecovery.javaindex e2efbf33a2c..00df4b2c96a 100644--- a/solr/core/src/test/org/apache/solr/search/TestRecovery.java+++ b/solr/core/src/test/org/apache/solr/search/TestRecovery.java@@ -864,6 +864,83 @@ public class TestRecovery extends SolrTestCaseJ4 {}}++ //+ // test that a corrupt tlog doesn't stop us from coming up+ //+ @Test+ public void testCorruptLog() throws Exception {+ 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);+ }+ }+ };++ UpdateLog.testing_logReplayFinishHook = new Runnable() {+ @Override+ public void run() {+ logReplayFinish.release();+ }+ };++ File logDir = h.getCore().getUpdateHandler().getUpdateLog().getLogDir();++ clearIndex();+ assertU(commit());++ assertU(adoc("id","G1"));+ assertU(adoc("id","G2"));+ assertU(adoc("id","G3"));++ h.close();+ String[] files = UpdateLog.getLogList(logDir);+ Arrays.sort(files);+ RandomAccessFile raf = new RandomAccessFile(new File(logDir, files[files.length-1]), "rw");+ long len = raf.length();+ raf.seek(0); // seek to start+ raf.write(new byte[(int)len]); // zero out file+ raf.close();++ logReplay.release(1000);+ logReplayFinish.release(1);+ ignoreException("Failure to open existing log file"); // this is what the corrupted log currently produces... subject to change.+ createCore();+ resetExceptionIgnores();++ // just make sure it responds+ assertJQ(req("q","*:*") ,"/response/numFound==0");++ //+ // Now test that the bad log file doesn't mess up retrieving latest versions+ //++ updateJ(jsonAdd(sdoc("id","G4", "_version_","104")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));+ updateJ(jsonAdd(sdoc("id","G5", "_version_","105")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));+ updateJ(jsonAdd(sdoc("id","G6", "_version_","106")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));++ // This currently skips the bad log file and also returns the version of the clearIndex (del *:*)+ // assertJQ(req("qt","/get", "getVersions","6"), "/versions==[106,105,104]");+ assertJQ(req("qt","/get", "getVersions","3"), "/versions==[106,105,104]");++ } finally {+ DirectUpdateHandler2.commitOnClose = true;+ UpdateLog.testing_logReplayHook = null;+ UpdateLog.testing_logReplayFinishHook = null;+ }+ }+++// in rare circumstances, two logs can be left uncapped (lacking a commit at the end signifying that all the content in the log was committed)@Testpublic void testRecoveryMultipleLogs() throws Exception {