Search in sources :

Example 1 with DefaultEventLoop

use of org.apache.hbase.thirdparty.io.netty.channel.DefaultEventLoop in project hbase by apache.

the class TestIPCUtil method testExecute.

@Test
public void testExecute() throws IOException {
    EventLoop eventLoop = new DefaultEventLoop();
    MutableInt executed = new MutableInt(0);
    MutableInt numStackTraceElements = new MutableInt(0);
    CompletableFuture<Void> future = new CompletableFuture<>();
    try {
        IPCUtil.execute(eventLoop, new Runnable() {

            @Override
            public void run() {
                int numElements = new Exception().getStackTrace().length;
                int depth = executed.getAndIncrement();
                if (depth <= IPCUtil.MAX_DEPTH) {
                    if (numElements <= numStackTraceElements.intValue()) {
                        future.completeExceptionally(new AssertionError("should call run directly but stack trace decreased from " + numStackTraceElements.intValue() + " to " + numElements));
                        return;
                    }
                    numStackTraceElements.setValue(numElements);
                    IPCUtil.execute(eventLoop, this);
                } else {
                    if (numElements >= numStackTraceElements.intValue()) {
                        future.completeExceptionally(new AssertionError("should call eventLoop.execute to prevent stack overflow but" + " stack trace increased from " + numStackTraceElements.intValue() + " to " + numElements));
                    } else {
                        future.complete(null);
                    }
                }
            }
        });
        FutureUtils.get(future);
    } finally {
        eventLoop.shutdownGracefully();
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) EventLoop(org.apache.hbase.thirdparty.io.netty.channel.EventLoop) DefaultEventLoop(org.apache.hbase.thirdparty.io.netty.channel.DefaultEventLoop) MutableInt(org.apache.commons.lang3.mutable.MutableInt) DefaultEventLoop(org.apache.hbase.thirdparty.io.netty.channel.DefaultEventLoop) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeoutException (java.util.concurrent.TimeoutException)1 MutableInt (org.apache.commons.lang3.mutable.MutableInt)1 TimeoutIOException (org.apache.hadoop.hbase.exceptions.TimeoutIOException)1 DefaultEventLoop (org.apache.hbase.thirdparty.io.netty.channel.DefaultEventLoop)1 EventLoop (org.apache.hbase.thirdparty.io.netty.channel.EventLoop)1 Test (org.junit.Test)1