use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestPassCustomCellViaRegionObserver method testMutation.
@Test
public void testMutation() throws Exception {
Put put = new Put(ROW);
put.addColumn(FAMILY, QUALIFIER, VALUE);
table.put(put);
byte[] value = VALUE;
assertResult(table.get(new Get(ROW)), value, value);
assertObserverHasExecuted();
Increment inc = new Increment(ROW);
inc.addColumn(FAMILY, QUALIFIER, 10L);
table.increment(inc);
// QUALIFIER -> 10 (put) + 10 (increment)
// QUALIFIER_FROM_CP -> 10 (from cp's put) + 10 (from cp's increment)
value = Bytes.toBytes(20L);
assertResult(table.get(new Get(ROW)), value, value);
assertObserverHasExecuted();
Append append = new Append(ROW);
append.addColumn(FAMILY, QUALIFIER, APPEND_VALUE);
table.append(append);
// 10L + "MB"
value = ByteBuffer.wrap(new byte[value.length + APPEND_VALUE.length]).put(value).put(APPEND_VALUE).array();
assertResult(table.get(new Get(ROW)), value, value);
assertObserverHasExecuted();
Delete delete = new Delete(ROW);
delete.addColumns(FAMILY, QUALIFIER);
table.delete(delete);
assertTrue(Arrays.asList(table.get(new Get(ROW)).rawCells()).toString(), table.get(new Get(ROW)).isEmpty());
assertObserverHasExecuted();
assertTrue(table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER).ifNotExists().thenPut(put));
assertObserverHasExecuted();
assertTrue(table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER).ifEquals(VALUE).thenDelete(delete));
assertObserverHasExecuted();
assertTrue(table.get(new Get(ROW)).isEmpty());
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestRegionObserverInterface method testCheckAndAppendHooks.
@Test
public void testCheckAndAppendHooks() 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 Append(row).addColumn(A, A, A)));
verifyMethodResult(SimpleRegionObserver.class, new String[] { "getPreCheckAndMutate", "getPreCheckAndMutateAfterRowLock", "getPostCheckAndMutate" }, tableName, new Integer[] { 1, 1, 1 });
table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(A, A, A).build(new Append(row).addColumn(A, A, A)));
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.Append in project hbase by apache.
the class TestPostIncrementAndAppendBeforeWAL method testChangeCellWithDifferntColumnFamily.
@Test
public void testChangeCellWithDifferntColumnFamily() throws Exception {
TableName tableName = TableName.valueOf(name.getMethodName());
createTableWithCoprocessor(tableName, ChangeCellWithDifferntColumnFamilyObserver.class.getName());
try (Table table = connection.getTable(tableName)) {
Increment increment = new Increment(ROW).addColumn(CF1_BYTES, CQ1, 1);
table.increment(increment);
Get get = new Get(ROW).addColumn(CF2_BYTES, CQ1);
Result result = table.get(get);
assertEquals(1, result.size());
assertEquals(1, Bytes.toLong(result.getValue(CF2_BYTES, CQ1)));
Append append = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE);
table.append(append);
get = new Get(ROW).addColumn(CF2_BYTES, CQ2);
result = table.get(get);
assertEquals(1, result.size());
assertTrue(Bytes.equals(VALUE, result.getValue(CF2_BYTES, CQ2)));
}
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestPostIncrementAndAppendBeforeWAL method testAppendTTLWithACLTag.
@Test
public void testAppendTTLWithACLTag() throws Exception {
TableName tableName = TableName.valueOf(name.getMethodName());
createTableWithCoprocessor(tableName, ChangeCellWithACLTagObserver.class.getName());
try (Table table = connection.getTable(tableName)) {
// Append without TTL
Append firstAppend = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE).setACL(USER, PERMS);
Result result = table.append(firstAppend);
assertEquals(1, result.size());
assertTrue(Bytes.equals(VALUE, result.getValue(CF1_BYTES, CQ2)));
// Check if the new cell can be read
Get get = new Get(ROW).addColumn(CF1_BYTES, CQ2);
result = table.get(get);
assertEquals(1, result.size());
assertTrue(Bytes.equals(VALUE, result.getValue(CF1_BYTES, CQ2)));
// Append with TTL
Append secondAppend = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE).setTTL(1000).setACL(USER, PERMS);
result = table.append(secondAppend);
// We should get "valuevalue""
assertEquals(1, result.size());
assertTrue(Bytes.equals(VALUE2, result.getValue(CF1_BYTES, CQ2)));
// Wait 4s to let the second append expire
Thread.sleep(4000);
get = new Get(ROW).addColumn(CF1_BYTES, CQ2);
result = table.get(get);
// The value should revert to "value"
assertEquals(1, result.size());
assertTrue(Bytes.equals(VALUE, result.getValue(CF1_BYTES, CQ2)));
}
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestIncrementAndAppendWithNullResult method testAppend.
@Test
public void testAppend() throws Exception {
testAppend(new Append(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, Bytes.toBytes("value")));
testAppend(new Append(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, Bytes.toBytes("value")).setReturnResults(false));
}
Aggregations