public static void main()

in java/dataproc-wordcount/src/main/java/com/example/bigtable/sample/ValidateWordCount.java [39:66]


  public static void main(String[] args) throws IOException {
    Configuration conf = HBaseConfiguration.create();
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if (otherArgs.length < 2) {
      System.err.println("Usage: java -cp <this jar>:<hbase classpath> "
          + ValidateWordCount.class.getName() + " <table-name> <expected count>");
      System.exit(2);
    }

    TableName tableName = TableName.valueOf(otherArgs[0]);
    int expectedCount = Integer.parseInt(otherArgs[1]);

    Scan scan = new Scan();
    scan.addFamily(Bytes.toBytes("cf"));
    scan.setStartRow(Bytes.toBytes(""));
    int count = 0;

    try (Connection conn = ConnectionFactory.createConnection(conf);
        Table table = conn.getTable(tableName);
        ResultScanner rs = table.getScanner(scan)) {
      for (Result result : rs) {
        count++;
      }
    }

    System.out.println("Count: " + count + ".  Expected: " + expectedCount);
    System.exit(count == expectedCount ? 0 : 1);
  }