@@ -0,0 +1,3222 @@
+/*%0A * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0%0A * (the %22License%22). You may not use this work except in compliance with the License, which is%0A * available at www.apache.org/licenses/LICENSE-2.0%0A *%0A * This software is distributed on an %22AS IS%22 basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,%0A * either express or implied, as more fully set forth in the License.%0A *%0A * See the NOTICE file distributed with this work for information regarding copyright ownership.%0A */%0A%0Apackage alluxio.worker.netty;%0A%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport alluxio.client.netty.ClientHandler;%0Aimport alluxio.client.netty.NettyClient;%0Aimport alluxio.client.netty.SingleResponseListener;%0Aimport alluxio.network.protocol.RPCBlockWriteRequest;%0Aimport alluxio.network.protocol.RPCResponse;%0Aimport alluxio.network.protocol.databuffer.DataByteArrayChannel;%0Aimport alluxio.util.CommonUtils;%0Aimport alluxio.worker.AlluxioWorker;%0Aimport alluxio.worker.block.BlockWorker;%0Aimport alluxio.worker.file.FileSystemWorker;%0A%0Aimport io.netty.bootstrap.Bootstrap;%0Aimport io.netty.channel.Channel;%0Aimport io.netty.channel.ChannelFuture;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.mockito.Mockito;%0A%0Aimport java.net.InetSocketAddress;%0Aimport java.util.concurrent.TimeUnit;%0A%0A/**%0A * Unit tests for %7B@link NettyDataServer%7D. The entire alluxio.worker.netty package is treated as one%0A * unit for the purposes of these tests; all classes except for NettyDataServer are package-private.%0A */%0Apublic final class NettyDataServerTest %7B%0A  private NettyDataServer mNettyDataServer;%0A  private BlockWorker mBlockWorker;%0A  private FileSystemWorker mFileSystemWorker;%0A%0A  @Before%0A  public void before() %7B%0A    mBlockWorker = Mockito.mock(BlockWorker.class);%0A    mFileSystemWorker = Mockito.mock(FileSystemWorker.class);%0A    AlluxioWorker alluxioWorker = Mockito.mock(AlluxioWorker.class);%0A    Mockito.when(alluxioWorker.getBlockWorker()).thenReturn(mBlockWorker);%0A    Mockito.when(alluxioWorker.getFileSystemWorker()).thenReturn(mFileSystemWorker);%0A%0A    mNettyDataServer = new NettyDataServer(new InetSocketAddress(0), alluxioWorker);%0A  %7D%0A%0A  @After%0A  public void after() throws Exception %7B%0A    mNettyDataServer.close();%0A  %7D%0A%0A  @Test%0A  public void closeTest() throws Exception %7B%0A    mNettyDataServer.close();%0A  %7D%0A%0A  @Test%0A  public void portTest() %7B%0A    assertTrue(mNettyDataServer.getPort() %3E 0);%0A  %7D%0A%0A  @Test%0A  public void writeBlockTest() throws Exception %7B%0A    InetSocketAddress address = new InetSocketAddress(mNettyDataServer.getBindHost(), mNettyDataServer.getPort());%0A    ClientHandler handler = new ClientHandler();%0A    Bootstrap clientBootstrap = NettyClient.createClientBootstrap(handler);%0A    ChannelFuture f = clientBootstrap.connect(address).sync();%0A    Channel channel = f.channel();%0A    SingleResponseListener listener = new SingleResponseListener();%0A    handler.addListener(listener);%0A    channel.writeAndFlush(new RPCBlockWriteRequest(0, 1, 2, 3,%0A        new DataByteArrayChannel(new byte%5B%5D %7B1, 2, 3%7D, 1, 1)));%0A    RPCResponse response = listener.get(NettyClient.TIMEOUT_MS, TimeUnit.MILLISECONDS);%0A    channel.close().sync();%0A    CommonUtils.sleepMs(100000000);%0A  %7D%0A%7D%0A

Add unit test for NettyDataServer package