示例#1
0
  /** Tests setting the token regex configuration. */
  @Test
  public void testTokenRegex() {
    // Add a new value that we won't split
    CKeyValue keyValue =
        new CKeyValue(
            rowId.getBytes(),
            colFam1.getBytes(),
            colQual1.getBytes(),
            "I'm not sure how one spells splitable. Is it even a word?".getBytes());
    Put put = new Put(keyValue);

    // Set the split regex to splittable.
    TermBasedIndex.setTokenRegex("splitable", conf);

    // Insert the data
    termIndex.handlePut(put);

    // Get Fry back
    byte[] partBytes = "i'm not sure how one spells ".getBytes();

    // The end byte object should look like: steve\x01
    // This represents the next possible value which is allowable
    // since we pad the value with 6 null bytes.
    byte[] end = new byte[partBytes.length + 1];
    System.arraycopy(partBytes, 0, end, 0, partBytes.length);
    end[end.length - 1] = 0x01;

    SeekingCurrentIterator indexIterator = termIndex.handleGet(partBytes, end);

    // Test the returned data
    int count = 0;
    while (indexIterator.hasNext()) {
      Result result = indexIterator.next();
      count++;

      assertTrue(Bytes.compareTo(result.getRecordId(), rowIdBytes) == 0);
    }

    // Test if we have the expected number of results
    assertTrue(count == 1);
  }