Java 类org.apache.zookeeper.server.PurgeTxnLog 实例源码

项目:fuck_zookeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains snap files equals to the
 * number of files to be retained
 */
@Test
public void testSnapFilesEqualsToRetain() throws Exception {
    int nRecentCount = 3;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:fuck_zookeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs
 */
@Test
public void testSnapFilesLessThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:https-github.com-apache-zookeeper    文件:PurgeTxnTest.java   
public void internalTestSnapFilesEqualsToRetain(boolean testWithPrecedingLogFile) throws Exception {
    int nRecentCount = 3;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, nRecentCount, testWithPrecedingLogFile, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
    txnLog.close();
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:ZooKeeper    文件:PurgeTxnTest.java   
public void internalTestSnapFilesEqualsToRetain(boolean testWithPrecedingLogFile) throws Exception {
    int nRecentCount = 3;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, nRecentCount, testWithPrecedingLogFile, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
    txnLog.close();
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:StreamProcessingInfrastructure    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains snap files equals to the
 * number of files to be retained
 */
@Test
public void testSnapFilesEqualsToRetain() throws Exception {
    int nRecentCount = 3;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:StreamProcessingInfrastructure    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs
 */
@Test
public void testSnapFilesLessThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:zookeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains snap files equals to the
 * number of files to be retained
 */
@Test
public void testSnapFilesEqualsToRetain() throws Exception {
    int nRecentCount = 3;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:zookeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs
 */
@Test
public void testSnapFilesLessThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:SecureKeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains snap files equals to the
 * number of files to be retained
 */
@Test
public void testSnapFilesEqualsToRetain() throws Exception {
    int nRecentCount = 3;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:SecureKeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs
 */
@Test
public void testSnapFilesLessThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:SecureKeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains snap files equals to the
 * number of files to be retained
 */
@Test
public void testSnapFilesEqualsToRetain() throws Exception {
    int nRecentCount = 3;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:SecureKeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs
 */
@Test
public void testSnapFilesLessThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:fuck_zookeeper    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
项目:fuck_zookeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs, (newest + n) snapshots and data
 * logs
 */
@Test
public void testSnapFilesGreaterThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileAboveRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    List<File> snapsAboveRecentFiles = new ArrayList<File>();
    List<File> logsAboveRecentFiles = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);
    createDataDirFiles(offset, fileAboveRecentCount, version2,
            snapsAboveRecentFiles, logsAboveRecentFiles);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
    verifyFilesAfterPurge(snapsAboveRecentFiles, true);
    verifyFilesAfterPurge(logsAboveRecentFiles, true);
}
项目:fuck_zookeeper    文件:PurgeTxnTest.java   
/**
 * PurgeTxnLog is called with dataLogDir -n count This test case verify
 * these values are parsed properly and functionality works fine
 */
@Test
public void testPurgeTxnLogWithoutDataDir()
        throws Exception {
    tmpDir = ClientBase.createTmpDir();
    File dataDir = new File(tmpDir, "dataDir");
    File dataLogDir = new File(tmpDir, "dataLogDir");

    File dataDirVersion2 = new File(dataDir, "version-2");
    dataDirVersion2.mkdirs();
    File dataLogDirVersion2 = new File(dataLogDir, "version-2");
    dataLogDirVersion2.mkdirs();

    // create dummy log and transaction file
    int totalFiles = 20;

    // create transaction and snapshot files in data directory
    for (int i = 0; i < totalFiles; i++) {
        // simulate log file
        File logFile = new File(dataLogDirVersion2, "log."
                + Long.toHexString(i));
        logFile.createNewFile();
        // simulate snapshot file
        File snapFile = new File(dataLogDirVersion2, "snapshot."
                + Long.toHexString(i));
        snapFile.createNewFile();
    }

    int numberOfFilesToKeep = 10;
    // scenario where only three parameter are passed
    String[] args = new String[] { dataLogDir.getAbsolutePath(), "-n",
            Integer.toString(numberOfFilesToKeep) };
    PurgeTxnLog.main(args);
    assertEquals(numberOfFilesToKeep + numberOfFilesToKeep,
            dataLogDirVersion2.listFiles().length);
    ClientBase.recursiveDelete(tmpDir);

}
项目:https-github.com-apache-zookeeper    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
项目:https-github.com-apache-zookeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs, (newest + n) snapshots and data
 * logs
 */
@Test
public void testSnapFilesGreaterThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileAboveRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    List<File> snapsAboveRecentFiles = new ArrayList<File>();
    List<File> logsAboveRecentFiles = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, false, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, false, version2, snaps, logs);
    logs.add(logsToPurge.remove(0)); // log that precedes first retained snapshot is also retained
    createDataDirFiles(offset, fileAboveRecentCount, false, version2,
            snapsAboveRecentFiles, logsAboveRecentFiles);

    /**
     * The newest log file preceding the oldest retained snapshot is not removed as it may
     * contain transactions newer than the oldest snapshot.
     */
    logsToPurge.remove(0);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
    verifyFilesAfterPurge(snapsAboveRecentFiles, true);
    verifyFilesAfterPurge(logsAboveRecentFiles, true);
}
项目:https-github.com-apache-zookeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs
 */
@Test
public void testSnapFilesLessThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, false, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, false, version2, snaps, logs);
    logs.add(logsToPurge.remove(0)); // log that precedes first retained snapshot is also retained

    /**
     * The newest log file preceding the oldest retained snapshot is not removed as it may
     * contain transactions newer than the oldest snapshot.
     */
    logsToPurge.remove(0);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:https-github.com-apache-zookeeper    文件:PurgeTxnTest.java   
/**
 * PurgeTxnLog is called with dataLogDir -n count This test case verify
 * these values are parsed properly and functionality works fine
 */
@Test
public void testPurgeTxnLogWithoutDataDir()
        throws Exception {
    tmpDir = ClientBase.createTmpDir();
    File dataDir = new File(tmpDir, "dataDir");
    File dataLogDir = new File(tmpDir, "dataLogDir");

    File dataDirVersion2 = new File(dataDir, "version-2");
    dataDirVersion2.mkdirs();
    File dataLogDirVersion2 = new File(dataLogDir, "version-2");
    dataLogDirVersion2.mkdirs();

    // create dummy log and transaction file
    int totalFiles = 20;

    // create transaction and snapshot files in data directory
    for (int i = 0; i < totalFiles; i++) {
        // simulate log file
        File logFile = new File(dataLogDirVersion2, "log."
                + Long.toHexString(i));
        logFile.createNewFile();
        // simulate snapshot file
        File snapFile = new File(dataLogDirVersion2, "snapshot."
                + Long.toHexString(i));
        snapFile.createNewFile();
    }

    int numberOfSnapFilesToKeep = 10;
    // scenario where only three parameter are passed
    String[] args = new String[] { dataLogDir.getAbsolutePath(), "-n",
            Integer.toString(numberOfSnapFilesToKeep) };
    PurgeTxnLog.main(args);
    assertEquals(numberOfSnapFilesToKeep * 2, // Since for each snapshot we have a log file with same zxid, expect same # logs as snaps to be kept
            dataLogDirVersion2.listFiles().length);
    ClientBase.recursiveDelete(tmpDir);

}
项目:ZooKeeper    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
项目:ZooKeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs, (newest + n) snapshots and data
 * logs
 */
@Test
public void testSnapFilesGreaterThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileAboveRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    List<File> snapsAboveRecentFiles = new ArrayList<File>();
    List<File> logsAboveRecentFiles = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, false, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, false, version2, snaps, logs);
    logs.add(logsToPurge.remove(0)); // log that precedes first retained snapshot is also retained
    createDataDirFiles(offset, fileAboveRecentCount, false, version2,
            snapsAboveRecentFiles, logsAboveRecentFiles);

    /**
     * The newest log file preceding the oldest retained snapshot is not removed as it may
     * contain transactions newer than the oldest snapshot.
     */
    logsToPurge.remove(0);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
    verifyFilesAfterPurge(snapsAboveRecentFiles, true);
    verifyFilesAfterPurge(logsAboveRecentFiles, true);
}
项目:ZooKeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs
 */
@Test
public void testSnapFilesLessThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, false, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, false, version2, snaps, logs);
    logs.add(logsToPurge.remove(0)); // log that precedes first retained snapshot is also retained

    /**
     * The newest log file preceding the oldest retained snapshot is not removed as it may
     * contain transactions newer than the oldest snapshot.
     */
    logsToPurge.remove(0);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
}
项目:ZooKeeper    文件:PurgeTxnTest.java   
/**
 * PurgeTxnLog is called with dataLogDir -n count This test case verify
 * these values are parsed properly and functionality works fine
 */
@Test
public void testPurgeTxnLogWithoutDataDir()
        throws Exception {
    tmpDir = ClientBase.createTmpDir();
    File dataDir = new File(tmpDir, "dataDir");
    File dataLogDir = new File(tmpDir, "dataLogDir");

    File dataDirVersion2 = new File(dataDir, "version-2");
    dataDirVersion2.mkdirs();
    File dataLogDirVersion2 = new File(dataLogDir, "version-2");
    dataLogDirVersion2.mkdirs();

    // create dummy log and transaction file
    int totalFiles = 20;

    // create transaction and snapshot files in data directory
    for (int i = 0; i < totalFiles; i++) {
        // simulate log file
        File logFile = new File(dataLogDirVersion2, "log."
                + Long.toHexString(i));
        logFile.createNewFile();
        // simulate snapshot file
        File snapFile = new File(dataLogDirVersion2, "snapshot."
                + Long.toHexString(i));
        snapFile.createNewFile();
    }

    int numberOfSnapFilesToKeep = 10;
    // scenario where only three parameter are passed
    String[] args = new String[] { dataLogDir.getAbsolutePath(), "-n",
            Integer.toString(numberOfSnapFilesToKeep) };
    PurgeTxnLog.main(args);
    assertEquals(numberOfSnapFilesToKeep * 2, // Since for each snapshot we have a log file with same zxid, expect same # logs as snaps to be kept
            dataLogDirVersion2.listFiles().length);
    ClientBase.recursiveDelete(tmpDir);

}
项目:StreamProcessingInfrastructure    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
项目:StreamProcessingInfrastructure    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs, (newest + n) snapshots and data
 * logs
 */
@Test
public void testSnapFilesGreaterThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileAboveRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    List<File> snapsAboveRecentFiles = new ArrayList<File>();
    List<File> logsAboveRecentFiles = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);
    createDataDirFiles(offset, fileAboveRecentCount, version2,
            snapsAboveRecentFiles, logsAboveRecentFiles);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
    verifyFilesAfterPurge(snapsAboveRecentFiles, true);
    verifyFilesAfterPurge(logsAboveRecentFiles, true);
}
项目:StreamProcessingInfrastructure    文件:PurgeTxnTest.java   
/**
 * PurgeTxnLog is called with dataLogDir -n count This test case verify
 * these values are parsed properly and functionality works fine
 */
@Test
public void testPurgeTxnLogWithoutDataDir()
        throws Exception {
    tmpDir = ClientBase.createTmpDir();
    File dataDir = new File(tmpDir, "dataDir");
    File dataLogDir = new File(tmpDir, "dataLogDir");

    File dataDirVersion2 = new File(dataDir, "version-2");
    dataDirVersion2.mkdirs();
    File dataLogDirVersion2 = new File(dataLogDir, "version-2");
    dataLogDirVersion2.mkdirs();

    // create dummy log and transaction file
    int totalFiles = 20;

    // create transaction and snapshot files in data directory
    for (int i = 0; i < totalFiles; i++) {
        // simulate log file
        File logFile = new File(dataLogDirVersion2, "log."
                + Long.toHexString(i));
        logFile.createNewFile();
        // simulate snapshot file
        File snapFile = new File(dataLogDirVersion2, "snapshot."
                + Long.toHexString(i));
        snapFile.createNewFile();
    }

    int numberOfFilesToKeep = 10;
    // scenario where only three parameter are passed
    String[] args = new String[] { dataLogDir.getAbsolutePath(), "-n",
            Integer.toString(numberOfFilesToKeep) };
    PurgeTxnLog.main(args);
    assertEquals(numberOfFilesToKeep + numberOfFilesToKeep,
            dataLogDirVersion2.listFiles().length);
    ClientBase.recursiveDelete(tmpDir);

}
项目:bigstreams    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
}
项目:bigstreams    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
}
项目:zookeeper    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
项目:zookeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs, (newest + n) snapshots and data
 * logs
 */
@Test
public void testSnapFilesGreaterThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileAboveRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    List<File> snapsAboveRecentFiles = new ArrayList<File>();
    List<File> logsAboveRecentFiles = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);
    createDataDirFiles(offset, fileAboveRecentCount, version2,
            snapsAboveRecentFiles, logsAboveRecentFiles);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
    verifyFilesAfterPurge(snapsAboveRecentFiles, true);
    verifyFilesAfterPurge(logsAboveRecentFiles, true);
}
项目:zookeeper    文件:PurgeTxnTest.java   
/**
 * PurgeTxnLog is called with dataLogDir -n count This test case verify
 * these values are parsed properly and functionality works fine
 */
@Test
public void testPurgeTxnLogWithoutDataDir()
        throws Exception {
    tmpDir = ClientBase.createTmpDir();
    File dataDir = new File(tmpDir, "dataDir");
    File dataLogDir = new File(tmpDir, "dataLogDir");

    File dataDirVersion2 = new File(dataDir, "version-2");
    dataDirVersion2.mkdirs();
    File dataLogDirVersion2 = new File(dataLogDir, "version-2");
    dataLogDirVersion2.mkdirs();

    // create dummy log and transaction file
    int totalFiles = 20;

    // create transaction and snapshot files in data directory
    for (int i = 0; i < totalFiles; i++) {
        // simulate log file
        File logFile = new File(dataLogDirVersion2, "log."
                + Long.toHexString(i));
        logFile.createNewFile();
        // simulate snapshot file
        File snapFile = new File(dataLogDirVersion2, "snapshot."
                + Long.toHexString(i));
        snapFile.createNewFile();
    }

    int numberOfFilesToKeep = 10;
    // scenario where only three parameter are passed
    String[] args = new String[] { dataLogDir.getAbsolutePath(), "-n",
            Integer.toString(numberOfFilesToKeep) };
    PurgeTxnLog.main(args);
    assertEquals(numberOfFilesToKeep + numberOfFilesToKeep,
            dataLogDirVersion2.listFiles().length);
    ClientBase.recursiveDelete(tmpDir);

}
项目:SecureKeeper    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
项目:SecureKeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs, (newest + n) snapshots and data
 * logs
 */
@Test
public void testSnapFilesGreaterThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileAboveRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    List<File> snapsAboveRecentFiles = new ArrayList<File>();
    List<File> logsAboveRecentFiles = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);
    createDataDirFiles(offset, fileAboveRecentCount, version2,
            snapsAboveRecentFiles, logsAboveRecentFiles);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
    verifyFilesAfterPurge(snapsAboveRecentFiles, true);
    verifyFilesAfterPurge(logsAboveRecentFiles, true);
}
项目:SecureKeeper    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
项目:SecureKeeper    文件:PurgeTxnTest.java   
/**
 * Tests purge where the data directory contains old snapshots and data
 * logs, newest snapshots and data logs, (newest + n) snapshots and data
 * logs
 */
@Test
public void testSnapFilesGreaterThanToRetain() throws Exception {
    int nRecentCount = 4;
    int fileAboveRecentCount = 4;
    int fileToPurgeCount = 2;
    AtomicInteger offset = new AtomicInteger(0);
    tmpDir = ClientBase.createTmpDir();
    File version2 = new File(tmpDir.toString(), "version-2");
    Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
            version2.mkdir());
    List<File> snapsToPurge = new ArrayList<File>();
    List<File> logsToPurge = new ArrayList<File>();
    List<File> snaps = new ArrayList<File>();
    List<File> logs = new ArrayList<File>();
    List<File> snapsAboveRecentFiles = new ArrayList<File>();
    List<File> logsAboveRecentFiles = new ArrayList<File>();
    createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
            logsToPurge);
    createDataDirFiles(offset, nRecentCount, version2, snaps, logs);
    createDataDirFiles(offset, fileAboveRecentCount, version2,
            snapsAboveRecentFiles, logsAboveRecentFiles);

    FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
    PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
    txnLog.close();
    verifyFilesAfterPurge(snapsToPurge, false);
    verifyFilesAfterPurge(logsToPurge, false);
    verifyFilesAfterPurge(snaps, true);
    verifyFilesAfterPurge(logs, true);
    verifyFilesAfterPurge(snapsAboveRecentFiles, true);
    verifyFilesAfterPurge(logsAboveRecentFiles, true);
}
项目:StreamBench    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    zks.shutdown();
}
项目:LoadBalanced_zk    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
}
项目:LoadBalanced_zk    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
}
项目:zookeeper.dsc    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
public void testPurge() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(
            new InetSocketAddress(PORT));
    f.startup(zks);
    assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    assertTrue("exactly 3 snapshots ", (numSnaps == 3));
}
项目:zookeeper-pkg    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
    f.startup(zks);
    Assert.assertTrue("waiting for server being up ",
            ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    try {
        for (int i = 0; i< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
}