use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.
the class TestAccessController method testWrite.
@Test
public // test put, delete, increment
void testWrite() throws Exception {
// put action
AccessTestAction putAction = new AccessTestAction() {
@Override
public Object run() throws Exception {
Put p = new Put(TEST_ROW);
p.addColumn(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(1));
try (Connection conn = ConnectionFactory.createConnection(conf);
Table t = conn.getTable(TEST_TABLE)) {
t.put(p);
}
return null;
}
};
verifyWrite(putAction);
// delete action
AccessTestAction deleteAction = new AccessTestAction() {
@Override
public Object run() throws Exception {
Delete d = new Delete(TEST_ROW);
d.addFamily(TEST_FAMILY);
try (Connection conn = ConnectionFactory.createConnection(conf);
Table t = conn.getTable(TEST_TABLE)) {
t.delete(d);
}
return null;
}
};
verifyWrite(deleteAction);
// increment action
AccessTestAction incrementAction = new AccessTestAction() {
@Override
public Object run() throws Exception {
Increment inc = new Increment(TEST_ROW);
inc.addColumn(TEST_FAMILY, TEST_QUALIFIER, 1);
try (Connection conn = ConnectionFactory.createConnection(conf);
Table t = conn.getTable(TEST_TABLE)) {
t.increment(inc);
}
return null;
}
};
verifyWrite(incrementAction);
}
use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.
the class TestSpaceQuotaBasicFunctioning method testNoInsertsWithIncrement.
@Test
public void testNoInsertsWithIncrement() throws Exception {
Increment i = new Increment(Bytes.toBytes("to_reject"));
i.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("count"), 0);
helper.writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_INSERTS, i);
}
use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.
the class TestSpaceQuotaBasicFunctioning method testNoWritesWithIncrement.
@Test
public void testNoWritesWithIncrement() throws Exception {
Increment i = new Increment(Bytes.toBytes("to_reject"));
i.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("count"), 0);
helper.writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_WRITES, i);
}
use of org.apache.hadoop.hbase.client.Increment in project metron by apache.
the class HBaseClient method addMutation.
/**
* Adds a Mutation such as a Put or Increment with a time to live. The Mutation is only queued
* for later execution.
*
* @param rowKey The row key of the Mutation.
* @param cols The columns affected by the Mutation.
* @param durability The durability of the mutation.
* @param timeToLiveMillis The time to live in milliseconds.
*/
public void addMutation(byte[] rowKey, ColumnList cols, Durability durability, Long timeToLiveMillis) {
if (cols.hasColumns()) {
Put put = createPut(rowKey, cols, durability, timeToLiveMillis);
mutations.add(put);
}
if (cols.hasCounters()) {
Increment inc = createIncrement(rowKey, cols, durability, timeToLiveMillis);
mutations.add(inc);
}
if (mutations.isEmpty()) {
Put put = new Put(rowKey);
put.setTTL(timeToLiveMillis);
mutations.add(put);
}
}
use of org.apache.hadoop.hbase.client.Increment in project metron by apache.
the class HBaseClient method createIncrement.
/**
* Creates an HBase Increment for a counter.
*
* @param rowKey The row key.
* @param cols The columns to include.
* @param durability The durability of the increment.
*/
private Increment createIncrement(byte[] rowKey, ColumnList cols, Durability durability, long timeToLiveMillis) {
Increment inc = new Increment(rowKey);
inc.setDurability(durability);
inc.setTTL(timeToLiveMillis);
cols.getCounters().forEach(cnt -> inc.addColumn(cnt.getFamily(), cnt.getQualifier(), cnt.getIncrement()));
return inc;
}
Aggregations