return new TxnLogToolkit(cli.getArgs()[0], cli.getOptionValue("zxid")); return new TxnLogToolkit(cli.hasOption("recover"), cli.hasOption("verbose"), cli.getArgs()[0], cli.hasOption("yes")); } catch (ParseException e) { throw new TxnLogToolkitParseException(options, ExitCode.UNEXPECTED_ERROR.getValue(), e.getMessage());
@Test(expected = TxnLogToolkit.TxnLogToolkitException.class) public void testInitMissingFile() throws FileNotFoundException, TxnLogToolkit.TxnLogToolkitException { // Arrange & Act File logfile = new File("this_file_should_not_exists"); TxnLogToolkit lt = new TxnLogToolkit(false, false, logfile.toString(), true); }
@Test(expected = TxnLogToolkit.TxnLogToolkitException.class) public void testInitWithRecoveryFileExists() throws IOException, TxnLogToolkit.TxnLogToolkitException { // Arrange & Act File logfile = new File(new File(mySnapDir, "version-2"), "log.274"); File recoveryFile = new File(new File(mySnapDir, "version-2"), "log.274.fixed"); recoveryFile.createNewFile(); TxnLogToolkit lt = new TxnLogToolkit(true, false, logfile.toString(), true); }
@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"))); }
private static TxnLogToolkit parseCommandLine(String[] args) throws TxnLogToolkitException, FileNotFoundException { TxnLogToolkitCliParser parser = new TxnLogToolkitCliParser(); parser.parse(args); return new TxnLogToolkit(parser.isRecoveryMode(), parser.isVerbose(), parser.getTxnLogFileName(), parser.isForce()); }