commit 8316bf642c9c36a0b93cd243cee2ae2caf5bdf79 Author: Pravin Sinha Date: Fri Oct 9 01:43:36 2020 +0530 HIVE-24244: NPE during Atlas metadata replication diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/atlas/AtlasRestClientBuilder.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/atlas/AtlasRestClientBuilder.java index 6c609aa619..fa0ca5f634 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/atlas/AtlasRestClientBuilder.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/atlas/AtlasRestClientBuilder.java @@ -46,7 +46,6 @@ private UserGroupInformation userGroupInformation; protected String incomingUrl; protected String[] baseUrls; - private HiveConf hiveConf; public AtlasRestClientBuilder(String urls) { this.incomingUrl = urls; @@ -61,10 +60,10 @@ public AtlasRestClient getClient(HiveConf conf) throws SemanticException { if (conf.getBoolVar(HiveConf.ConfVars.HIVE_IN_TEST_REPL)) { return new NoOpAtlasRestClient(); } - return create(); + return create(conf); } - private AtlasRestClient create() throws SemanticException { + private AtlasRestClient create(HiveConf conf) throws SemanticException { if (baseUrls == null || baseUrls.length == 0) { throw new SemanticException(ErrorMsg.REPL_INVALID_CONFIG_FOR_SERVICE.format("baseUrls is not set.", ReplUtils.REPL_ATLAS_SERVICE)); @@ -73,7 +72,7 @@ private AtlasRestClient create() throws SemanticException { initializeAtlasApplicationProperties(); AtlasClientV2 clientV2 = new AtlasClientV2(this.userGroupInformation, this.userGroupInformation.getShortUserName(), baseUrls); - return new AtlasRestClientImpl(clientV2, hiveConf); + return new AtlasRestClientImpl(clientV2, conf); } private AtlasRestClientBuilder setUGInfo() throws SemanticException { diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestAtlasDumpTask.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestAtlasDumpTask.java index 6cfd782315..fbc6dfc229 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestAtlasDumpTask.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestAtlasDumpTask.java @@ -23,9 +23,12 @@ import org.apache.hadoop.hive.ql.exec.repl.atlas.AtlasReplInfo; import org.apache.hadoop.hive.ql.exec.repl.atlas.AtlasRequestBuilder; import org.apache.hadoop.hive.ql.exec.repl.atlas.AtlasRestClient; +import org.apache.hadoop.hive.ql.exec.repl.atlas.AtlasRestClientBuilder; import org.apache.hadoop.hive.ql.exec.repl.util.ReplUtils; +import org.apache.hadoop.hive.ql.parse.SemanticException; import org.apache.hadoop.hive.ql.parse.repl.ReplState; import org.apache.hadoop.hive.ql.parse.repl.metric.ReplicationMetricCollector; +import org.apache.hadoop.security.UserGroupInformation; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,11 +43,17 @@ import static org.mockito.ArgumentMatchers.any; +import java.io.IOException; + +import static org.mockito.Mockito.mock; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; + /** * Unit test class for testing Atlas metadata Dump. */ @RunWith(PowerMockRunner.class) -@PrepareForTest({LoggerFactory.class}) +@PrepareForTest({LoggerFactory.class, UserGroupInformation.class}) public class TestAtlasDumpTask { @Mock @@ -96,4 +105,13 @@ public void testAtlasDumpMetrics() throws Exception { Assert.assertTrue(eventDetailsCaptor .getAllValues().get(1).toString().contains("{\"dbName\":\"srcDB\",\"dumpEndTime\"")); } + + @Test + public void testAtlasRestClientBuilder() throws SemanticException, IOException { + mockStatic(UserGroupInformation.class); + when(UserGroupInformation.getLoginUser()).thenReturn(mock(UserGroupInformation.class)); + AtlasRestClientBuilder atlasRestCleintBuilder = new AtlasRestClientBuilder("http://localhost:31000"); + AtlasRestClient atlasClient = atlasRestCleintBuilder.getClient(conf); + Assert.assertTrue(atlasClient != null); + } }