@Override public ResultScanner getScanner(Scan filter) throws IOException { return table.getScanner(filter); }
@Override public Object run() throws Exception { try(Connection conn = ConnectionFactory.createConnection(conf); Table t = conn.getTable(TEST_TABLE)) { return t.get(new Get(TEST_ROW)); } } };
/** * Invokes Table#delete to delete test data (i.e. the row) * * @param table Standard Table object * @throws IOException If IO problem is encountered */ static void deleteRow(final Table table) throws IOException { System.out.println("Deleting row [" + Bytes.toString(MY_ROW_ID) + "] from Table [" + table.getName().getNameAsString() + "]."); table.delete(new Delete(MY_ROW_ID)); }
/** * Test read only tables * @throws Exception */ @Test public void testReadOnlyTable() throws Exception { final TableName name = TableName.valueOf(this.name.getMethodName()); Table table = TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); byte[] value = Bytes.toBytes("somedata"); // This used to use an empty row... That must have been a bug Put put = new Put(value); put.addColumn(HConstants.CATALOG_FAMILY, HConstants.CATALOG_FAMILY, value); table.put(put); table.close(); }
private static final void createTable(HTableDescriptor desc) throws Exception { Admin admin = TEST_UTIL.getAdmin(); admin.createTable(desc, new byte[][]{ROWS[rowSeperator1], ROWS[rowSeperator2]}); TEST_UTIL.waitUntilAllRegionsAssigned(desc.getTableName()); Table table = TEST_UTIL.getConnection().getTable(desc.getTableName()); try { for (int i = 0; i < ROWSIZE; i++) { Put put = new Put(ROWS[i]); put.addColumn(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(i)); table.put(put); } } finally { table.close(); } }
@Test public void testFlush() throws IOException { byte[] row = Bytes.toBytes("row"); byte[] cf = Bytes.toBytes("cf"); byte[] cq = Bytes.toBytes("cq"); byte[] value = Bytes.toBytes("value"); TableName name = TableName.valueOf(getClass().getSimpleName()); Table t = util.createTable(name, cf); t.put(new Put(row).addColumn(cf, cq, value)); util.getAdmin().flush(name); assertArrayEquals(value, t.get(new Get(row)).getValue(cf, cq)); } }
@Test public void testBatchWithRowMutation() throws Exception { LOG.info("Starting testBatchWithRowMutation"); final TableName TABLENAME = TableName.valueOf("testBatchWithRowMutation"); try (Table t = TEST_UTIL.createTable(TABLENAME, FAMILY)) { byte [][] QUALIFIERS = new byte [][] { Bytes.toBytes("a"), Bytes.toBytes("b") }; new Put(ROW).addColumn(FAMILY, QUALIFIERS[0], VALUE))); Object[] batchResult = new Object[1]; t.batch(Arrays.asList(arm), batchResult); Result r = t.get(g); assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIERS[0]))); new Put(ROW).addColumn(FAMILY, QUALIFIERS[1], VALUE), new Delete(ROW).addColumns(FAMILY, QUALIFIERS[0]))); t.batch(Arrays.asList(arm), batchResult); r = t.get(g); assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIERS[1]))); assertNull(r.getValue(FAMILY, QUALIFIERS[0])); arm = RowMutations.of(Collections.singletonList( new Put(ROW).addColumn(new byte[]{'b', 'o', 'g', 'u', 's'}, QUALIFIERS[0], VALUE))); t.batch(Arrays.asList(arm), batchResult); fail("Expected RetriesExhaustedWithDetailsException with NoSuchColumnFamilyException"); } catch(RetriesExhaustedWithDetailsException e) {
@Test public void testHTableExistsBeforeGet() throws Exception { Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), new byte[][] { FAMILY }); try { Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, VALUE); table.put(put); Get get = new Get(ROW); boolean exist = table.exists(get); assertEquals(true, exist); Result result = table.get(get); assertEquals(false, result.isEmpty()); assertTrue(Bytes.equals(VALUE, result.getValue(FAMILY, QUALIFIER))); } finally { table.close(); } }
@Test(expected=RetriesExhaustedException.class) public void testSocketClosed() throws IOException, InterruptedException { TableName tableName = TableName.valueOf(name.getMethodName()); UTIL.createTable(tableName, fam1).close(); Configuration conf = new Configuration(UTIL.getConfiguration()); conf.set(RpcClientFactory.CUSTOM_RPC_CLIENT_IMPL_CONF_KEY, MyRpcClientImpl.class.getName()); conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(TableName.valueOf(name.getMethodName())); table.get(new Get(Bytes.toBytes("asd"))); connection.close(); for (Socket socket : MyRpcClientImpl.savedSockets) { assertTrue("Socket + " + socket + " is not closed", socket.isClosed()); } } }
@Test public void testBatchWithIncrementAndAppend() throws Exception { LOG.info("test=testBatchWithIncrementAndAppend"); final byte[] QUAL1 = Bytes.toBytes("qual1"); final byte[] QUAL2 = Bytes.toBytes("qual2"); final byte[] QUAL3 = Bytes.toBytes("qual3"); final byte[] QUAL4 = Bytes.toBytes("qual4"); Table table = UTIL.getConnection().getTable(TEST_TABLE); Delete d = new Delete(ONE_ROW); table.delete(d); Put put = new Put(ONE_ROW); put.addColumn(BYTES_FAMILY, QUAL1, Bytes.toBytes("abc")); put.addColumn(BYTES_FAMILY, QUAL2, Bytes.toBytes(1L)); table.put(put); table.batch(actions, multiRes); validateResult(multiRes[1], QUAL1, Bytes.toBytes("abcdef")); validateResult(multiRes[1], QUAL4, Bytes.toBytes("xyz")); validateResult(multiRes[0], QUAL2, Bytes.toBytes(2L)); validateResult(multiRes[0], QUAL3, Bytes.toBytes(1L)); table.close();
/** * For HADOOP-2579 * @throws IOException */ @Test (expected=TableNotFoundException.class) public void testTableNotFoundExceptionWithoutAnyTables() throws IOException { TableName tableName = TableName .valueOf("testTableNotFoundExceptionWithoutAnyTables"); Table ht = TEST_UTIL.getConnection().getTable(tableName); ht.get(new Get(Bytes.toBytes("e"))); }
@Test public void testDisabledWAL() throws Exception { LOG.info("Writing data to table " + tableName); Put p = new Put(Bytes.toBytes("row")); p.addColumn(fam, Bytes.toBytes("qual"), Bytes.toBytes("val")); table.put(p); LOG.info("Flushing table " + tableName); TEST_UTIL.flush(tableName); LOG.info("Getting data from table " + tableName); Get get = new Get(Bytes.toBytes("row")); Result result = table.get(get); assertNotNull(result.getValue(fam, Bytes.toBytes("qual"))); } }
@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)); } }
@Test public void testBatchAppendWithReturnResultFalse() throws Exception { LOG.info("Starting testBatchAppendWithReturnResultFalse"); final TableName tableName = TableName.valueOf(name.getMethodName()); Table table = TEST_UTIL.createTable(tableName, FAMILY); Append append1 = new Append(Bytes.toBytes("row1")); append1.setReturnResults(false); append1.addColumn(FAMILY, Bytes.toBytes("f1"), Bytes.toBytes("value1")); Append append2 = new Append(Bytes.toBytes("row1")); append2.setReturnResults(false); append2.addColumn(FAMILY, Bytes.toBytes("f1"), Bytes.toBytes("value2")); List<Append> appends = new ArrayList<>(); appends.add(append1); appends.add(append2); Object[] results = new Object[2]; table.batch(appends, results); assertTrue(results.length == 2); for(Object r : results) { Result result = (Result)r; assertTrue(result.isEmpty()); } table.close(); }
public int testGet(final RegionInfo hri, final int nrows) throws IOException { int nresults = 0; final Table table = UTIL.getConnection().getTable(hri.getTable()); for (int i = 0; i < nrows; ++i) { final byte[] row = Bytes.add(hri.getStartKey(), Bytes.toBytes(i)); final Result result = table.get(new Get(row)); if (result != null && !result.isEmpty() && Bytes.equals(row, result.getValue(FAMILY, null))) { nresults++; } } return nresults; } }
@Test public void testHTableWithLargeBatch() throws Exception { Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), new byte[][] { FAMILY }); int sixtyFourK = 64 * 1024; try { List actions = new ArrayList(); Object[] results = new Object[(sixtyFourK + 1) * 2]; for (int i = 0; i < sixtyFourK + 1; i ++) { Put put1 = new Put(ROW); put1.addColumn(FAMILY, QUALIFIER, VALUE); actions.add(put1); Put put2 = new Put(ANOTHERROW); put2.addColumn(FAMILY, QUALIFIER, VALUE); actions.add(put2); } table.batch(actions, results); } finally { table.close(); } }