Search in sources :

Example 11 with EventLoop

use of org.apache.hbase.thirdparty.io.netty.channel.EventLoop 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

EventLoop (org.apache.hbase.thirdparty.io.netty.channel.EventLoop)11 Path (org.apache.hadoop.fs.Path)8 Test (org.junit.Test)8 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 DataNodeProperties (org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 MutableInt (org.apache.commons.lang3.mutable.MutableInt)1 TimeoutIOException (org.apache.hadoop.hbase.exceptions.TimeoutIOException)1 ExcludeDatanodeManager (org.apache.hadoop.hbase.io.asyncfs.monitor.ExcludeDatanodeManager)1 StreamSlowMonitor (org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor)1 RemoteException (org.apache.hadoop.ipc.RemoteException)1 DefaultEventLoop (org.apache.hbase.thirdparty.io.netty.channel.DefaultEventLoop)1 NioEventLoopGroup (org.apache.hbase.thirdparty.io.netty.channel.nio.NioEventLoopGroup)1 BeforeClass (org.junit.BeforeClass)1