public static void tearDownAfterClass() throws Exception { if (CONN != null) { CONN.close(); } AbstractTestScanCursor.tearDownAfterClass(); }
@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 AsyncAdmin getRawAsyncAdmin() { return ASYNC_CONN.getAdmin(); }
@Override void onStartup() throws IOException { this.table = connection.getTable(TableName.valueOf(opts.tableName)); }
@Test public void testAsyncTable() throws Exception { TableName tn = TableName.valueOf(name.getMethodName()); ColumnFamilyDescriptorBuilder cfDescBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family); TableDescriptorBuilder tableDescBuilder = TableDescriptorBuilder.newBuilder(tn).setColumnFamily(cfDescBuilder.build()); try (AsyncConnection ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get()) { ASYNC_CONN.getAdmin().createTable(tableDescBuilder.build()).get(); AsyncTable<?> table = ASYNC_CONN.getTable(tn); // put some data Put put = new Put(row); put.addColumn(family, qualifier, value); table.put(put).get(); // get and verify Get get = new Get(row); Result result = table.get(get).get(); LOG.debug("Result: " + Bytes.toString(result.getValue(family, qualifier))); Assert.assertArrayEquals(value, result.getValue(family, qualifier)); } } }
/** * Retrieve an {@link AsyncTable} implementation for accessing a table. * <p> * This method no longer checks table existence. An exception will be thrown if the table does not * exist only when the first operation is attempted. * @param tableName the name of the table * @param pool the thread pool to use for executing callback * @return an AsyncTable to use for interactions with this table */ default AsyncTable<ScanResultConsumer> getTable(TableName tableName, ExecutorService pool) { return getTableBuilder(tableName, pool).build(); }
/** * Retrieve an {@link AsyncAdmin} implementation to administer an HBase cluster. * <p> * The returned instance will use default configs. Use {@link #getAdminBuilder(ExecutorService)} * if you want to customize some configs. * @param pool the thread pool to use for executing callback * @return an {@link AsyncAdmin} instance for cluster administration */ default AsyncAdmin getAdmin(ExecutorService pool) { return getAdminBuilder(pool).build(); }
/** * Retrieve an {@link AsyncBufferedMutator} for performing client-side buffering of writes. * <p> * The returned instance will use default configs. Use * {@link #getBufferedMutatorBuilder(TableName)} if you want to customize some configs. * @param tableName the name of the table * @return an {@link AsyncBufferedMutator} for the supplied tableName. */ default AsyncBufferedMutator getBufferedMutator(TableName tableName) { return getBufferedMutatorBuilder(tableName).build(); }
@Test public void testGetRegionLocation() throws Exception { RawAsyncHBaseAdmin rawAdmin = (RawAsyncHBaseAdmin) ASYNC_CONN.getAdmin(); TEST_UTIL.createMultiRegionTable(tableName, HConstants.CATALOG_FAMILY); AsyncTableRegionLocator locator = ASYNC_CONN.getRegionLocator(tableName); HRegionLocation regionLocation = locator.getRegionLocation(Bytes.toBytes("mmm")).get(); RegionInfo region = regionLocation.getRegion(); byte[] regionName = regionLocation.getRegion().getRegionName(); HRegionLocation location = rawAdmin.getRegionLocation(regionName).get(); assertTrue(Bytes.equals(regionName, location.getRegion().getRegionName())); location = rawAdmin.getRegionLocation(region.getEncodedNameAsBytes()).get(); assertTrue(Bytes.equals(regionName, location.getRegion().getRegionName())); }
AsyncTest(final AsyncConnection con, final TestOptions options, final Status status) { super(con == null ? HBaseConfiguration.create() : con.getConfiguration(), options, status); this.connection = con; } }
@Override void onStartup() throws IOException { this.asyncTable = connection.getTable(TableName.valueOf(opts.tableName), Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); }
/** * Retrieve an {@link AsyncTable} implementation for accessing a table. * <p> * The returned instance will use default configs. Use {@link #getTableBuilder(TableName)} if * you want to customize some configs. * <p> * This method no longer checks table existence. An exception will be thrown if the table does not * exist only when the first operation is attempted. * <p> * The returned {@code CompletableFuture} will be finished directly in the rpc framework's * callback thread, so typically you should not do any time consuming work inside these methods. * And also the observer style scan API will use {@link AdvancedScanResultConsumer} which is * designed for experts only. Only use it when you know what you are doing. * @param tableName the name of the table * @return an AsyncTable to use for interactions with this table * @see #getTableBuilder(TableName) */ default AsyncTable<AdvancedScanResultConsumer> getTable(TableName tableName) { return getTableBuilder(tableName).build(); }
private static AsyncAdminBuilder getRawAsyncAdminBuilder() { return ASYNC_CONN.getAdminBuilder(); }
/** * Retrieve an {@link AsyncBufferedMutator} for performing client-side buffering of writes. * <p> * The returned instance will use default configs. Use * {@link #getBufferedMutatorBuilder(TableName, ExecutorService)} if you want to customize some * configs. * @param tableName the name of the table * @param pool the thread pool to use for executing callback * @return an {@link AsyncBufferedMutator} for the supplied tableName. */ default AsyncBufferedMutator getBufferedMutator(TableName tableName, ExecutorService pool) { return getBufferedMutatorBuilder(tableName, pool).build(); }
AsyncTest(final AsyncConnection con, final TestOptions options, final Status status) { super(con == null ? HBaseConfiguration.create() : con.getConfiguration(), options, status); this.connection = con; } }
private void test(TableName tableName) throws InterruptedException { List<CompletableFuture<Void>> futures = new ArrayList<>(); try (AsyncBufferedMutator mutator = CONN.getBufferedMutatorBuilder(tableName).setWriteBufferSize(16 * 1024).build()) { List<CompletableFuture<Void>> fs = mutator.mutate(IntStream.range(0, COUNT / 2) .mapToObj(i -> new Put(Bytes.toBytes(i)).addColumn(CF, CQ, VALUE)) .collect(Collectors.toList())); // exceeded the write buffer size, a flush will be called directly fs.forEach(f -> f.join()); IntStream.range(COUNT / 2, COUNT).forEach(i -> { futures.add(mutator.mutate(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, VALUE))); }); // the first future should have been sent out. futures.get(0).join(); Thread.sleep(2000); // the last one should still be in write buffer assertFalse(futures.get(futures.size() - 1).isDone()); } // mutator.close will call mutator.flush automatically so all tasks should have been done. futures.forEach(f -> f.join()); AsyncTable<?> table = CONN.getTable(tableName); IntStream.range(0, COUNT).mapToObj(i -> new Get(Bytes.toBytes(i))).map(g -> table.get(g).join()) .forEach(r -> { assertArrayEquals(VALUE, r.getValue(CF, CQ)); }); }
public static void tearDownAfterClass() throws Exception { if (CONN != null) { CONN.close(); } AbstractTestScanCursor.tearDownAfterClass(); }
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 AsyncAdmin getAsyncAdmin() { return ASYNC_CONN.getAdmin(ForkJoinPool.commonPool()); }
protected static void setUp(MemoryCompactionPolicy memoryCompaction) throws Exception { TEST_UTIL.getConfiguration().set(TABLES_ON_MASTER, "none"); TEST_UTIL.getConfiguration().setLong(HBASE_CLIENT_META_OPERATION_TIMEOUT, 60000L); TEST_UTIL.getConfiguration().setInt(ByteBufferPool.MAX_POOL_SIZE_KEY, 100); TEST_UTIL.getConfiguration().set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, String.valueOf(memoryCompaction)); TEST_UTIL.startMiniCluster(5); SPLIT_KEYS = new byte[8][]; for (int i = 111; i < 999; i += 111) { SPLIT_KEYS[i / 111 - 1] = Bytes.toBytes(String.format("%03d", i)); } TEST_UTIL.createTable(TABLE_NAME, FAMILY); TEST_UTIL.waitTableAvailable(TABLE_NAME); CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); TABLE = CONN.getTableBuilder(TABLE_NAME).setReadRpcTimeout(1, TimeUnit.SECONDS) .setMaxRetries(1000).build(); TABLE.putAll( IntStream.range(0, COUNT).mapToObj(i -> new Put(Bytes.toBytes(String.format("%03d", i))) .addColumn(FAMILY, QUALIFIER, Bytes.toBytes(i))).collect(Collectors.toList())) .get(); }