HBASE-20543 Fix the flaky TestThriftHttpServer

This commit is contained in:
huzheng 2018-05-09 10:50:09 +08:00
parent dda8018b0f
commit 0dcae90eaa
1 changed files with 9 additions and 18 deletions

View File

@ -57,7 +57,6 @@ import org.apache.hbase.thirdparty.com.google.common.base.Joiner;
* interface and talk to it from client side. * interface and talk to it from client side.
*/ */
@Category({ClientTests.class, LargeTests.class}) @Category({ClientTests.class, LargeTests.class})
public class TestThriftHttpServer { public class TestThriftHttpServer {
@ClassRule @ClassRule
@ -118,18 +117,14 @@ public class TestThriftHttpServer {
LOG.info("Starting HBase Thrift server with HTTP server: " + Joiner.on(" ").join(args)); LOG.info("Starting HBase Thrift server with HTTP server: " + Joiner.on(" ").join(args));
httpServerException = null; httpServerException = null;
httpServerThread = new Thread(new Runnable() { httpServerThread = new Thread(() -> {
@Override try {
public void run() { thriftServer.doMain(args);
try { } catch (Exception e) {
thriftServer.doMain(args); httpServerException = e;
} catch (Exception e) {
httpServerException = e;
}
} }
}); });
httpServerThread.setName(ThriftServer.class.getSimpleName() + httpServerThread.setName(ThriftServer.class.getSimpleName() + "-httpServer");
"-httpServer");
httpServerThread.start(); httpServerThread.start();
} }
@ -168,13 +163,9 @@ public class TestThriftHttpServer {
startHttpServerThread(args.toArray(new String[args.size()])); startHttpServerThread(args.toArray(new String[args.size()]));
// wait up to 10s for the server to start // wait up to 10s for the server to start
for (int i = 0; i < 100 HBaseTestingUtility.waitForHostPort(HConstants.LOCALHOST, port);
&& (thriftServer.serverRunner == null || thriftServer.serverRunner.httpServer ==
null); i++) {
Thread.sleep(100);
}
String url = "http://"+ HConstants.LOCALHOST + ":" + port; String url = "http://" + HConstants.LOCALHOST + ":" + port;
try { try {
checkHttpMethods(url); checkHttpMethods(url);
talkToThriftServer(url, customHeaderSize); talkToThriftServer(url, customHeaderSize);
@ -186,7 +177,7 @@ public class TestThriftHttpServer {
if (clientSideException != null) { if (clientSideException != null) {
LOG.error("Thrift client threw an exception " + clientSideException); LOG.error("Thrift client threw an exception " + clientSideException);
if (clientSideException instanceof TTransportException) { if (clientSideException instanceof TTransportException) {
throw clientSideException; throw clientSideException;
} else { } else {
throw new Exception(clientSideException); throw new Exception(clientSideException);