예제 #1
0
 /**
  * Helper method for a {@link KeyValueBuilder} that catches an IOException from a {@link Put} when
  * adding a {@link KeyValue} generated by the KeyValueBuilder.
  *
  * @throws RuntimeException if there is an IOException thrown from the underlying {@link Put}
  */
 @SuppressWarnings("javadoc")
 public static void deleteQuietly(Delete delete, KeyValueBuilder builder, KeyValue kv) {
   try {
     delete.addDeleteMarker(kv);
   } catch (IOException e) {
     throw new RuntimeException(
         "KeyValue Builder " + builder + " created an invalid kv: " + kv + "!");
   }
 }
      @Override
      public void process(long now, HRegion region, List<Mutation> mutations, WALEdit walEdit)
          throws IOException {

        // Override the time to avoid race-condition in the unit test caused by
        // inacurate timer on some machines
        now = myTimer.getAndIncrement();

        // Scan both rows
        List<Cell> kvs1 = new ArrayList<Cell>();
        List<Cell> kvs2 = new ArrayList<Cell>();
        doScan(region, new Scan(row1, row1), kvs1);
        doScan(region, new Scan(row2, row2), kvs2);

        // Assert swapped
        if (swapped) {
          assertEquals(rowSize, kvs2.size());
          assertEquals(row2Size, kvs1.size());
        } else {
          assertEquals(rowSize, kvs1.size());
          assertEquals(row2Size, kvs2.size());
        }
        swapped = !swapped;

        // Add and delete keyvalues
        List<List<Cell>> kvs = new ArrayList<List<Cell>>();
        kvs.add(kvs1);
        kvs.add(kvs2);
        byte[][] rows = new byte[][] {row1, row2};
        for (int i = 0; i < kvs.size(); ++i) {
          for (Cell kv : kvs.get(i)) {
            // Delete from the current row and add to the other row
            Delete d = new Delete(rows[i]);
            KeyValue kvDelete =
                new KeyValue(
                    rows[i],
                    CellUtil.cloneFamily(kv),
                    CellUtil.cloneQualifier(kv),
                    kv.getTimestamp(),
                    KeyValue.Type.Delete);
            d.addDeleteMarker(kvDelete);
            Put p = new Put(rows[1 - i]);
            KeyValue kvAdd =
                new KeyValue(
                    rows[1 - i],
                    CellUtil.cloneFamily(kv),
                    CellUtil.cloneQualifier(kv),
                    now,
                    CellUtil.cloneValue(kv));
            p.add(kvAdd);
            mutations.add(d);
            walEdit.add(kvDelete);
            mutations.add(p);
            walEdit.add(kvAdd);
          }
        }
      }