@Test
  public void testSuccessRangerDumpMetrics() throws Exception {
    Logger logger = LoggerFactory.getLogger("ReplState");
    StringAppender appender = StringAppender.createStringAppender(null);
    appender.addToLogger(logger.getName(), Level.INFO);
    appender.start();
    RangerExportPolicyList rangerPolicyList = new RangerExportPolicyList();
    rangerPolicyList.setPolicies(new ArrayList<RangerPolicy>());
    Mockito.when(mockClient.exportRangerPolicies(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
      Mockito.any()))
      .thenReturn(rangerPolicyList);
    Mockito.when(conf.get(RANGER_REST_URL)).thenReturn("rangerEndpoint");
    Mockito.when(conf.get(RANGER_HIVE_SERVICE_NAME)).thenReturn("hive");
    Mockito.when(work.getDbName()).thenReturn("testdb");
    Mockito.when(work.getCurrentDumpPath()).thenReturn(new Path("/tmp"));
    Mockito.when(work.getRangerConfigResource()).thenReturn(new URL("file://ranger.xml"));
    int status = task.execute();
    Assert.assertEquals(0, status);
    String logStr = appender.getOutput();
    Assert.assertEquals(2, StringUtils.countMatches(logStr, "REPL::"));
    Assert.assertTrue(logStr.contains("RANGER_DUMP_START"));
    Assert.assertTrue(logStr.contains("RANGER_DUMP_END"));
    Assert.assertTrue(logStr.contains("{\"dbName\":\"testdb\",\"dumpStartTime"));
    Assert.assertTrue(logStr.contains("{\"dbName\":\"testdb\",\"actualNumPolicies\":0,\"dumpEndTime\""));
  }
Unit test class for testing Ranger Dump.
ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestRangerDumpTask.java