use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.
the class TestRegionObserverInterface method testCheckAndIncrementHooks.
@Test
public void testCheckAndIncrementHooks() throws Exception {
final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try {
byte[] row = Bytes.toBytes(0);
verifyMethodResult(SimpleRegionObserver.class, new String[] { "getPreCheckAndMutate", "getPreCheckAndMutateAfterRowLock", "getPostCheckAndMutate" }, tableName, new Integer[] { 0, 0, 0 });
table.checkAndMutate(CheckAndMutate.newBuilder(row).ifNotExists(A, A).build(new Increment(row).addColumn(A, A, 1)));
verifyMethodResult(SimpleRegionObserver.class, new String[] { "getPreCheckAndMutate", "getPreCheckAndMutateAfterRowLock", "getPostCheckAndMutate" }, tableName, new Integer[] { 1, 1, 1 });
table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(A, A, Bytes.toBytes(1L)).build(new Increment(row).addColumn(A, A, 1)));
verifyMethodResult(SimpleRegionObserver.class, new String[] { "getPreCheckAndMutate", "getPreCheckAndMutateAfterRowLock", "getPostCheckAndMutate" }, tableName, new Integer[] { 2, 2, 2 });
} finally {
util.deleteTable(tableName);
table.close();
}
}
use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.
the class TestHRegion method testIncrWithReadOnlyTable.
@Test
public void testIncrWithReadOnlyTable() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
this.region = initHRegion(tableName, method, CONF, true, Bytes.toBytes("somefamily"));
boolean exceptionCaught = false;
Increment inc = new Increment(Bytes.toBytes("somerow"));
inc.setDurability(Durability.SKIP_WAL);
inc.addColumn(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"), 1L);
try {
region.increment(inc);
} catch (IOException e) {
exceptionCaught = true;
}
assertTrue(exceptionCaught == true);
}
use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.
the class TestHRegion method testCheckAndRowMutations.
@Test
public void testCheckAndRowMutations() throws Throwable {
final byte[] row = Bytes.toBytes("row");
final byte[] q1 = Bytes.toBytes("q1");
final byte[] q2 = Bytes.toBytes("q2");
final byte[] q3 = Bytes.toBytes("q3");
final byte[] q4 = Bytes.toBytes("q4");
final String v1 = "v1";
region = initHRegion(tableName, method, CONF, fam1);
// Initial values
region.batchMutate(new Mutation[] { new Put(row).addColumn(fam1, q2, Bytes.toBytes("toBeDeleted")), new Put(row).addColumn(fam1, q3, Bytes.toBytes(5L)), new Put(row).addColumn(fam1, q4, Bytes.toBytes("a")) });
// Do CheckAndRowMutations
CheckAndMutate checkAndMutate = CheckAndMutate.newBuilder(row).ifNotExists(fam1, q1).build(new RowMutations(row).add(Arrays.asList(new Put(row).addColumn(fam1, q1, Bytes.toBytes(v1)), new Delete(row).addColumns(fam1, q2), new Increment(row).addColumn(fam1, q3, 1), new Append(row).addColumn(fam1, q4, Bytes.toBytes("b")))));
CheckAndMutateResult result = region.checkAndMutate(checkAndMutate);
assertTrue(result.isSuccess());
assertEquals(6L, Bytes.toLong(result.getResult().getValue(fam1, q3)));
assertEquals("ab", Bytes.toString(result.getResult().getValue(fam1, q4)));
// Verify the value
Result r = region.get(new Get(row));
assertEquals(v1, Bytes.toString(r.getValue(fam1, q1)));
assertNull(r.getValue(fam1, q2));
assertEquals(6L, Bytes.toLong(r.getValue(fam1, q3)));
assertEquals("ab", Bytes.toString(r.getValue(fam1, q4)));
// Do CheckAndRowMutations again
checkAndMutate = CheckAndMutate.newBuilder(row).ifNotExists(fam1, q1).build(new RowMutations(row).add(Arrays.asList(new Delete(row).addColumns(fam1, q1), new Put(row).addColumn(fam1, q2, Bytes.toBytes(v1)), new Increment(row).addColumn(fam1, q3, 1), new Append(row).addColumn(fam1, q4, Bytes.toBytes("b")))));
result = region.checkAndMutate(checkAndMutate);
assertFalse(result.isSuccess());
assertNull(result.getResult());
// Verify the value
r = region.get(new Get(row));
assertEquals(v1, Bytes.toString(r.getValue(fam1, q1)));
assertNull(r.getValue(fam1, q2));
assertEquals(6L, Bytes.toLong(r.getValue(fam1, q3)));
assertEquals("ab", Bytes.toString(r.getValue(fam1, q4)));
}
use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.
the class TestHRegion method testCheckAndIncrement.
@Test
public void testCheckAndIncrement() throws Throwable {
final byte[] FAMILY = Bytes.toBytes("fam");
// Setting up region
this.region = initHRegion(tableName, method, CONF, FAMILY);
region.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")));
// CheckAndIncrement with correct value
CheckAndMutateResult res = region.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")).build(new Increment(row).addColumn(FAMILY, Bytes.toBytes("B"), 1)));
assertTrue(res.isSuccess());
assertEquals(1, Bytes.toLong(res.getResult().getValue(FAMILY, Bytes.toBytes("B"))));
Result result = region.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B")));
assertEquals(1, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("B"))));
// CheckAndIncrement with wrong value
res = region.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("b")).build(new Increment(row).addColumn(FAMILY, Bytes.toBytes("B"), 1)));
assertFalse(res.isSuccess());
assertNull(res.getResult());
result = region.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B")));
assertEquals(1, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("B"))));
region.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")));
// CheckAndIncrement with a filter and correct value
res = region.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new FilterList(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a")), new SingleColumnValueFilter(FAMILY, Bytes.toBytes("C"), CompareOperator.EQUAL, Bytes.toBytes("c")))).build(new Increment(row).addColumn(FAMILY, Bytes.toBytes("B"), 2)));
assertTrue(res.isSuccess());
assertEquals(3, Bytes.toLong(res.getResult().getValue(FAMILY, Bytes.toBytes("B"))));
result = region.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B")));
assertEquals(3, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("B"))));
// CheckAndIncrement with a filter and correct value
res = region.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new FilterList(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("b")), new SingleColumnValueFilter(FAMILY, Bytes.toBytes("C"), CompareOperator.EQUAL, Bytes.toBytes("d")))).build(new Increment(row).addColumn(FAMILY, Bytes.toBytes("B"), 2)));
assertFalse(res.isSuccess());
assertNull(res.getResult());
result = region.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B")));
assertEquals(3, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("B"))));
}
use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.
the class TestRegionServerMetrics method testIncrement.
@Test
public void testIncrement() throws Exception {
Put p = new Put(row).addColumn(cf, qualifier, Bytes.toBytes(0L));
table.put(p);
for (int count = 0; count < 13; count++) {
Increment inc = new Increment(row);
inc.addColumn(cf, qualifier, 100);
table.increment(inc);
}
metricsRegionServer.getRegionServerWrapper().forceRecompute();
assertCounter("incrementNumOps", 13);
}
Aggregations