zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfenes <...@git.apache.org>
Subject [GitHub] zookeeper pull request #450: ZOOKEEPER-2967: Add check to validate dataDir a...
Date Tue, 30 Jan 2018 00:20:07 GMT
Github user mfenes commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/450#discussion_r164606812
  
    --- Diff: src/java/test/org/apache/zookeeper/server/persistence/FileTxnSnapLogTest.java
---
    @@ -159,4 +159,222 @@ public void onTxnLoaded(TxnHeader hdr, Record rec) {
                 }
             }
         }
    +
    +    @Test
    +    public void testDirCheckWithCorrectFiles() throws IOException {
    +        File tmpDir = ClientBase.createEmptyTestDir();
    +        File logDir = new File(tmpDir, "logdir");
    +        File snapDir = new File(tmpDir, "snapdir");
    +        File logVersionDir = new File(logDir, FileTxnSnapLog.version +  FileTxnSnapLog.VERSION);
    +        File snapVersionDir = new File(snapDir, FileTxnSnapLog.version +  FileTxnSnapLog.VERSION);
    +
    +        if (!logVersionDir.exists()) {
    +            logVersionDir.mkdirs();
    +        }
    +        if (!snapVersionDir.exists()) {
    +            snapVersionDir.mkdirs();
    +        }
    +
    +        Assert.assertTrue(logVersionDir.exists());
    +        Assert.assertTrue(snapVersionDir.exists());
    +
    +        // transaction log files in log dir - correct
    +        File logFile1 = new File(logVersionDir.getPath() +File.separator + Util.makeLogName(1L));
    +        logFile1.createNewFile();
    +        File logFile2 = new File(logVersionDir.getPath() +File.separator + Util.makeLogName(2L));
    +        logFile2.createNewFile();
    +
    +        // snapshot files in snap dir - correct
    +        File snapFile1 = new File(snapVersionDir.getPath() +File.separator + Util.makeSnapshotName(1L));
    +        snapFile1.createNewFile();
    +        File snapFile2 = new File(snapVersionDir.getPath() +File.separator + Util.makeSnapshotName(2L));
    +        snapFile2.createNewFile();
    +
    +        Assert.assertTrue(logFile1.exists());
    +        Assert.assertTrue(logFile2.exists());
    +        Assert.assertTrue(snapFile1.exists());
    +        Assert.assertTrue(snapFile2.exists());
    +
    +        String priorAutocreateDirValue = System.getProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE);
    +        System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, "false");
    +        FileTxnSnapLog fileTxnSnapLog;
    +        try {
    +            fileTxnSnapLog = new FileTxnSnapLog(logDir, snapDir);
    +        } catch (FileTxnSnapLog.LogdirContentCheckException e) {
    +            Assert.fail("Should not throw LogdirContentCheckException.");
    +        } catch (FileTxnSnapLog.SnapdirContentCheckException e) {
    +            Assert.fail("Should not throw SnapdirContentCheckException.");
    +        } finally {
    +            if (priorAutocreateDirValue == null) {
    +                System.clearProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE);
    +            } else {
    +                System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, priorAutocreateDirValue);
    +            }
    --- End diff --
    
    I switched off autocreate to make sure the test is reading the test input data and not
something else by mistake.
    Added clean-up of temp directories.


---

Mime
View raw message