コード例 #1
0
ファイル: TestRowCounter.java プロジェクト: lilonglai/hbase
  /**
   * Test a case when the timerange is specified with --starttime and --endtime options
   *
   * @throws Exception
   */
  @Test
  public void testRowCounterTimeRange() throws Exception {
    final byte[] family = Bytes.toBytes(COL_FAM);
    final byte[] col1 = Bytes.toBytes(COL1);
    Put put1 = new Put(Bytes.toBytes("row_timerange_" + 1));
    Put put2 = new Put(Bytes.toBytes("row_timerange_" + 2));
    Put put3 = new Put(Bytes.toBytes("row_timerange_" + 3));

    long ts;

    // clean up content of TABLE_NAME
    HTable table = TEST_UTIL.deleteTableData(TableName.valueOf(TABLE_NAME));
    ts = System.currentTimeMillis();
    put1.add(family, col1, ts, Bytes.toBytes("val1"));
    table.put(put1);
    Thread.sleep(100);

    ts = System.currentTimeMillis();
    put2.add(family, col1, ts, Bytes.toBytes("val2"));
    put3.add(family, col1, ts, Bytes.toBytes("val3"));
    table.put(put2);
    table.put(put3);
    table.close();

    String[] args =
        new String[] {TABLE_NAME, COL_FAM + ":" + COL1, "--starttime=" + 0, "--endtime=" + ts};
    runRowCount(args, 1);

    args =
        new String[] {
          TABLE_NAME, COL_FAM + ":" + COL1, "--starttime=" + 0, "--endtime=" + (ts - 10)
        };
    runRowCount(args, 1);

    args =
        new String[] {
          TABLE_NAME, COL_FAM + ":" + COL1, "--starttime=" + ts, "--endtime=" + (ts + 1000)
        };
    runRowCount(args, 2);

    args =
        new String[] {
          TABLE_NAME,
          COL_FAM + ":" + COL1,
          "--starttime=" + (ts - 30 * 1000),
          "--endtime=" + (ts + 30 * 1000),
        };
    runRowCount(args, 3);
  }