Exemplo n.º 1
0
  /** Tests setting the splitable configuration. */
  @Test
  public void testNotSplitable() {
    // Add a new value that we won't split
    CKeyValue keyValue =
        new CKeyValue(
            rowId.getBytes(),
            colFam1.getBytes(),
            colQual1.getBytes(),
            "broken glass everyone".getBytes());
    Put put = new Put(keyValue);

    // Set the splitable indicator to false
    TermBasedIndex.setSplitable(false, conf);

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

    // Get all the data back
    SeekingCurrentIterator indexIterator = termIndex.handleGet(new byte[0], new byte[0]);

    // 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
    // 3 for the original values in setup() and 1 for the new value
    assertTrue(count == 4);
  }
Exemplo n.º 2
0
  /**
   * Tests whether the TermBasedIndex is able to retrieve a specific range. Implicitly tests putting
   * the data.
   */
  @Test
  public void testGetSteve() {
    // Get steve back
    byte[] steveBytes = "steve".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[steveBytes.length + 1];
    System.arraycopy(steveBytes, 0, end, 0, steveBytes.length);
    end[end.length - 1] = 0x01;

    SeekingCurrentIterator indexIterator = termIndex.handleGet(steveBytes, 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);
  }
Exemplo n.º 3
0
  /**
   * Tests whether the TermBasedIndex is able to retrieve all the data. Implicitly tests putting the
   * data.
   */
  @Test
  public void testGetAll() {
    // Get all the data back
    SeekingCurrentIterator indexIterator = termIndex.handleGet(new byte[0], new byte[0]);

    // 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 == 3);
  }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
0
  /** Tests setting the lower case configuration. */
  @Test
  public void testNotLowerCase() {
    // Add a new value that we won't lower case
    CKeyValue keyValue =
        new CKeyValue(
            rowId.getBytes(),
            colFam1.getBytes(),
            colQual1.getBytes(),
            "That was the old Fry. He's dead now.".getBytes());
    Put put = new Put(keyValue);

    // Set the splitable indicator to false
    TermBasedIndex.setToLower(false, conf);

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

    // Get Fry back
    byte[] fryBytes = "Fry".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[fryBytes.length + 1];
    System.arraycopy(fryBytes, 0, end, 0, fryBytes.length);
    end[end.length - 1] = 0x01;

    SeekingCurrentIterator indexIterator = termIndex.handleGet(fryBytes, 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);
  }