@Test public void testGetInvalidTxSize() throws Exception { Transaction tx1 = txClient.startShort(); txClient.startLong(); txClient.invalidate(tx1.getTransactionId()); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); TransactionAdmin txAdmin = new TransactionAdmin(new PrintStream(out), new PrintStream(err)); int status = txAdmin.doMain(new String[]{"--get-invalid-tx-size"}, conf); Assert.assertEquals(0, status); Assert.assertTrue(out.toString("UTF-8").contains("Invalid list size: 1\n")); }
@VisibleForTesting int doMain(String[] args, Configuration conf) { if (args.length < 1) { printUsage(); return 1; } Injector injector = Guice.createInjector( new ConfigModule(conf), new ZKModule(), new DiscoveryModules().getDistributedModules(), new TransactionModules().getDistributedModules(), new TransactionClientModule() ); ZKClientService zkClient = injector.getInstance(ZKClientService.class); zkClient.startAndWait(); try { TransactionSystemClient txClient = injector.getInstance(TransactionSystemClient.class); String option = args[0]; if (option.equals(OPT_TRUNCATE_INVALID_TX)) { if (args.length != 2) { printUsage(); return 1; } Set<Long> txIds; try { txIds = parseTxIds(args[1]); } catch (NumberFormatException e) { err.println("NumberFormatException: " + e.getMessage()); return 1; } if (!txIds.isEmpty()) { out.println("Invalid list size before truncation: " + txClient.getInvalidSize()); txClient.truncateInvalidTx(txIds); out.println("Invalid list size after truncation: " + txClient.getInvalidSize()); } } else if (option.equals(OPT_TRUNCATE_INVALID_TX_BEFORE)) { if (args.length != 2) { printUsage(); return 1; } try { long time = Long.parseLong(args[1]); out.println("Invalid list size before truncation: " + txClient.getInvalidSize()); txClient.truncateInvalidTxBefore(time); out.println("Invalid list size after truncation: " + txClient.getInvalidSize()); } catch (InvalidTruncateTimeException e) { err.println(e.getMessage()); return 1; } catch (NumberFormatException e) { err.println("NumberFormatException: " + e.getMessage()); return 1; } } else if (option.equals(OPT_GET_INVALID_TX_SIZE)) { if (args.length != 1) { printUsage(); return 1; } out.println("Invalid list size: " + txClient.getInvalidSize()); } else { printUsage(); return 1; } } finally { zkClient.stopAndWait(); } return 0; }
TransactionAdmin { @VisibleForTesting int doMain(String[] args, Configuration conf) { if (args.length < 1) { printUsage(); return 1; } Injector injector = Guice.createInjector( new ConfigModule(conf), new ZKModule(), new DiscoveryModules().getDistributedModules(), new TransactionModules().getDistributedModules(), new TransactionClientModule() ); ZKClientService zkClient = injector.getInstance(ZKClientService.class); zkClient.startAndWait(); try { TransactionSystemClient txClient = injector.getInstance(TransactionSystemClient.class); String option = args[0]; if (option.equals(OPT_TRUNCATE_INVALID_TX)) { if (args.length != 2) { printUsage(); return 1; } Set<Long> txIds; try { txIds = parseTxIds(args[1]); } catch (NumberFormatException e) { err.println("NumberFormatException: " + e.getMessage()); return 1; } if (!txIds.isEmpty()) { out.println("Invalid list size before truncation: " + txClient.getInvalidSize()); txClient.truncateInvalidTx(txIds); out.println("Invalid list size after truncation: " + txClient.getInvalidSize()); } } else if (option.equals(OPT_TRUNCATE_INVALID_TX_BEFORE)) { if (args.length != 2) { printUsage(); return 1; } try { long time = Long.parseLong(args[1]); out.println("Invalid list size before truncation: " + txClient.getInvalidSize()); txClient.truncateInvalidTxBefore(time); out.println("Invalid list size after truncation: " + txClient.getInvalidSize()); } catch (InvalidTruncateTimeException e) { err.println(e.getMessage()); return 1; } catch (NumberFormatException e) { err.println("NumberFormatException: " + e.getMessage()); return 1; } } else if (option.equals(OPT_GET_INVALID_TX_SIZE)) { if (args.length != 1) { printUsage(); return 1; } out.println("Invalid list size: " + txClient.getInvalidSize()); } else { printUsage(); return 1; } } finally { zkClient.stopAndWait(); } return 0; } }
TransactionAdmin { @VisibleForTesting int doMain(String[] args, Configuration conf) { if (args.length < 1) { printUsage(); return 1; } Injector injector = Guice.createInjector( new ConfigModule(conf), new ZKModule(), new DiscoveryModules().getDistributedModules(), new TransactionModules().getDistributedModules(), new TransactionClientModule() ); ZKClientService zkClient = injector.getInstance(ZKClientService.class); zkClient.startAndWait(); try { TransactionSystemClient txClient = injector.getInstance(TransactionSystemClient.class); String option = args[0]; if (option.equals(OPT_TRUNCATE_INVALID_TX)) { if (args.length != 2) { printUsage(); return 1; } Set<Long> txIds; try { txIds = parseTxIds(args[1]); } catch (NumberFormatException e) { err.println("NumberFormatException: " + e.getMessage()); return 1; } if (!txIds.isEmpty()) { out.println("Invalid list size before truncation: " + txClient.getInvalidSize()); txClient.truncateInvalidTx(txIds); out.println("Invalid list size after truncation: " + txClient.getInvalidSize()); } } else if (option.equals(OPT_TRUNCATE_INVALID_TX_BEFORE)) { if (args.length != 2) { printUsage(); return 1; } try { long time = Long.parseLong(args[1]); out.println("Invalid list size before truncation: " + txClient.getInvalidSize()); txClient.truncateInvalidTxBefore(time); out.println("Invalid list size after truncation: " + txClient.getInvalidSize()); } catch (InvalidTruncateTimeException e) { err.println(e.getMessage()); return 1; } catch (NumberFormatException e) { err.println("NumberFormatException: " + e.getMessage()); return 1; } } else if (option.equals(OPT_GET_INVALID_TX_SIZE)) { if (args.length != 1) { printUsage(); return 1; } out.println("Invalid list size: " + txClient.getInvalidSize()); } else { printUsage(); return 1; } } finally { zkClient.stopAndWait(); } return 0; } TransactionAdmin(PrintStream out, PrintStream err); }
TransactionAdmin { @VisibleForTesting int doMain(String[] args, Configuration conf) { if (args.length < 1) { printUsage(); return 1; } Injector injector = Guice.createInjector( new ConfigModule(conf), new ZKModule(), new DiscoveryModules().getDistributedModules(), new TransactionModules().getDistributedModules(), new TransactionClientModule() ); ZKClientService zkClient = injector.getInstance(ZKClientService.class); zkClient.startAndWait(); try { TransactionSystemClient txClient = injector.getInstance(TransactionSystemClient.class); String option = args[0]; if (option.equals(OPT_TRUNCATE_INVALID_TX)) { if (args.length != 2) { printUsage(); return 1; } Set<Long> txIds; try { txIds = parseTxIds(args[1]); } catch (NumberFormatException e) { err.println("NumberFormatException: " + e.getMessage()); return 1; } if (!txIds.isEmpty()) { out.println("Invalid list size before truncation: " + txClient.getInvalidSize()); txClient.truncateInvalidTx(txIds); out.println("Invalid list size after truncation: " + txClient.getInvalidSize()); } } else if (option.equals(OPT_TRUNCATE_INVALID_TX_BEFORE)) { if (args.length != 2) { printUsage(); return 1; } try { long time = Long.parseLong(args[1]); out.println("Invalid list size before truncation: " + txClient.getInvalidSize()); txClient.truncateInvalidTxBefore(time); out.println("Invalid list size after truncation: " + txClient.getInvalidSize()); } catch (InvalidTruncateTimeException e) { err.println(e.getMessage()); return 1; } catch (NumberFormatException e) { err.println("NumberFormatException: " + e.getMessage()); return 1; } } else if (option.equals(OPT_GET_INVALID_TX_SIZE)) { if (args.length != 1) { printUsage(); return 1; } out.println("Invalid list size: " + txClient.getInvalidSize()); } else { printUsage(); return 1; } } finally { zkClient.stopAndWait(); } return 0; } TransactionAdmin(PrintStream out, PrintStream err); static void main(String[] args); }
TransactionAdmin { @VisibleForTesting int doMain(String[] args, Configuration conf) { if (args.length < 1) { printUsage(); return 1; } Injector injector = Guice.createInjector( new ConfigModule(conf), new ZKModule(), new DiscoveryModules().getDistributedModules(), new TransactionModules().getDistributedModules(), new TransactionClientModule() ); ZKClientService zkClient = injector.getInstance(ZKClientService.class); zkClient.startAndWait(); try { TransactionSystemClient txClient = injector.getInstance(TransactionSystemClient.class); String option = args[0]; if (option.equals(OPT_TRUNCATE_INVALID_TX)) { if (args.length != 2) { printUsage(); return 1; } Set<Long> txIds; try { txIds = parseTxIds(args[1]); } catch (NumberFormatException e) { err.println("NumberFormatException: " + e.getMessage()); return 1; } if (!txIds.isEmpty()) { out.println("Invalid list size before truncation: " + txClient.getInvalidSize()); txClient.truncateInvalidTx(txIds); out.println("Invalid list size after truncation: " + txClient.getInvalidSize()); } } else if (option.equals(OPT_TRUNCATE_INVALID_TX_BEFORE)) { if (args.length != 2) { printUsage(); return 1; } try { long time = Long.parseLong(args[1]); out.println("Invalid list size before truncation: " + txClient.getInvalidSize()); txClient.truncateInvalidTxBefore(time); out.println("Invalid list size after truncation: " + txClient.getInvalidSize()); } catch (InvalidTruncateTimeException e) { err.println(e.getMessage()); return 1; } catch (NumberFormatException e) { err.println("NumberFormatException: " + e.getMessage()); return 1; } } else if (option.equals(OPT_GET_INVALID_TX_SIZE)) { if (args.length != 1) { printUsage(); return 1; } out.println("Invalid list size: " + txClient.getInvalidSize()); } else { printUsage(); return 1; } } finally { zkClient.stopAndWait(); } return 0; } TransactionAdmin(PrintStream out, PrintStream err); static void main(String[] args);  }