use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestSpaceQuotaBasicFunctioning method testNoWritesWithAppend.
@Test
public void testNoWritesWithAppend() throws Exception {
Append a = new Append(Bytes.toBytes("to_reject"));
a.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), Bytes.toBytes("reject"));
helper.writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_WRITES, a);
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestRegionServerMetrics method testAppend.
@Test
public void testAppend() throws Exception {
doNPuts(1, false);
for (int count = 0; count < 73; count++) {
Append append = new Append(row);
append.addColumn(cf, qualifier, Bytes.toBytes(",Test"));
table.append(append);
}
metricsRegionServer.getRegionServerWrapper().forceRecompute();
assertCounter("appendNumOps", 73);
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestVisibilityLabels method testLabelsWithAppend.
@Test
public void testLabelsWithAppend() throws Throwable {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
try (Table table = TEST_UTIL.createTable(tableName, fam)) {
byte[] row1 = Bytes.toBytes("row1");
byte[] val = Bytes.toBytes("a");
Put put = new Put(row1);
put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, val);
put.setCellVisibility(new CellVisibility(SECRET + " & " + CONFIDENTIAL));
table.put(put);
Get get = new Get(row1);
get.setAuthorizations(new Authorizations(SECRET));
Result result = table.get(get);
assertTrue(result.isEmpty());
Append append = new Append(row1);
append.addColumn(fam, qual, Bytes.toBytes("b"));
table.append(append);
result = table.get(get);
assertTrue(result.isEmpty());
append = new Append(row1);
append.addColumn(fam, qual, Bytes.toBytes("c"));
append.setCellVisibility(new CellVisibility(SECRET));
table.append(append);
result = table.get(get);
assertTrue(!result.isEmpty());
}
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class TestVisibilityWithCheckAuths method testLabelsWithAppend.
@Test
public void testLabelsWithAppend() throws Throwable {
PrivilegedExceptionAction<VisibilityLabelsResponse> action = new PrivilegedExceptionAction<VisibilityLabelsResponse>() {
@Override
public VisibilityLabelsResponse run() throws Exception {
try (Connection conn = ConnectionFactory.createConnection(conf)) {
return VisibilityClient.setAuths(conn, new String[] { TOPSECRET }, USER.getShortName());
} catch (Throwable e) {
}
return null;
}
};
SUPERUSER.runAs(action);
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
try (Table table = TEST_UTIL.createTable(tableName, fam)) {
final byte[] row1 = Bytes.toBytes("row1");
final byte[] val = Bytes.toBytes("a");
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Put put = new Put(row1);
put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, val);
put.setCellVisibility(new CellVisibility(TOPSECRET));
table.put(put);
}
return null;
}
};
USER.runAs(actiona);
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Append append = new Append(row1);
append.addColumn(fam, qual, Bytes.toBytes("b"));
table.append(append);
}
return null;
}
};
USER.runAs(actiona);
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Append append = new Append(row1);
append.addColumn(fam, qual, Bytes.toBytes("c"));
append.setCellVisibility(new CellVisibility(PUBLIC));
table.append(append);
Assert.fail("Testcase should fail with AccesDeniedException");
} catch (Throwable t) {
assertTrue(t.getMessage().contains("AccessDeniedException"));
}
return null;
}
};
USER.runAs(actiona);
}
}
use of org.apache.hadoop.hbase.client.Append in project hbase by apache.
the class ThriftHBaseServiceHandler method append.
@Override
public List<TCell> append(TAppend tappend) throws IOError, TException {
if (tappend.getRow().length == 0 || tappend.getTable().length == 0) {
throw new TException("Must supply a table and a row key; can't append");
}
Table table = null;
try {
table = getTable(tappend.getTable());
Append append = ThriftUtilities.appendFromThrift(tappend);
Result result = table.append(append);
return ThriftUtilities.cellFromHBase(result.rawCells());
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} finally {
closeTable(table);
}
}
Aggregations