@Test public void testDumpMode() throws Exception { // Arrange File logfile = new File(new File(mySnapDir, "version-2"), "log.274"); TxnLogToolkit lt = new TxnLogToolkit(false, false, logfile.toString(), true); // Act lt.dump(null); // Assert // no exception thrown }
@Test public void testDumpWithCrcError() throws Exception { // Arrange File logfile = new File(new File(mySnapDir, "version-2"), "log.42"); TxnLogToolkit lt = new TxnLogToolkit(false, false, logfile.toString(), true); // Act lt.dump(null); // Assert String output = outContent.toString(); Pattern p = Pattern.compile("^CRC ERROR.*session 0x8061fac5ddeb0000 cxid 0x0 zxid 0x8800000002 createSession 30000$", Pattern.MULTILINE); Matcher m = p.matcher(output); assertTrue("Output doesn't indicate CRC error for the broken session id: " + output, m.find()); }
@Test public void testRecoveryInteractiveMode() throws Exception { // Arrange File logfile = new File(new File(mySnapDir, "version-2"), "log.42"); TxnLogToolkit lt = new TxnLogToolkit(true, false, logfile.toString(), false); // Act lt.dump(new Scanner("y\n")); // Assert String output = outContent.toString(); assertThat(output, containsString("CRC ERROR")); // Should be able to dump the recovered logfile with no CRC error outContent.reset(); logfile = new File(new File(mySnapDir, "version-2"), "log.42.fixed"); lt = new TxnLogToolkit(false, false, logfile.toString(), true); lt.dump(null); output = outContent.toString(); assertThat(output, not(containsString("CRC ERROR"))); } }
@Test public void testRecoveryFixBrokenFile() throws Exception { // Arrange File logfile = new File(new File(mySnapDir, "version-2"), "log.42"); TxnLogToolkit lt = new TxnLogToolkit(true, false, logfile.toString(), true); // Act lt.dump(null); // Assert String output = outContent.toString(); assertThat(output, containsString("CRC FIXED")); // Should be able to dump the recovered logfile with no CRC error outContent.reset(); logfile = new File(new File(mySnapDir, "version-2"), "log.42.fixed"); lt = new TxnLogToolkit(false, false, logfile.toString(), true); lt.dump(null); output = outContent.toString(); assertThat(output, not(containsString("CRC ERROR"))); }
/** * @param args Command line arguments */ public static void main(String[] args) throws Exception { try (final TxnLogToolkit lt = parseCommandLine(args)) { if (lt.isDumpMode()) { lt.dump(new Scanner(System.in)); lt.printStat(); } else { lt.chop(); } } catch (TxnLogToolkitParseException e) { System.err.println(e.getMessage() + "\n"); printHelpAndExit(e.getExitCode(), e.getOptions()); } catch (TxnLogToolkitException e) { System.err.println(e.getMessage()); System.exit(e.getExitCode()); } }
/** * @param args Command line arguments */ public static void main(String[] args) throws Exception { final TxnLogToolkit lt = parseCommandLine(args); try { lt.dump(new Scanner(System.in)); lt.printStat(); } catch (TxnLogToolkitParseException e) { System.err.println(e.getMessage() + "\n"); printHelpAndExit(e.getExitCode()); } catch (TxnLogToolkitException e) { System.err.println(e.getMessage()); System.exit(e.getExitCode()); } finally { lt.close(); } }