示例#1
0
    @Override
    public void run() {
      byte[] value = new byte[100];
      Put[] in = new Put[1];

      // iterate for the specified number of operations
      for (int i = 0; i < numOps; i++) {
        // generate random bytes
        rand.nextBytes(value);

        // put the randombytes and verify that we can read it. This is one
        // way of ensuring that rwcc manipulation in HRegion.put() is fine.
        Put put = new Put(rowkey);
        put.add(fam1, qual1, value);
        in[0] = put;
        try {
          OperationStatus[] ret = region.put(in);
          assertEquals(1, ret.length);
          assertEquals(OperationStatusCode.SUCCESS, ret[0].getOperationStatusCode());
          assertGet(rowkey, fam1, qual1, value);
        } catch (IOException e) {
          assertTrue("Thread id " + threadNumber + " operation " + i + " failed.", false);
        }
      }
    }
示例#2
0
  private static void assertGet(byte[] row, byte[] familiy, byte[] qualifier, byte[] value)
      throws IOException {
    // run a get and see if the value matches
    Get get = new Get(row);
    get.addColumn(familiy, qualifier);
    Result result = region.get(get, null);
    assertEquals(1, result.size());

    KeyValue kv = result.raw()[0];
    byte[] r = kv.getValue();
    assertTrue(Bytes.compareTo(r, value) == 0);
  }
示例#3
0
  /** Test one put command. */
  public void testPut() throws IOException {
    LOG.info("Starting testPut");
    initHRegion(tableName, getName(), fam1);

    long value = 1L;

    Put put = new Put(row);
    put.add(fam1, qual1, Bytes.toBytes(value));
    region.put(put);

    assertGet(row, fam1, qual1, Bytes.toBytes(value));
  }
示例#4
0
 private void initHRegion(
     byte[] tableName, String callingMethod, Configuration conf, byte[]... families)
     throws IOException {
   HTableDescriptor htd = new HTableDescriptor(tableName);
   for (byte[] family : families) {
     htd.addFamily(new HColumnDescriptor(family));
   }
   HRegionInfo info = new HRegionInfo(htd.getName(), null, null, false);
   Path path = new Path(DIR + callingMethod);
   if (fs.exists(path)) {
     if (!fs.delete(path, true)) {
       throw new IOException("Failed delete of " + path);
     }
   }
   region = HRegion.createHRegion(info, path, conf, htd);
 }