veghlaci05 commented on code in PR #3801:
URL: https://github.com/apache/hive/pull/3801#discussion_r1065947652


##########
itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestCrudCompactorOnTez.java:
##########
@@ -3189,11 +3302,42 @@ private void testCompactionWithMerge(CompactionType 
compactionType, boolean isPa
     // Verify delete delta
     Assert.assertTrue(CompactorTestUtil.getBaseOrDeltaNames(fs, 
AcidUtils.deleteEventDeltaDirFilter, table,
             partitionName).isEmpty());
-    // Run a compaction
-    if (partitionName == null) {
-      CompactorTestUtil.runCompaction(conf, dbName, tableName, compactionType, 
true);
-    } else {
-      CompactorTestUtil.runCompaction(conf, dbName, tableName, compactionType, 
true, partitionName);
+    // Run a compaction which uses only merge compactor / query-based 
compaction
+    CompactorFactory compactorFactory = mock(CompactorFactory.class);
+    // Return mocked instance of CompactorFactory
+    try (MockedStatic mockedStatic = mockStatic(CompactorFactory.class)) {
+      
mockedStatic.when(CompactorFactory::getInstance).thenReturn(compactorFactory);
+      Compactor compactor;
+      List<Compactor> compactorList = new ArrayList<>();
+      if (useFallback) {
+        // Create a mock of merge compactor
+        compactor = mock(MergeCompactor.class);
+        compactorList.add(compactor);
+        if (compactionType == CompactionType.MAJOR) {
+          compactorList.add(new MajorQueryCompactor());
+        } else {
+          compactorList.add(new MinorQueryCompactor());
+        }
+      } else {
+        // Create a mock of major/minor compactor
+        if (compactionType == CompactionType.MAJOR) {
+          compactor = mock(MajorQueryCompactor.class);
+        } else {
+          compactor = mock(MinorQueryCompactor.class);
+        }
+        compactorList.add(new MergeCompactor());
+        compactorList.add(compactor);
+      }
+      // Mocked compaction always returns false
+      when(compactor.run(any(), any(), any(), any(), any(), any(), 
any())).thenReturn(false);
+      CompactorChain compactorChain = new CompactorChain(compactorList);
+      // Return mocked compactor chain
+      when(compactorFactory.getCompactor(any(), any(), any(), 
any())).thenReturn(compactorChain);
+      if (partitionName == null) {
+        CompactorTestUtil.runCompaction(conf, dbName, tableName, 
compactionType, true);
+      } else {
+        CompactorTestUtil.runCompaction(conf, dbName, tableName, 
compactionType, true, partitionName);
+      }

Review Comment:
   Sorry when I said you may need to mock something I was using bad wording. 
You should not re-create the compactor chain and the compactors inside, because 
in that case you are not testing the production code anymore. Instead, you 
should only check if the right chain was created with the right compactors in 
the right order. Also, you should check that the fallback Compactor was called 
only when MergeCompactor was expected to fail. 



-- 
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: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to