Skip to content

Commit

Permalink
HIVE-28194: Regenerate HS2 thrift port in TestRetryingThriftCLIServic…
Browse files Browse the repository at this point in the history
…eClient
  • Loading branch information
Araika committed Apr 19, 2024
1 parent cf0d4f1 commit 3a25dfd
Showing 1 changed file with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.hive.service.cli;

import org.apache.hadoop.hive.common.ServerUtils;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveServer2TransportMode;
import org.apache.hive.service.Service;
Expand Down Expand Up @@ -48,12 +49,14 @@ public class TestRetryingThriftCLIServiceClient {
protected static ThriftCLIService service;
private HiveConf hiveConf;
private HiveServer2 server;
private int port = 15000;
public static final int RETRY_COUNT = 10;

@Before
public void init() {
hiveConf = new HiveConf();
hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST, "localhost");
hiveConf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT, 15000);
hiveConf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT, port);
hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS, false);
hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_AUTHENTICATION, HiveAuthConstants.AuthTypes.NONE.toString());
hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_TRANSPORT_MODE, HiveServer2TransportMode.binary.toString());
Expand All @@ -66,13 +69,30 @@ public void init() {
"org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
}

private void startHiveServer() throws InterruptedException {
// Start hive server2
server = new HiveServer2();
server.init(hiveConf);
server.start();
Thread.sleep(5000);
System.out.println("## HiveServer started");
private void startHiveServer() throws Exception {
Exception hs2Exception = null;
boolean hs2Started = false;

for (int tryCount = 0; (tryCount < RETRY_COUNT); tryCount++) {
try {
// Start hive server2
server = new HiveServer2();
server.init(hiveConf);
server.start();
Thread.sleep(5000);
System.out.println("## HiveServer started");
hs2Started = true;
break;
} catch (Exception e) {
hs2Exception = e;
port = ServerUtils.findFreePort();
hiveConf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT, port);
}
}

if (!hs2Started) {
throw(hs2Exception);
}
}

private void stopHiveServer() {
Expand Down Expand Up @@ -128,7 +148,7 @@ public void testRetryBehaviour() throws Exception {
assertTrue(sqlExc.getMessage().contains("3"));
}
// Reset port setting
hiveConf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT, 15000);
hiveConf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT, port);

hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST, "10.17.207.11");
try {
Expand Down Expand Up @@ -166,7 +186,7 @@ public void testRetryBehaviour() throws Exception {
}

@Test
public void testTransportClose() throws InterruptedException, HiveSQLException {
public void testTransportClose() throws Exception {
hiveConf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_CONNECTION_RETRY_LIMIT, 0);
try {
startHiveServer();
Expand All @@ -186,7 +206,7 @@ public void testTransportClose() throws InterruptedException, HiveSQLException {
}

@Test
public void testSessionLifeAfterTransportClose() throws InterruptedException, HiveSQLException {
public void testSessionLifeAfterTransportClose() throws Exception {
try {
startHiveServer();
CLIService service = null;
Expand Down

0 comments on commit 3a25dfd

Please sign in to comment.