InvisibleProgrammer commented on code in PR #4707:
URL: https://github.com/apache/hive/pull/4707#discussion_r1337259651
##########
ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestAtlasDumpTask.java:
##########
@@ -92,48 +90,40 @@ public class TestAtlasDumpTask {
@Test
public void testAtlasDumpMetrics() throws Exception {
- Mockito.when(work.getMetricCollector()).thenReturn(metricCollector);
-
Mockito.when(conf.get(HiveConf.ConfVars.REPL_ATLAS_ENDPOINT.varname)).thenReturn("http://localhost:21000/atlas");
-
Mockito.when(conf.get(HiveConf.ConfVars.REPL_ATLAS_REPLICATED_TO_DB.varname)).thenReturn("tgtDb");
-
Mockito.when(conf.get(HiveConf.ConfVars.REPL_SOURCE_CLUSTER_NAME.varname)).thenReturn("srcCluster");
-
Mockito.when(conf.get(HiveConf.ConfVars.REPL_TARGET_CLUSTER_NAME.varname)).thenReturn("tgtCluster");
-
Mockito.when(conf.get(ReplUtils.DEFAULT_FS_CONFIG)).thenReturn("hdfs:tgtFsUri:8020");
- Mockito.when(work.getStagingDir()).thenReturn(new
Path("hdfs://tmp:8020/staging"));
- Mockito.when(work.getSrcDB()).thenReturn("srcDB");
- Mockito.when(work.isBootstrap()).thenReturn(true);
- atlasDumpTask = new AtlasDumpTask(atlasRestClient, conf, work);
+ AtlasDumpLogger logger = mock(AtlasDumpLogger.class);
+ when(work.getMetricCollector()).thenReturn(metricCollector);
+
when(conf.get(HiveConf.ConfVars.REPL_ATLAS_ENDPOINT.varname)).thenReturn("http://localhost:21000/atlas");
+
when(conf.get(HiveConf.ConfVars.REPL_ATLAS_REPLICATED_TO_DB.varname)).thenReturn("tgtDb");
+
when(conf.get(HiveConf.ConfVars.REPL_SOURCE_CLUSTER_NAME.varname)).thenReturn("srcCluster");
+
when(conf.get(HiveConf.ConfVars.REPL_TARGET_CLUSTER_NAME.varname)).thenReturn("tgtCluster");
+
when(conf.get(ReplUtils.DEFAULT_FS_CONFIG)).thenReturn("hdfs:tgtFsUri:8020");
+ when(work.getStagingDir()).thenReturn(new Path("hdfs://tmp:8020/staging"));
+ when(work.getSrcDB()).thenReturn("srcDB");
+ when(work.isBootstrap()).thenReturn(true);
+ ReplLoggerFactory replLoggerFactoryMock = mock(ReplLoggerFactory.class);
+ when(replLoggerFactoryMock.createAtlasDumpLogger(anyString(),
anyString())).thenReturn(logger);
+ atlasDumpTask = new AtlasDumpTask(atlasRestClient, conf, work,
replLoggerFactoryMock);
AtlasDumpTask atlasDumpTaskSpy = Mockito.spy(atlasDumpTask);
-
Mockito.when(conf.getBoolVar(HiveConf.ConfVars.HIVE_IN_TEST_REPL)).thenReturn(true);
- Logger logger = Mockito.mock(Logger.class);
- Whitebox.setInternalState(ReplState.class, logger);
+
when(conf.getBoolVar(HiveConf.ConfVars.HIVE_IN_TEST_REPL)).thenReturn(true);
Mockito.doReturn(0L).when(atlasDumpTaskSpy)
- .dumpAtlasMetaData(Mockito.any(AtlasRequestBuilder.class),
Mockito.any(AtlasReplInfo.class));
-
Mockito.doNothing().when(atlasDumpTaskSpy).createDumpMetadata(Mockito.any(AtlasReplInfo.class),
-
Mockito.any(Long.class));
+ .dumpAtlasMetaData(any(AtlasRequestBuilder.class),
any(AtlasReplInfo.class));
+
Mockito.doNothing().when(atlasDumpTaskSpy).createDumpMetadata(any(AtlasReplInfo.class),
+ any(Long.class));
int status = atlasDumpTaskSpy.execute();
Assert.assertEquals(0, status);
- ArgumentCaptor<String> replStateCaptor =
ArgumentCaptor.forClass(String.class);
- ArgumentCaptor<Object> eventCaptor = ArgumentCaptor.forClass(Object.class);
- ArgumentCaptor<Object> eventDetailsCaptor =
ArgumentCaptor.forClass(Object.class);
- Mockito.verify(logger,
- Mockito.times(2)).info(replStateCaptor.capture(),
- eventCaptor.capture(), eventDetailsCaptor.capture());
- Assert.assertEquals("REPL::{}: {}", replStateCaptor.getAllValues().get(0));
- Assert.assertEquals("ATLAS_DUMP_START", eventCaptor.getAllValues().get(0));
- Assert.assertEquals("ATLAS_DUMP_END", eventCaptor.getAllValues().get(1));
- Assert.assertTrue(eventDetailsCaptor.getAllValues().get(1).toString(),
eventDetailsCaptor.getAllValues().get(0)
- .toString().contains("{\"dbName\":\"srcDB\",\"dumpStartTime"));
- Assert.assertTrue(eventDetailsCaptor
-
.getAllValues().get(1).toString().contains("{\"dbName\":\"srcDB\",\"dumpEndTime\""));
Review Comment:
The short answer is:
> Task related tests modified a little bit: instead of checking the log
entries in the given metric tests, it just check if the startLog and endLog
methods are properly called.
The long answer is actually deep inside the abusing power of
`Whitebox.setInternalState(ReplState.class, logger);` in PowerMock:
This and all the ...Task related tests when you see that change pattern did
the following:
- The execute method in the given task creates a logger. In that case, it is
AtlasDumpLogger.
- And Whitebox.setInternalState combined with the replStateCaptor and other
captors belove, basically checks if the logger is executed with that
REPLS::ATLAS_DUMP_START and END text.
- The AtlasDumpLogger has two methods: startLog and endLog. And what they
literally do is only one thing: logs the exact same text that was originally
checked with the captors.
So that refactor actually checks if the startLog and endLog methods are
called instead of checking the output of the startLog and endLog methods.
--
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]