예제 #1
0
  /**
   * Tests whether data in valuesIterator matches with sorted input data set.
   *
   * <p>Returns a list of value counts for each key.
   *
   * @param valuesIterator
   * @return List
   * @throws IOException
   */
  private List<Integer> verifyIteratorData(ValuesIterator valuesIterator) throws IOException {
    boolean result = true;

    ArrayList<Integer> sequence = new ArrayList<Integer>();

    // sort original data based on comparator
    ListMultimap<Writable, Writable> sortedMap =
        new ImmutableListMultimap.Builder<Writable, Writable>()
            .orderKeysBy(this.correctComparator)
            .putAll(originalData)
            .build();

    Set<Map.Entry<Writable, Writable>> oriKeySet = Sets.newSet();
    oriKeySet.addAll(sortedMap.entries());

    // Iterate through sorted data and valuesIterator for verification
    for (Map.Entry<Writable, Writable> entry : oriKeySet) {

      assertTrue(valuesIterator.moveToNext());

      Writable oriKey = entry.getKey();
      // Verify if the key and the original key are same
      if (!oriKey.equals((Writable) valuesIterator.getKey())) {
        result = false;
        break;
      }

      int valueCount = 0;
      // Verify values
      Iterator<Writable> vItr = valuesIterator.getValues().iterator();
      for (Writable val : sortedMap.get(oriKey)) {
        assertTrue(vItr.hasNext());

        // Verify if the values are same
        if (!val.equals((Writable) vItr.next())) {
          result = false;
          break;
        }

        valueCount++;
      }
      sequence.add(valueCount);
      assertTrue("At least 1 value per key", valueCount > 0);
    }
    if (expectedTestResult) {
      assertTrue(result);

      assertFalse(valuesIterator.moveToNext());
      getNextFromFinishedIterator(valuesIterator);
    } else {
      while (valuesIterator.moveToNext()) {
        // iterate through all keys
      }
      getNextFromFinishedIterator(valuesIterator);
      assertFalse(result);
    }

    return sequence;
  }
예제 #2
0
  @Test(timeout = 20000)
  public void testIteratorWithIFileReaderEmptyPartitions()
      throws IOException, InterruptedException {
    ValuesIterator iterator = createEmptyIterator(false);
    assertTrue(iterator.moveToNext() == false);

    iterator = createEmptyIterator(true);
    assertTrue(iterator.moveToNext() == false);
  }
예제 #3
0
 private void getNextFromFinishedIterator(ValuesIterator iterator) {
   try {
     boolean hasNext = iterator.moveToNext();
     fail();
   } catch (IOException e) {
     assertTrue(e.getMessage().contains("Please check if you are invoking moveToNext()"));
   }
 }