@Override void onStartup() throws IOException { this.table = connection.getTable(TableName.valueOf(opts.tableName)); }
@Override void onStartup() throws IOException { this.asyncTable = connection.getTable(TableName.valueOf(opts.tableName), Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); }
private void put(ChannelHandlerContext ctx, FullHttpRequest req) { Params params = parse(req); byte[] value = new byte[req.content().readableBytes()]; req.content().readBytes(value); conn.getTable(TableName.valueOf(params.table)).put(new Put(Bytes.toBytes(params.row)) .addColumn(Bytes.toBytes(params.family), Bytes.toBytes(params.qualifier), value)) .whenComplete((r, e) -> { if (e != null) { exceptionCaught(ctx, e); } else { write(ctx, HttpResponseStatus.OK, Optional.empty()); } }); }
private static AsyncTable<?> getTable() { return ASYNC_CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()); }
static TableState.State getStateFromMeta(TableName table) throws Exception { Optional<TableState> state = AsyncMetaTableAccessor .getTableState(ASYNC_CONN.getTable(TableName.META_TABLE_NAME), table).get(); assertTrue(state.isPresent()); return state.get().getState(); }
@Override protected ResultScanner getScanner(Scan scan) throws Exception { return CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()).getScanner(scan); } }
@BeforeClass public static void setUp() throws Exception { UTIL.startMiniCluster(1); UTIL.createTable(TABLE_NAME, FAMILY); CONN = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get(); TABLE = CONN.getTable(TABLE_NAME); TABLE.putAll(IntStream.range(0, ROW_COUNT).mapToObj(i -> { Put put = new Put(Bytes.toBytes(i)); IntStream.range(0, CQS.length) .forEach(j -> put.addColumn(FAMILY, CQS[j], Bytes.toBytes((j + 1) * i))); return put; }).collect(Collectors.toList())).get(); }
@BeforeClass public static void setUp() throws Exception { TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, SCANNER_LEASE_TIMEOUT_PERIOD_MS); TEST_UTIL.startMiniCluster(1); TEST_UTIL.createTable(TABLE_NAME, FAMILY); CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); TABLE = CONN.getTable(TABLE_NAME); TABLE.putAll(IntStream.range(0, 10).mapToObj( i -> new Put(Bytes.toBytes(String.format("%02d", i))).addColumn(FAMILY, CQ, Bytes.toBytes(i))) .collect(Collectors.toList())).get(); }
@BeforeClass public static void setUp() throws Exception { TEST_UTIL.startMiniCluster(1); TEST_UTIL.createTable(TABLE_NAME, FAMILY); CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); TABLE = CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()); TABLE.putAll(IntStream.range(0, 100).mapToObj( i -> new Put(Bytes.toBytes(String.format("%02d", i))).addColumn(FAMILY, CQ, Bytes.toBytes(i))) .collect(Collectors.toList())).get(); }
private void createAndLoadTable(TableName[] tables) { for (TableName table : tables) { TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(table); builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)); admin.createTable(builder.build(), Bytes.toBytes("aaaaa"), Bytes.toBytes("zzzzz"), 16).join(); AsyncTable<?> asyncTable = ASYNC_CONN.getTable(table); List<Put> puts = new ArrayList<>(); for (byte[] row : HBaseTestingUtility.ROWS) { puts.add(new Put(row).addColumn(FAMILY, Bytes.toBytes("q"), Bytes.toBytes("v"))); } asyncTable.putAll(puts).join(); } } }
@Test public void testIncrement() throws InterruptedException, ExecutionException { AsyncTable<?> table = ASYNC_CONN.getTable(TABLE_NAME); assertEquals(1L, table.incrementColumnValue(row, FAMILY, QUALIFIER, 1L).get().longValue()); // the second call should have no effect as we always generate the same nonce. assertEquals(1L, table.incrementColumnValue(row, FAMILY, QUALIFIER, 1L).get().longValue()); Result result = table.get(new Get(row)).get(); assertEquals(1L, Bytes.toLong(result.getValue(FAMILY, QUALIFIER))); } }
@Test public void testPeriodicFlush() throws InterruptedException, ExecutionException { AsyncBufferedMutator mutator = CONN.getBufferedMutatorBuilder(TABLE_NAME) .setWriteBufferPeriodicFlush(1, TimeUnit.SECONDS).build(); Put put = new Put(Bytes.toBytes(0)).addColumn(CF, CQ, VALUE); CompletableFuture<?> future = mutator.mutate(put); future.get(); AsyncTable<?> table = CONN.getTable(TABLE_NAME); assertArrayEquals(VALUE, table.get(new Get(Bytes.toBytes(0))).get().getValue(CF, CQ)); }
private static Pair<List<Result>, ScanMetrics> doScanWithRawAsyncTable(Scan scan) throws IOException, InterruptedException { BufferingScanResultConsumer consumer = new BufferingScanResultConsumer(); CONN.getTable(TABLE_NAME).scan(scan, consumer); List<Result> results = new ArrayList<>(); for (Result result; (result = consumer.take()) != null;) { results.add(result); } return Pair.newPair(results, consumer.getScanMetrics()); }
@BeforeClass public static void setUpBeforeClass() throws Exception { startClusterAndCreateTable(); AsyncTable<?> table = ASYNC_CONN.getTable(TABLE_NAME); table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE)).get(); waitUntilAllReplicasHaveRow(ROW); }
private static Pair<List<Result>, ScanMetrics> doScanWithAsyncTableScanner(Scan scan) throws IOException { try (ResultScanner scanner = CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()).getScanner(scan)) { List<Result> results = new ArrayList<>(); for (Result result; (result = scanner.next()) != null;) { results.add(result); } return Pair.newPair(results, scanner.getScanMetrics()); } }
@Test public void testAppend() throws InterruptedException, ExecutionException { AsyncTable<?> table = ASYNC_CONN.getTable(TABLE_NAME); Result result = table.append(new Append(row).addColumn(FAMILY, QUALIFIER, VALUE)).get(); assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER)); result = table.append(new Append(row).addColumn(FAMILY, QUALIFIER, VALUE)).get(); // the second call should have no effect as we always generate the same nonce. assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER)); result = table.get(new Get(row)).get(); assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER)); }
@Override protected List<Result> doScan(Scan scan) throws Exception { BufferingScanResultConsumer scanConsumer = new BufferingScanResultConsumer(); ASYNC_CONN.getTable(TABLE_NAME).scan(scan, scanConsumer); List<Result> results = new ArrayList<>(); for (Result result; (result = scanConsumer.take()) != null;) { results.add(result); } if (scan.getBatch() > 0) { results = convertFromBatchResult(results); } return results; } }
@BeforeClass public static void setUpBeforeClass() throws Exception { startClusterAndCreateTable(); AsyncTable<?> table = ASYNC_CONN.getTable(TABLE_NAME); for (int i = 0; i < ROW_COUNT; i++) { table.put(new Put(getRow(i)).addColumn(FAMILY, QUALIFIER, getValue(i))).get(); } waitUntilAllReplicasHaveRow(getRow(ROW_COUNT - 1)); }
private static Pair<List<Result>, ScanMetrics> doScanWithAsyncTableScan(Scan scan) throws Exception { SimpleScanResultConsumer consumer = new SimpleScanResultConsumer(); CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()).scan(scan, consumer); return Pair.newPair(consumer.getAll(), consumer.getScanMetrics()); }
@Override protected List<Result> doScan(Scan scan) throws Exception { AsyncTable<ScanResultConsumer> table = ASYNC_CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()); SimpleScanResultConsumer consumer = new SimpleScanResultConsumer(); table.scan(scan, consumer); List<Result> results = consumer.getAll(); if (scan.getBatch() > 0) { results = convertFromBatchResult(results); } return results; }