use of org.apache.hbase.thirdparty.io.netty.util.Timeout in project hbase by apache.
the class TestAsyncBufferMutator method testCancelPeriodicFlushByClose.
@Test
public void testCancelPeriodicFlushByClose() throws InterruptedException, ExecutionException {
CompletableFuture<?> future;
Timeout task;
try (AsyncBufferedMutatorImpl mutator = (AsyncBufferedMutatorImpl) CONN.getBufferedMutatorBuilder(TABLE_NAME).setWriteBufferPeriodicFlush(1, TimeUnit.SECONDS).build()) {
future = mutator.mutate(new Put(Bytes.toBytes(0)).addColumn(CF, CQ, VALUE));
task = mutator.periodicFlushTask;
// we should have scheduled a periodic flush task
assertNotNull(task);
}
assertTrue(task.isCancelled());
future.get();
AsyncTable<?> table = CONN.getTable(TABLE_NAME);
assertArrayEquals(VALUE, table.get(new Get(Bytes.toBytes(0))).get().getValue(CF, CQ));
}
use of org.apache.hbase.thirdparty.io.netty.util.Timeout in project hbase by apache.
the class TestAsyncBufferMutator method testCancelPeriodicFlush.
// a bit deep into the implementation
@Test
public void testCancelPeriodicFlush() throws InterruptedException, ExecutionException {
Put put = new Put(Bytes.toBytes(0)).addColumn(CF, CQ, VALUE);
try (AsyncBufferedMutatorImpl mutator = (AsyncBufferedMutatorImpl) CONN.getBufferedMutatorBuilder(TABLE_NAME).setWriteBufferPeriodicFlush(1, TimeUnit.SECONDS).setWriteBufferSize(10 * put.heapSize()).build()) {
List<CompletableFuture<?>> futures = new ArrayList<>();
futures.add(mutator.mutate(put));
Timeout task = mutator.periodicFlushTask;
// we should have scheduled a periodic flush task
assertNotNull(task);
for (int i = 1; ; i++) {
futures.add(mutator.mutate(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, VALUE)));
if (mutator.periodicFlushTask == null) {
break;
}
}
assertTrue(task.isCancelled());
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
AsyncTable<?> table = CONN.getTable(TABLE_NAME);
for (int i = 0; i < futures.size(); i++) {
assertArrayEquals(VALUE, table.get(new Get(Bytes.toBytes(i))).get().getValue(CF, CQ));
}
}
}
use of org.apache.hbase.thirdparty.io.netty.util.Timeout in project hbase by apache.
the class AsyncRegionLocator method withTimeout.
private <T> CompletableFuture<T> withTimeout(CompletableFuture<T> future, long timeoutNs, Supplier<String> timeoutMsg) {
if (future.isDone() || timeoutNs <= 0) {
return future;
}
Timeout timeoutTask = retryTimer.newTimeout(t -> {
if (future.isDone()) {
return;
}
future.completeExceptionally(new TimeoutIOException(timeoutMsg.get()));
}, timeoutNs, TimeUnit.NANOSECONDS);
FutureUtils.addListener(future, (loc, error) -> {
if (error != null && error.getClass() != TimeoutIOException.class) {
// cancel timeout task if we are not completed by it.
timeoutTask.cancel();
}
});
return future;
}
Aggregations