Ejemplo n.º 1
0
  /** Test the OfflineEditsViewer */
  @Test
  public void testGenerated() throws IOException {

    LOG.info("START - testing with generated edits");

    nnHelper.startCluster(buildDir + "/dfs/");

    // edits generated by nnHelper (MiniDFSCluster), should have all op codes
    // binary, XML, reparsed binary
    String edits = nnHelper.generateEdits();
    String editsParsedXml = cacheDir + "/editsParsed.xml";
    String editsReparsed = cacheDir + "/editsReparsed";

    // parse to XML then back to binary
    assertEquals(0, runOev(edits, editsParsedXml, "xml", false));
    assertEquals(0, runOev(editsParsedXml, editsReparsed, "binary", false));

    // judgment time
    assertTrue("Edits " + edits + " should have all op codes", hasAllOpCodes(edits));
    assertTrue(
        "Generated edits and reparsed (bin to XML to bin) should be same",
        filesEqualIgnoreTrailingZeros(edits, editsReparsed));

    // removes edits so do this at the end
    nnHelper.shutdownCluster();

    LOG.info("END");
  }
Ejemplo n.º 2
0
  @Test
  public void testRecoveryMode() throws IOException {
    LOG.info("START - testing with generated edits");

    nnHelper.startCluster(buildDir + "/dfs/");

    // edits generated by nnHelper (MiniDFSCluster), should have all op codes
    // binary, XML, reparsed binary
    String edits = nnHelper.generateEdits();

    // Corrupt the file by truncating the end
    FileChannel editsFile = new FileOutputStream(edits, true).getChannel();
    editsFile.truncate(editsFile.size() - 5);

    String editsParsedXml = cacheDir + "/editsRecoveredParsed.xml";
    String editsReparsed = cacheDir + "/editsRecoveredReparsed";
    String editsParsedXml2 = cacheDir + "/editsRecoveredParsed2.xml";

    // Can't read the corrupted file without recovery mode
    assertEquals(-1, runOev(edits, editsParsedXml, "xml", false));

    // parse to XML then back to binary
    assertEquals(0, runOev(edits, editsParsedXml, "xml", true));
    assertEquals(0, runOev(editsParsedXml, editsReparsed, "binary", false));
    assertEquals(0, runOev(editsReparsed, editsParsedXml2, "xml", false));

    // judgment time
    assertTrue("Test round trip", filesEqualIgnoreTrailingZeros(editsParsedXml, editsParsedXml2));

    // removes edits so do this at the end
    nnHelper.shutdownCluster();

    LOG.info("END");
  }