@Test(expected = DoNotRetryIOException.class) public void testAppendWithDoNotRetryIOException() throws Exception { tableDoNotRetry .append(new Append(Bytes.toBytes("row")).addColumn(CF, CQ, Bytes.toBytes("value"))); }
private void testAppend(Append append) throws Exception { checkResult(table.append(append)); List<Row> actions = Arrays.asList(append, append); Object[] results = new Object[actions.size()]; table.batch(actions, results); checkResult(results); }
@Test(expected = InvalidMutationDurabilityException.class) public void testAppendToTableNeedReplicate() throws Exception { tableNeedReplicate.append(newAppendWithSkipWAL()); }
@Test public void testAppendToTableNotReplicate() throws Exception { tableNotReplicate.append(newAppendWithSkipWAL()); }
@Test(expected = RetriesExhaustedException.class) public void testAppendWithIOException() throws Exception { tableRetry.append(new Append(Bytes.toBytes("row")).addColumn(CF, CQ, Bytes.toBytes("value"))); }
@Override public TResult append(ByteBuffer table, TAppend append) throws TIOError, TException { checkReadOnlyMode(); Table htable = getTable(table); try { return resultFromHBase(htable.append(appendFromThrift(append))); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@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); } }
@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; } };
@Override public Object run() throws Exception { byte[] row = TEST_ROW; byte[] qualifier = TEST_QUALIFIER; Put put = new Put(row); put.addColumn(TEST_FAMILY, qualifier, Bytes.toBytes(1)); Append append = new Append(row); append.addColumn(TEST_FAMILY, qualifier, Bytes.toBytes(2)); try(Connection conn = ConnectionFactory.createConnection(conf); Table t = conn.getTable(TEST_TABLE)) { t.put(put); t.append(append); } return null; } };
@Override boolean testRow(final int i) throws IOException { byte [] bytes = format(i); Append append = new Append(bytes); // unlike checkAndXXX tests, which make most sense to do on a single value, // if multiple families are specified for an append 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); append.addColumn(familyName, getQualifier(), bytes); } updateValueSize(this.table.append(append)); return true; } }
@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; } };
@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); }
@Override public Object run() throws Exception { try { if (table == null) { table = connection.getTable(tableName); } if (m instanceof Increment) { table.increment((Increment) m); } else if (m instanceof Append) { table.append((Append) m); } else if (m instanceof Put) { table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenPut((Put) m); } else if (m instanceof Delete) { table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenDelete((Delete) m); } else { throw new IllegalArgumentException("unsupported mutation " + m.getClass().getSimpleName()); } totalOpTimeMs.addAndGet(System.currentTimeMillis() - start); } catch (IOException e) { recordFailure(m, keyBase, start, e); } return null; } }
@Test public void testAppend() 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); Append append = new Append(ROW); append.addColumn(FAMILY, QUAL, FIXED_VALUE); assertRowAndValue(t.append(append), ROW, FIXED_VALUE); assertRowAndValue(t.get(new Get(ROW)), ROW, Bytes.add(VALUE, FIXED_VALUE)); } }
@Test public void testAppend() throws Exception { LOG.info("Starting testAppend"); final TableName tableName = TableName.valueOf(name.getMethodName()); Table t = TEST_UTIL.createTable(tableName, FAMILY); byte[] v1 = Bytes.toBytes("42"); byte[] v2 = Bytes.toBytes("23"); byte [][] QUALIFIERS = new byte [][] { Bytes.toBytes("b"), Bytes.toBytes("a"), Bytes.toBytes("c") }; Append a = new Append(ROW); a.addColumn(FAMILY, QUALIFIERS[0], v1); a.addColumn(FAMILY, QUALIFIERS[1], v2); a.setReturnResults(false); assertEmptyResult(t.append(a)); a = new Append(ROW); a.addColumn(FAMILY, QUALIFIERS[0], v2); a.addColumn(FAMILY, QUALIFIERS[1], v1); a.addColumn(FAMILY, QUALIFIERS[2], v2); Result r = t.append(a); assertEquals(0, Bytes.compareTo(Bytes.add(v1, v2), r.getValue(FAMILY, QUALIFIERS[0]))); assertEquals(0, Bytes.compareTo(Bytes.add(v2, v1), r.getValue(FAMILY, QUALIFIERS[1]))); // QUALIFIERS[2] previously not exist, verify both value and timestamp are correct assertEquals(0, Bytes.compareTo(v2, r.getValue(FAMILY, QUALIFIERS[2]))); assertEquals(r.getColumnLatestCell(FAMILY, QUALIFIERS[0]).getTimestamp(), r.getColumnLatestCell(FAMILY, QUALIFIERS[2]).getTimestamp()); } private List<Result> doAppend(final boolean walUsed) throws IOException {
@Test public void testAppendHook() throws IOException { final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName()); Table table = util.createTable(tableName, new byte[][] { A, B, C }); try { Append app = new Append(Bytes.toBytes(0)); app.addColumn(A, A, A); verifyMethodResult(SimpleRegionObserver.class, new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock" }, tableName, new Boolean[] { false, false, false }); table.append(app); verifyMethodResult(SimpleRegionObserver.class, new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock" }, tableName, new Boolean[] { true, true, true }); } finally { util.deleteTable(tableName); table.close(); } }
@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()); } }
@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))); } }
@Test public void testChangeCellWithNotExistColumnFamily() throws Exception { TableName tableName = TableName.valueOf(name.getMethodName()); createTableWithCoprocessor(tableName, ChangeCellWithNotExistColumnFamilyObserver.class.getName()); try (Table table = connection.getTable(tableName)) { try { Increment increment = new Increment(ROW).addColumn(CF1_BYTES, CQ1, 1); table.increment(increment); fail("should throw NoSuchColumnFamilyException"); } catch (Exception e) { assertTrue(e instanceof NoSuchColumnFamilyException); } try { Append append = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE); table.append(append); fail("should throw NoSuchColumnFamilyException"); } catch (Exception e) { assertTrue(e instanceof NoSuchColumnFamilyException); } } }
@Test public void testAppendWithCustomTimestamp() throws IOException { TableName TABLENAME = TableName.valueOf(name.getMethodName()); Table table = TEST_UTIL.createTable(TABLENAME, FAMILY); long timestamp = 999; Append append = new Append(ROW); append.add(CellUtil.createCell(ROW, FAMILY, QUALIFIER, timestamp, KeyValue.Type.Put.getCode(), Bytes.toBytes(100L))); Result r = table.append(append); 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.append(append); 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()); } }