예제 #1
0
 /** Assert CellUtil makes Cell toStrings same way we do KeyValue toStrings. */
 @Test
 public void testToString() {
   byte[] row = Bytes.toBytes("row");
   long ts = 123l;
   // Make a KeyValue and a Cell and see if same toString result.
   KeyValue kv =
       new KeyValue(
           row,
           HConstants.EMPTY_BYTE_ARRAY,
           HConstants.EMPTY_BYTE_ARRAY,
           ts,
           KeyValue.Type.Minimum,
           HConstants.EMPTY_BYTE_ARRAY);
   Cell cell =
       CellUtil.createCell(
           row,
           HConstants.EMPTY_BYTE_ARRAY,
           HConstants.EMPTY_BYTE_ARRAY,
           ts,
           KeyValue.Type.Minimum.getCode(),
           HConstants.EMPTY_BYTE_ARRAY);
   String cellToString = CellUtil.getCellKeyAsString(cell);
   assertEquals(kv.toString(), cellToString);
   // Do another w/ non-null family.
   byte[] f = new byte[] {'f'};
   byte[] q = new byte[] {'q'};
   kv = new KeyValue(row, f, q, ts, KeyValue.Type.Minimum, HConstants.EMPTY_BYTE_ARRAY);
   cell =
       CellUtil.createCell(
           row, f, q, ts, KeyValue.Type.Minimum.getCode(), HConstants.EMPTY_BYTE_ARRAY);
   cellToString = CellUtil.getCellKeyAsString(cell);
   assertEquals(kv.toString(), cellToString);
 }
예제 #2
0
  @Test
  public void testToString1() {
    String row = "test.row";
    String family = "test.family";
    String qualifier = "test.qualifier";
    long timestamp = 42;
    Type type = Type.Put;
    String value = "test.value";
    long seqId = 1042;

    Cell cell =
        CellUtil.createCell(
            Bytes.toBytes(row),
            Bytes.toBytes(family),
            Bytes.toBytes(qualifier),
            timestamp,
            type.getCode(),
            Bytes.toBytes(value),
            seqId);

    String nonVerbose = CellUtil.toString(cell, false);
    String verbose = CellUtil.toString(cell, true);

    System.out.println("nonVerbose=" + nonVerbose);
    System.out.println("verbose=" + verbose);

    Assert.assertEquals(
        String.format(
            "%s/%s:%s/%d/%s/vlen=%s/seqid=%s",
            row, family, qualifier, timestamp, type.toString(), Bytes.toBytes(value).length, seqId),
        nonVerbose);

    Assert.assertEquals(
        String.format(
            "%s/%s:%s/%d/%s/vlen=%s/seqid=%s/%s",
            row,
            family,
            qualifier,
            timestamp,
            type.toString(),
            Bytes.toBytes(value).length,
            seqId,
            value),
        verbose);

    // TODO: test with tags
  }