SourabhBadhya commented on code in PR #3801: URL: https://github.com/apache/hive/pull/3801#discussion_r1067811008
########## 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: Implemented using spies and made sure we are not creating a compactor chain again. Fetched the array of compactors using reflection and changed the compactor objects to corresponding spies. -- 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