SourabhBadhya commented on code in PR #4707:
URL: https://github.com/apache/hive/pull/4707#discussion_r1340939040
##########
ql/pom.xml:
##########
@@ -809,20 +808,8 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>${mockito-core.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <version>${powermock.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
- <version>${powermock.version}</version>
+ <artifactId>mockito-inline</artifactId>
+ <version>4.11.0</version>
Review Comment:
Consider defining a `${mockito-inline.version}` since the same version is
used in beeline package as well.
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/CreateFunctionHandler.java:
##########
@@ -155,7 +156,7 @@ static class PrimaryToReplicaResourceFunction
private String destinationDbName;
PrimaryToReplicaResourceFunction(Context context, MetaData metadata,
- String destinationDbName) {
+ String destinationDbName) {
Review Comment:
Please correct formatting. Avoid unnecessary changes which impact git
history.
##########
ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestRangerLoadTask.java:
##########
@@ -111,32 +113,34 @@ public void testSuccessNonEmptyRangerPolicies() throws
Exception {
+
"\"dataMaskPolicyItems\":[],\"rowFilterPolicyItems\":[],\"id\":40,\"guid\":"
+
"\"4e2b3406-7b9a-4004-8cdf-7a239c8e2cae\",\"isEnabled\":true,\"version\":1}]}";
RangerExportPolicyList rangerPolicyList = new
Gson().fromJson(rangerResponse, RangerExportPolicyList.class);
- Mockito.when(conf.get(RANGER_REST_URL)).thenReturn("rangerEndpoint");
- Mockito.when(work.getSourceDbName()).thenReturn("srcdb");
- Mockito.when(work.getTargetDbName()).thenReturn("tgtdb");
+ when(conf.get(RANGER_REST_URL)).thenReturn("rangerEndpoint");
+ when(work.getSourceDbName()).thenReturn("srcdb");
+ when(work.getTargetDbName()).thenReturn("tgtdb");
Path rangerDumpPath = new Path("/tmp");
- Mockito.when(work.getCurrentDumpPath()).thenReturn(rangerDumpPath);
- Mockito.when(mockClient.readRangerPoliciesFromJsonFile(Mockito.any(),
Mockito.any())).thenReturn(rangerPolicyList);
- Mockito.when(work.getRangerConfigResource()).thenReturn(new
URL("file://ranger.xml"));
+ when(work.getCurrentDumpPath()).thenReturn(rangerDumpPath);
+ when(mockClient.readRangerPoliciesFromJsonFile(Mockito.any(),
Mockito.any())).thenReturn(rangerPolicyList);
+ when(work.getRangerConfigResource()).thenReturn(new
URL("file://ranger.xml"));
int status = task.execute();
Assert.assertEquals(0, status);
}
@Test
public void testSuccessRangerDumpMetrics() throws Exception {
- Logger logger = Mockito.mock(Logger.class);
- Whitebox.setInternalState(ReplState.class, logger);
+ Logger logger = LoggerFactory.getLogger("ReplState");
+ StringAppender appender = StringAppender.createStringAppender(null);
+ appender.addToLogger(logger.getName(), Level.INFO);
+ appender.start();
String rangerResponse = "{\"metaDataInfo\":{\"Host
name\":\"ranger.apache.org\","
- + "\"Exported by\":\"hive\",\"Export time\":\"May 5, 2020, 8:55:03
AM\",\"Ranger apache version\""
- +
":\"2.0.0.7.2.0.0-61\"},\"policies\":[{\"service\":\"cm_hive\",\"name\":\"db-level\",\"policyType\":0,"
- +
"\"description\":\"\",\"isAuditEnabled\":true,\"resources\":{\"database\":{\"values\":[\"aa\"],"
- +
"\"isExcludes\":false,\"isRecursive\":false},\"column\":{\"values\":[\"id\"],\"isExcludes\":false,"
- +
"\"isRecursive\":false},\"table\":{\"values\":[\"*\"],\"isExcludes\":false,\"isRecursive\":false}},"
- +
"\"policyItems\":[{\"accesses\":[{\"type\":\"select\",\"isAllowed\":true},{\"type\":\"update\","
- +
"\"isAllowed\":true}],\"users\":[\"admin\"],\"groups\":[\"public\"],\"conditions\":[],"
- +
"\"delegateAdmin\":false}],\"denyPolicyItems\":[],\"allowExceptions\":[],\"denyExceptions\":[],"
- +
"\"dataMaskPolicyItems\":[],\"rowFilterPolicyItems\":[],\"id\":40,\"guid\":"
- +
"\"4e2b3406-7b9a-4004-8cdf-7a239c8e2cae\",\"isEnabled\":true,\"version\":1}]}";
+ + "\"Exported by\":\"hive\",\"Export time\":\"May 5, 2020, 8:55:03
AM\",\"Ranger apache version\""
+ +
":\"2.0.0.7.2.0.0-61\"},\"policies\":[{\"service\":\"cm_hive\",\"name\":\"db-level\",\"policyType\":0,"
+ +
"\"description\":\"\",\"isAuditEnabled\":true,\"resources\":{\"database\":{\"values\":[\"aa\"],"
+ +
"\"isExcludes\":false,\"isRecursive\":false},\"column\":{\"values\":[\"id\"],\"isExcludes\":false,"
+ +
"\"isRecursive\":false},\"table\":{\"values\":[\"*\"],\"isExcludes\":false,\"isRecursive\":false}},"
+ +
"\"policyItems\":[{\"accesses\":[{\"type\":\"select\",\"isAllowed\":true},{\"type\":\"update\","
+ +
"\"isAllowed\":true}],\"users\":[\"admin\"],\"groups\":[\"public\"],\"conditions\":[],"
+ +
"\"delegateAdmin\":false}],\"denyPolicyItems\":[],\"allowExceptions\":[],\"denyExceptions\":[],"
+ +
"\"dataMaskPolicyItems\":[],\"rowFilterPolicyItems\":[],\"id\":40,\"guid\":"
+ +
"\"4e2b3406-7b9a-4004-8cdf-7a239c8e2cae\",\"isEnabled\":true,\"version\":1}]}";
Review Comment:
Unnecessary changes, please correct it.
##########
ql/src/test/org/apache/hadoop/hive/ql/testutil/ReflectionUtil.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.testutil;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.hadoop.hive.ql.txn.compactor.Cleaner;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+
+import static java.lang.String.format;
+
+/**
+ * Various helper methods for mocking.
+ * <b>Please use it only in tests, not in production code!</b>
+ */
+public class ReflectionUtil {
Review Comment:
There is already a ReflectionUtil here -
https://github.com/apache/hive/blob/master/common/src/java/org/apache/hive/common/util/ReflectionUtil.java
I think we must extend that rather than creating a new class.
##########
ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestAtlasDumpTask.java:
##########
@@ -223,36 +222,39 @@ public void testAtlasServerEntityRetryExhausted() throws
AtlasServiceException {
Assert.assertTrue(atlasServiceException == ex.getCause());
}
ArgumentCaptor<String> getServerReqCaptor =
ArgumentCaptor.forClass(String.class);
- Mockito.verify(atlasClientV2,
Mockito.times(4)).getServer(getServerReqCaptor.capture());
+ verify(atlasClientV2, times(4)).getServer(getServerReqCaptor.capture());
}
@Test
public void testAtlasClientTimeouts() throws Exception {
-
when(conf.getTimeVar(HiveConf.ConfVars.REPL_EXTERNAL_CLIENT_CONNECT_TIMEOUT,
- TimeUnit.MILLISECONDS)).thenReturn(20L);
- when(conf.getTimeVar(HiveConf.ConfVars.REPL_ATLAS_CLIENT_READ_TIMEOUT,
TimeUnit.MILLISECONDS)).thenReturn(500L);
- mockStatic(UserGroupInformation.class);
-
when(UserGroupInformation.getLoginUser()).thenReturn(mock(UserGroupInformation.class));
- mockStatic(ConfigurationConverter.class);
-
when(ConfigurationConverter.getConfiguration(Mockito.any(Properties.class))).thenCallRealMethod();
- AtlasRestClientBuilder atlasRestCleintBuilder = new
AtlasRestClientBuilder("http://localhost:31000");
- AtlasRestClient atlasClient = atlasRestCleintBuilder.getClient(conf);
- Assert.assertTrue(atlasClient != null);
- ArgumentCaptor<Properties> propsCaptor =
ArgumentCaptor.forClass(Properties.class);
- PowerMockito.verifyStatic(ConfigurationConverter.class, Mockito.times(1));
- ConfigurationConverter.getConfiguration(propsCaptor.capture());
- Assert.assertEquals("20", propsCaptor.getValue().getProperty(
- AtlasRestClientBuilder.ATLAS_PROPERTY_CONNECT_TIMEOUT_IN_MS));
- Assert.assertEquals("500", propsCaptor.getValue().getProperty(
- AtlasRestClientBuilder.ATLAS_PROPERTY_READ_TIMEOUT_IN_MS));
+ try (
+ MockedStatic<UserGroupInformation>
userGroupInformationMockedStatic = mockStatic(UserGroupInformation.class);
+ MockedStatic<ConfigurationConverter>
configurationConverterMockedStatic = mockStatic(ConfigurationConverter.class)
+ ) {
Review Comment:
Ensure formatting.
##########
ql/src/test/org/apache/hadoop/hive/ql/exec/repl/ranger/TestRangerRestClient.java:
##########
@@ -54,23 +55,26 @@ public class TestRangerRestClient {
@Mock
private HiveConf conf;
+ MockedStatic<UserGroupInformation> userGroupInformationMockedStatic;
+
@Before
public void setup() throws Exception {
- PowerMockito.mockStatic(UserGroupInformation.class);
-
Mockito.when(UserGroupInformation.getLoginUser()).thenReturn(userGroupInformation);
- Mockito.when(userGroupInformation.doAs((PrivilegedAction<Object>)
Mockito.any())).thenCallRealMethod();
- Mockito.when(userGroupInformation.doAs((PrivilegedExceptionAction<Object>)
Mockito.any())).thenCallRealMethod();
+ userGroupInformationMockedStatic = mockStatic(UserGroupInformation.class);
+
+
userGroupInformationMockedStatic.when(UserGroupInformation::getLoginUser).thenReturn(userGroupInformation);
+
Mockito.when(mockClient.getRangerExportUrl(Mockito.anyString(),
Mockito.anyString(), Mockito.anyString()))
- .thenCallRealMethod();
- Mockito.when(mockClient.getRangerImportUrl(Mockito.anyString(),
Mockito.anyString()))
Review Comment:
Not calling real method for getRangerImportUrl()?
##########
ql/src/test/org/apache/hadoop/hive/ql/parse/repl/TestCopyUtils.java:
##########
@@ -97,151 +96,156 @@ public void shouldThrowExceptionOnDistcpFailure() throws
Exception {
List<Path> srcPaths = Arrays.asList(source, source);
HiveConf conf = mock(HiveConf.class);
CopyUtils copyUtils = Mockito.spy(new CopyUtils(null, conf, fs));
+ doReturn(false).when(copyUtils).regularCopy(same(fs), anyList());
- mockStatic(FileUtils.class);
- mockStatic(Utils.class);
- when(destination.getFileSystem(same(conf))).thenReturn(fs);
when(source.getFileSystem(same(conf))).thenReturn(fs);
- when(FileUtils.distCp(same(fs), anyListOf(Path.class), same(destination),
- anyBoolean(), eq(null), same(conf),
- same(ShimLoader.getHadoopShims())))
- .thenReturn(false);
- when(Utils.getUGI()).thenReturn(mock(UserGroupInformation.class));
- doReturn(false).when(copyUtils).regularCopy(same(fs),
anyListOf(ReplChangeManager.FileInfo.class));
-
- copyUtils.doCopy(destination, srcPaths);
+ try (MockedStatic<FileUtils> fileUtilsMockedStatic =
mockStatic(FileUtils.class);
+ MockedStatic<Utils> utilsMockedStatic = mockStatic(Utils.class)) {
+ fileUtilsMockedStatic.when(
+ () -> FileUtils.distCp(same(fs), anyList(), same(destination),
anyBoolean(), eq(null), same(conf),
+ same(ShimLoader.getHadoopShims()))).thenReturn(false);
+
utilsMockedStatic.when(Utils::getUGI).thenReturn(mock(UserGroupInformation.class));
+
+ copyUtils.doCopy(destination, srcPaths);
+ }
}
@Test
public void testFSCallsFailOnParentExceptions() throws Exception {
- mockStatic(UserGroupInformation.class);
- mockStatic(ReplChangeManager.class);
-
when(UserGroupInformation.getCurrentUser()).thenReturn(mock(UserGroupInformation.class));
- HiveConf conf = mock(HiveConf.class);
- conf.set(HiveConf.ConfVars.REPL_RETRY_INTIAL_DELAY.varname, "1s");
- FileSystem fs = mock(FileSystem.class);
- Path source = mock(Path.class);
- Path destination = mock(Path.class);
- ContentSummary cs = mock(ContentSummary.class);
-
- Exception exception = new
org.apache.hadoop.fs.PathPermissionException("Failed");
- when(ReplChangeManager.checksumFor(source,
fs)).thenThrow(exception).thenReturn("dummy");
- when(fs.exists(same(source))).thenThrow(exception).thenReturn(true);
- when(fs.delete(same(source),
anyBoolean())).thenThrow(exception).thenReturn(true);
- when(fs.mkdirs(same(source))).thenThrow(exception).thenReturn(true);
- when(fs.rename(same(source),
same(destination))).thenThrow(exception).thenReturn(true);
-
when(fs.getContentSummary(same(source))).thenThrow(exception).thenReturn(cs);
-
- CopyUtils copyUtils = new
CopyUtils(UserGroupInformation.getCurrentUser().getUserName(), conf, fs);
- CopyUtils copyUtilsSpy = Mockito.spy(copyUtils);
- try {
- copyUtilsSpy.exists(fs, source);
- } catch (Exception e) {
- assertEquals(exception.getClass(), e.getCause().getClass());
- }
- Mockito.verify(fs, Mockito.times(1)).exists(source);
- try {
- copyUtils.delete(fs, source, true);
- } catch (Exception e) {
- assertEquals(exception.getClass(), e.getCause().getClass());
- }
- Mockito.verify(fs, Mockito.times(1)).delete(source, true);
- try {
- copyUtils.mkdirs(fs, source);
- } catch (Exception e) {
- assertEquals(exception.getClass(), e.getCause().getClass());
- }
- Mockito.verify(fs, Mockito.times(1)).mkdirs(source);
- try {
- copyUtils.rename(fs, source, destination);
- } catch (Exception e) {
- assertEquals(exception.getClass(), e.getCause().getClass());
+ try (
+ MockedStatic<UserGroupInformation>
userGroupInformationMockedStatic = mockStatic(UserGroupInformation.class);
+ MockedStatic<ReplChangeManager> replChangeManagerMockedStatic =
mockStatic(ReplChangeManager.class)
+ ) {
Review Comment:
Ensure formatting.
##########
ql/src/test/org/apache/hadoop/hive/ql/parse/repl/TestCopyUtils.java:
##########
@@ -97,151 +96,156 @@ public void shouldThrowExceptionOnDistcpFailure() throws
Exception {
List<Path> srcPaths = Arrays.asList(source, source);
HiveConf conf = mock(HiveConf.class);
CopyUtils copyUtils = Mockito.spy(new CopyUtils(null, conf, fs));
+ doReturn(false).when(copyUtils).regularCopy(same(fs), anyList());
- mockStatic(FileUtils.class);
- mockStatic(Utils.class);
- when(destination.getFileSystem(same(conf))).thenReturn(fs);
when(source.getFileSystem(same(conf))).thenReturn(fs);
- when(FileUtils.distCp(same(fs), anyListOf(Path.class), same(destination),
- anyBoolean(), eq(null), same(conf),
- same(ShimLoader.getHadoopShims())))
- .thenReturn(false);
- when(Utils.getUGI()).thenReturn(mock(UserGroupInformation.class));
- doReturn(false).when(copyUtils).regularCopy(same(fs),
anyListOf(ReplChangeManager.FileInfo.class));
-
- copyUtils.doCopy(destination, srcPaths);
+ try (MockedStatic<FileUtils> fileUtilsMockedStatic =
mockStatic(FileUtils.class);
+ MockedStatic<Utils> utilsMockedStatic = mockStatic(Utils.class)) {
+ fileUtilsMockedStatic.when(
+ () -> FileUtils.distCp(same(fs), anyList(), same(destination),
anyBoolean(), eq(null), same(conf),
+ same(ShimLoader.getHadoopShims()))).thenReturn(false);
+
utilsMockedStatic.when(Utils::getUGI).thenReturn(mock(UserGroupInformation.class));
+
+ copyUtils.doCopy(destination, srcPaths);
+ }
}
@Test
public void testFSCallsFailOnParentExceptions() throws Exception {
- mockStatic(UserGroupInformation.class);
- mockStatic(ReplChangeManager.class);
-
when(UserGroupInformation.getCurrentUser()).thenReturn(mock(UserGroupInformation.class));
- HiveConf conf = mock(HiveConf.class);
- conf.set(HiveConf.ConfVars.REPL_RETRY_INTIAL_DELAY.varname, "1s");
- FileSystem fs = mock(FileSystem.class);
- Path source = mock(Path.class);
- Path destination = mock(Path.class);
- ContentSummary cs = mock(ContentSummary.class);
-
- Exception exception = new
org.apache.hadoop.fs.PathPermissionException("Failed");
- when(ReplChangeManager.checksumFor(source,
fs)).thenThrow(exception).thenReturn("dummy");
- when(fs.exists(same(source))).thenThrow(exception).thenReturn(true);
- when(fs.delete(same(source),
anyBoolean())).thenThrow(exception).thenReturn(true);
- when(fs.mkdirs(same(source))).thenThrow(exception).thenReturn(true);
- when(fs.rename(same(source),
same(destination))).thenThrow(exception).thenReturn(true);
-
when(fs.getContentSummary(same(source))).thenThrow(exception).thenReturn(cs);
-
- CopyUtils copyUtils = new
CopyUtils(UserGroupInformation.getCurrentUser().getUserName(), conf, fs);
- CopyUtils copyUtilsSpy = Mockito.spy(copyUtils);
- try {
- copyUtilsSpy.exists(fs, source);
- } catch (Exception e) {
- assertEquals(exception.getClass(), e.getCause().getClass());
- }
- Mockito.verify(fs, Mockito.times(1)).exists(source);
- try {
- copyUtils.delete(fs, source, true);
- } catch (Exception e) {
- assertEquals(exception.getClass(), e.getCause().getClass());
- }
- Mockito.verify(fs, Mockito.times(1)).delete(source, true);
- try {
- copyUtils.mkdirs(fs, source);
- } catch (Exception e) {
- assertEquals(exception.getClass(), e.getCause().getClass());
- }
- Mockito.verify(fs, Mockito.times(1)).mkdirs(source);
- try {
- copyUtils.rename(fs, source, destination);
- } catch (Exception e) {
- assertEquals(exception.getClass(), e.getCause().getClass());
+ try (
+ MockedStatic<UserGroupInformation>
userGroupInformationMockedStatic = mockStatic(UserGroupInformation.class);
+ MockedStatic<ReplChangeManager> replChangeManagerMockedStatic =
mockStatic(ReplChangeManager.class)
+ ) {
+
userGroupInformationMockedStatic.when(UserGroupInformation::getCurrentUser).thenReturn(mock(UserGroupInformation.class));
+ HiveConf conf = mock(HiveConf.class);
+ conf.set(HiveConf.ConfVars.REPL_RETRY_INTIAL_DELAY.varname, "1s");
+ FileSystem fs = mock(FileSystem.class);
+ Path source = mock(Path.class);
+ Path destination = mock(Path.class);
+ ContentSummary cs = mock(ContentSummary.class);
+
+ Exception exception = new
org.apache.hadoop.fs.PathPermissionException("Failed");
+ replChangeManagerMockedStatic.when(() ->
ReplChangeManager.checksumFor(source,
fs)).thenThrow(exception).thenReturn("dummy");
+ when(fs.exists(same(source))).thenThrow(exception).thenReturn(true);
+ when(fs.delete(same(source),
anyBoolean())).thenThrow(exception).thenReturn(true);
+ when(fs.mkdirs(same(source))).thenThrow(exception).thenReturn(true);
+ when(fs.rename(same(source),
same(destination))).thenThrow(exception).thenReturn(true);
+
when(fs.getContentSummary(same(source))).thenThrow(exception).thenReturn(cs);
+
+ CopyUtils copyUtils = new
CopyUtils(UserGroupInformation.getCurrentUser().getUserName(), conf, fs);
+ CopyUtils copyUtilsSpy = Mockito.spy(copyUtils);
+ try {
+ copyUtilsSpy.exists(fs, source);
+ } catch (Exception e) {
+ assertEquals(exception.getClass(), e.getCause().getClass());
+ }
+ Mockito.verify(fs, Mockito.times(1)).exists(source);
+ try {
+ copyUtils.delete(fs, source, true);
+ } catch (Exception e) {
+ assertEquals(exception.getClass(), e.getCause().getClass());
+ }
+ Mockito.verify(fs, Mockito.times(1)).delete(source, true);
+ try {
+ copyUtils.mkdirs(fs, source);
+ } catch (Exception e) {
+ assertEquals(exception.getClass(), e.getCause().getClass());
+ }
+ Mockito.verify(fs, Mockito.times(1)).mkdirs(source);
+ try {
+ copyUtils.rename(fs, source, destination);
+ } catch (Exception e) {
+ assertEquals(exception.getClass(), e.getCause().getClass());
+ }
+ Mockito.verify(fs, Mockito.times(1)).rename(source, destination);
+ try {
+ copyUtilsSpy.getContentSummary(fs, source);
+ } catch (Exception e) {
+ assertEquals(exception.getClass(), e.getCause().getClass());;
+ }
+ Mockito.verify(fs, Mockito.times(1)).getContentSummary(source);
+ try {
+ copyUtilsSpy.checkSumFor(source, fs);
+ } catch (Exception e) {
+ assertEquals(exception.getClass(), e.getCause().getClass());
+ }
+ Mockito.verify(copyUtilsSpy, Mockito.times(1)).checkSumFor(source, fs);
}
- Mockito.verify(fs, Mockito.times(1)).rename(source, destination);
- try {
- copyUtilsSpy.getContentSummary(fs, source);
- } catch (Exception e) {
- assertEquals(exception.getClass(), e.getCause().getClass());;
- }
- Mockito.verify(fs, Mockito.times(1)).getContentSummary(source);
- try {
- copyUtilsSpy.checkSumFor(source, fs);
- } catch (Exception e) {
- assertEquals(exception.getClass(), e.getCause().getClass());
- }
- Mockito.verify(copyUtilsSpy, Mockito.times(1)).checkSumFor(source, fs);
}
@Test
public void testRetryableFSCalls() throws Exception {
- mockStatic(UserGroupInformation.class);
- mockStatic(ReplChangeManager.class);
-
when(UserGroupInformation.getCurrentUser()).thenReturn(mock(UserGroupInformation.class));
- HiveConf conf = mock(HiveConf.class);
- conf.set(HiveConf.ConfVars.REPL_RETRY_INTIAL_DELAY.varname, "1s");
- FileSystem fs = mock(FileSystem.class);
- Path source = mock(Path.class);
- Path destination = mock(Path.class);
- ContentSummary cs = mock(ContentSummary.class);
-
- when(ReplChangeManager.checksumFor(source, fs)).thenThrow(new
IOException("Failed")).thenReturn("dummy");
- when(fs.exists(same(source))).thenThrow(new
IOException("Failed")).thenReturn(true);
- when(fs.delete(same(source), anyBoolean())).thenThrow(new
IOException("Failed")).thenReturn(true);
- when(fs.mkdirs(same(source))).thenThrow(new
IOException("Failed")).thenReturn(true);
- when(fs.rename(same(source), same(destination))).thenThrow(new
IOException("Failed")).thenReturn(true);
- when(fs.getContentSummary(same(source))).thenThrow(new
IOException("Failed")).thenReturn(cs);
-
- CopyUtils copyUtils = new
CopyUtils(UserGroupInformation.getCurrentUser().getUserName(), conf, fs);
- CopyUtils copyUtilsSpy = Mockito.spy(copyUtils);
- assertEquals (true, copyUtilsSpy.exists(fs, source));
- Mockito.verify(fs, Mockito.times(2)).exists(source);
- assertEquals (true, copyUtils.delete(fs, source, true));
- Mockito.verify(fs, Mockito.times(2)).delete(source, true);
- assertEquals (true, copyUtils.mkdirs(fs, source));
- Mockito.verify(fs, Mockito.times(2)).mkdirs(source);
- assertEquals (true, copyUtils.rename(fs, source, destination));
- Mockito.verify(fs, Mockito.times(2)).rename(source, destination);
- assertEquals (cs, copyUtilsSpy.getContentSummary(fs, source));
- Mockito.verify(fs, Mockito.times(2)).getContentSummary(source);
- assertEquals ("dummy", copyUtilsSpy.checkSumFor(source, fs));
+ try (
+ MockedStatic<UserGroupInformation>
userGroupInformationMockedStatic = mockStatic(UserGroupInformation.class);
+ MockedStatic<ReplChangeManager> replChangeManagerMockedStatic =
mockStatic(ReplChangeManager.class)
+ ) {
Review Comment:
Ensure formatting.
##########
ql/src/test/org/apache/hadoop/hive/ql/exec/repl/ranger/TestRangerRestClient.java:
##########
@@ -54,23 +55,26 @@ public class TestRangerRestClient {
@Mock
private HiveConf conf;
+ MockedStatic<UserGroupInformation> userGroupInformationMockedStatic;
+
@Before
public void setup() throws Exception {
- PowerMockito.mockStatic(UserGroupInformation.class);
-
Mockito.when(UserGroupInformation.getLoginUser()).thenReturn(userGroupInformation);
- Mockito.when(userGroupInformation.doAs((PrivilegedAction<Object>)
Mockito.any())).thenCallRealMethod();
- Mockito.when(userGroupInformation.doAs((PrivilegedExceptionAction<Object>)
Mockito.any())).thenCallRealMethod();
+ userGroupInformationMockedStatic = mockStatic(UserGroupInformation.class);
+
+
userGroupInformationMockedStatic.when(UserGroupInformation::getLoginUser).thenReturn(userGroupInformation);
+
Mockito.when(mockClient.getRangerExportUrl(Mockito.anyString(),
Mockito.anyString(), Mockito.anyString()))
- .thenCallRealMethod();
- Mockito.when(mockClient.getRangerImportUrl(Mockito.anyString(),
Mockito.anyString()))
- .thenCallRealMethod();
+ .thenCallRealMethod();
Mockito.when(conf.getTimeVar(HiveConf.ConfVars.REPL_RETRY_INTIAL_DELAY,
TimeUnit.SECONDS)).thenReturn(1L);
Mockito.when(conf.getTimeVar(HiveConf.ConfVars.REPL_RETRY_TOTAL_DURATION,
TimeUnit.SECONDS)).thenReturn(20L);
Mockito.when(conf.getTimeVar(HiveConf.ConfVars.REPL_RETRY_JITTER,
TimeUnit.SECONDS)).thenReturn(1L);
Mockito.when(conf.getTimeVar(HiveConf.ConfVars.REPL_RETRY_MAX_DELAY_BETWEEN_RETRIES,
TimeUnit.SECONDS))
- .thenReturn(10L);
-
Mockito.when(conf.getFloat(HiveConf.ConfVars.REPL_RETRY_BACKOFF_COEFFICIENT.varname,
1.0f))
Review Comment:
Why is this config removed? Is this config part of a test?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]