Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,11 @@ private void addHAContextAttributes(HttpServer.Builder builder, HiveConf hiveCon
builder.setContextAttribute("hs2.failover.callback", new FailoverHandlerCallback(hs2HARegistry));
}

private static HttpServer.Builder createHttpServerBuilder(String webHost, int port, String name, String contextPath,
@VisibleForTesting
static HttpServer.Builder createHttpServerBuilder(String webHost, int port, String name, String contextPath,
HiveConf hiveConf, CLIService cliService, PamAuthenticator pamAuthenticator) throws IOException {
HttpServer.Builder builder = new HttpServer.Builder(name);
hiveConf.set("startcode", String.valueOf(System.currentTimeMillis()));
builder.setConf(hiveConf);
builder.setHost(webHost);
builder.setPort(port);
Expand All @@ -476,7 +478,6 @@ private static HttpServer.Builder createHttpServerBuilder(String webHost, int po
builder.setAdmins(hiveConf.getVar(ConfVars.USERS_IN_ADMIN_ROLE));
// SessionManager is initialized
builder.setContextAttribute("hive.sm", cliService.getSessionManager());
hiveConf.set("startcode", String.valueOf(System.currentTimeMillis()));
if (hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_WEBUI_USE_SSL)) {
String keyStorePath = hiveConf.getVar(ConfVars.HIVE_SERVER2_WEBUI_SSL_KEYSTORE_PATH);
if (StringUtils.isBlank(keyStorePath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@
import org.apache.hadoop.hive.conf.Constants;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
import org.apache.hive.http.HttpServer;
import org.apache.hive.service.cli.CLIService;
import org.apache.hive.service.cli.session.SessionManager;
import org.junit.Test;

import java.lang.reflect.Field;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TestHiveServer2 {

Expand Down Expand Up @@ -98,4 +108,24 @@ public void testMaybeStartCompactorThreadsMultipleCustomPoolsAndDefaultPool() {
assertEquals(Integer.valueOf(5), startedWorkers.get("pool3"));
assertEquals(Integer.valueOf(3), startedWorkers.get(Constants.COMPACTION_DEFAULT_POOL));
}

@Test
public void testCreateHttpServerBuilderStampsStartcodeBeforeConfIsCopied() throws Exception {
HiveConf conf = new HiveConf();

CLIService cli = mock(CLIService.class);
SessionManager sessionManager = mock(SessionManager.class);
when(cli.getSessionManager()).thenReturn(sessionManager);

HttpServer.Builder builder = HiveServer2.createHttpServerBuilder(
"localhost", 0, "test", "/", conf, cli, null);

// setConf stores a *copy* of the conf on the Builder. Read that copy back via
// reflection — that's the same instance the servlet context exposes to the JSP.
Field confField = HttpServer.Builder.class.getDeclaredField("conf");
confField.setAccessible(true);
HiveConf builderConf = (HiveConf) confField.get(builder);
assertNotNull("Builder.conf must be set after createHttpServerBuilder", builderConf);
assertNotNull("startcode must be exists", builderConf.get("startcode"));
}
}