zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r777419 - in /hadoop/zookeeper/trunk: CHANGES.txt src/java/test/org/apache/zookeeper/server/CRCTest.java
Date Fri, 22 May 2009 07:43:14 GMT
Author: phunt
Date: Fri May 22 07:43:14 2009
New Revision: 777419

URL: http://svn.apache.org/viewvc?rev=777419&view=rev
Log:
ZOOKEEPER-385. crctest failed on hudson patch test

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/CRCTest.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=777419&r1=777418&r2=777419&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Fri May 22 07:43:14 2009
@@ -94,6 +94,8 @@
 
   ZOOKEEPER-415. zookeeper c tests hang. (mahadev via phunt)
 
+  ZOOKEEPER-385. crctest failed on hudson patch test (mahadev via phunt)
+
 IMPROVEMENTS:
   ZOOKEEPER-308. improve the atomic broadcast performance 3x.
   (breed via mahadev)

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/CRCTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/CRCTest.java?rev=777419&r1=777418&r2=777419&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/CRCTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/CRCTest.java Fri May
22 07:43:14 2009
@@ -26,6 +26,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.RandomAccessFile;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
@@ -81,6 +82,33 @@
         raf.close();
     }
 
+    /** return if checksum matches for a snapshot **/
+    private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
+        DataTree dt = new DataTree();
+        Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
+        InputStream snapIS = new BufferedInputStream(new FileInputStream(
+                snapFile));
+        CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
+        InputArchive ia = BinaryInputArchive.getArchive(crcIn);
+        try {
+            snap.deserialize(dt, sessions, ia);
+        } catch (IOException ie) {
+            // we failed on the most recent snapshot
+            // must be incomplete
+            // try reading the next one
+            // after corrupting
+            snapIS.close();
+            crcIn.close();
+            throw ie;
+        }
+
+        long checksum = crcIn.getChecksum().getValue();
+        long val = ia.readLong("val");
+        snapIS.close();
+        crcIn.close();
+        return (val != checksum);
+    }
+    
     /** test checksums for the logs and snapshots.
      * the reader should fail on reading 
      * a corrupt snapshot and a corrupt log
@@ -134,21 +162,21 @@
         itr.close();
         // find the last snapshot
         FileSnap snap = new FileSnap(versionDir);
-        snapFile = snap.findMostRecentSnapshot();
-        // corrupt this file
+        List<File> snapFiles = snap.findNRecentSnapshots(2);
+        snapFile = snapFiles.get(0);
         corruptFile(snapFile);
-        DataTree dt = new DataTree();
-        Map<Long, Integer> sessions = 
-            new ConcurrentHashMap<Long, Integer>();
-        InputStream snapIS = new BufferedInputStream(new FileInputStream(snapFile));
-        CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
-        InputArchive ia=BinaryInputArchive.getArchive(crcIn);
-        snap.deserialize(dt,sessions, ia);
-        long checkSum = crcIn.getChecksum().getValue();
-        long val = ia.readLong("val");
-        snapIS.close();
-        crcIn.close();
-        assertTrue(val != checkSum);
+        boolean cfile = false;
+        try {
+            cfile = getCheckSum(snap, snapFile);
+        } catch(IOException ie) {
+            //the last snapshot seems incompelte
+            // corrupt the last but one
+            // and use that
+            snapFile = snapFiles.get(1);
+            corruptFile(snapFile);
+            cfile = getCheckSum(snap, snapFile);
+        }
+        assertTrue(cfile);
    }
     
     public void process(WatchedEvent event) {



Mime
View raw message