private void testAppend(Increment inc) throws Exception { checkResult(table.increment(inc)); List<Row> actions = Arrays.asList(inc, inc); Object[] results = new Object[actions.size()]; table.batch(actions, results); checkResult(results); }
@Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf)) { try (Table t = connection.getTable(TEST_TABLE.getTableName())) { Increment inc = new Increment(TEST_ROW1); inc.setTimeRange(0, 123); inc.addColumn(TEST_FAMILY1, TEST_Q1, 2L); t.increment(inc); t.incrementColumnValue(TEST_ROW1, TEST_FAMILY1, TEST_Q2, 1L); } } return null; } });
@Test(expected = InvalidMutationDurabilityException.class) public void testIncrementToTableNeedReplicate() throws Exception { tableNeedReplicate.increment(newIncrementWithSkipWAL()); }
@Override protected void execute(Table table) throws IOException { table.increment(new Increment(FAM_NAM).addColumn(FAM_NAM, FAM_NAM, 1)); } }
@Test public void testIncrementToTableNotReplicate() throws Exception { tableNotReplicate.increment(newIncrementWithSkipWAL()); }
private static void increment(int sleepSteps) throws IOException { for (long i = 1; i <= UPPER; i++) { TABLE.increment(new Increment(ROW).addColumn(FAMILY, CQ1, i).addColumn(FAMILY, CQ2, 2 * i)); if (sleepSteps > 0 && i % sleepSteps == 0) { try { Thread.sleep(10); } catch (InterruptedException e) { } } } }
@Override public TResult increment(ByteBuffer table, TIncrement increment) throws TIOError, TException { checkReadOnlyMode(); Table htable = getTable(table); try { return resultFromHBase(htable.increment(incrementFromThrift(increment))); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Test(expected = DoNotRetryIOException.class) public void testIncrementWithDoNotRetryIOException() throws Exception { tableDoNotRetry.increment(new Increment(Bytes.toBytes("row")).addColumn(CF, CQ, 1)); }
@Test(expected = RetriesExhaustedException.class) public void testIncrementWithIOException() throws Exception { tableRetry.increment(new Increment(Bytes.toBytes("row")).addColumn(CF, CQ, 1)); }
/** * See {@link #incrementColumnValue(byte[], byte[], byte[], long, Durability)} * <p> * The {@link Durability} is defaulted to {@link Durability#SYNC_WAL}. * @param row The row that contains the cell to increment. * @param family The column family of the cell to increment. * @param qualifier The column qualifier of the cell to increment. * @param amount The amount to increment the cell with (or decrement, if the * amount is negative). * @return The new value, post increment. * @throws IOException if a remote or network exception occurs. */ default long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount) throws IOException { Increment increment = new Increment(row).addColumn(family, qualifier, amount); Cell cell = increment(increment).getColumnLatestCell(family, qualifier); return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); }
@Override boolean testRow(final int i) throws IOException { Increment increment = new Increment(format(i)); // unlike checkAndXXX tests, which make most sense to do on a single value, // if multiple families are specified for an increment test we assume it is // meant to raise the work factor for (int family = 0; family < opts.families; family++) { byte[] familyName = Bytes.toBytes(FAMILY_NAME_BASE + family); increment.addColumn(familyName, getQualifier(), 1l); } updateValueSize(this.table.increment(increment)); return true; } }
@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; } };
@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); }
@Test public void testIncrement() throws IOException { try (Table t = TEST_UTIL.getConnection().getTable(TABLE_NAME)) { Put put = new Put(ROW); put.addColumn(FAMILY, QUAL, VALUE); t.put(put); assertRowAndValue(t.get(new Get(ROW)), ROW, VALUE); Increment inc = new Increment(ROW); inc.addColumn(FAMILY, QUAL, 99); assertRowAndValue(t.increment(inc), ROW, FIXED_VALUE); assertRowAndValue(t.get(new Get(ROW)), ROW, Bytes.toBytes(199L)); } }
@Override public Object run() throws Exception { Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, 1L); try(Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(TEST_TABLE.getTableName())) { t.increment(i); } return null; } };
@Override public Object run() throws Exception { Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2, 1L); try(Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(TEST_TABLE.getTableName())) { t.increment(i); } return null; } };
@Override public Object run() throws Exception { Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q3, 1L); try(Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(TEST_TABLE.getTableName())) { t.increment(i); } return null; } };
@Override public Object run() throws Exception { Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2, 1L); // Tag this increment with an ACL that denies write permissions to USER_OTHER and GROUP i.setACL(prepareCellPermissions(usersAndGroups, Action.READ)); try(Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(TEST_TABLE.getTableName())) { t.increment(i); } return null; } };
@Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf)) { try (Table t = connection.getTable(TEST_TABLE.getTableName())) { Increment inc = new Increment(row); inc.setTimeRange(0, 127); inc.addColumn(TEST_FAMILY1, q1, 2L); t.increment(inc); fail(user.getShortName() + " cannot do the increment."); } catch (Exception e) { } } return null; } });
@Test public void testIncrementWithCustomTimestamp() throws IOException { TableName TABLENAME = TableName.valueOf(name.getMethodName()); Table table = TEST_UTIL.createTable(TABLENAME, FAMILY); long timestamp = 999; Increment increment = new Increment(ROW); increment.add(CellUtil.createCell(ROW, FAMILY, QUALIFIER, timestamp, KeyValue.Type.Put.getCode(), Bytes.toBytes(100L))); Result r = table.increment(increment); assertEquals(1, r.size()); assertEquals(timestamp, r.rawCells()[0].getTimestamp()); r = table.get(new Get(ROW)); assertEquals(1, r.size()); assertEquals(timestamp, r.rawCells()[0].getTimestamp()); r = table.increment(increment); assertEquals(1, r.size()); assertNotEquals(timestamp, r.rawCells()[0].getTimestamp()); r = table.get(new Get(ROW)); assertEquals(1, r.size()); assertNotEquals(timestamp, r.rawCells()[0].getTimestamp()); }