|  | 
| 17 | 17 |  */ | 
| 18 | 18 | package org.apache.hadoop.hbase.regionserver; | 
| 19 | 19 | 
 | 
|  | 20 | +import static org.apache.hadoop.hbase.regionserver.HRegion.COMPACTION_AFTER_BULKLOAD_ENABLE; | 
| 20 | 21 | import static org.mockito.ArgumentMatchers.any; | 
| 21 | 22 | import static org.mockito.ArgumentMatchers.anyInt; | 
| 22 | 23 | import static org.mockito.ArgumentMatchers.eq; | 
| @@ -84,27 +85,32 @@ public void shouldRequestCompactionAfterBulkLoad() throws IOException { | 
| 84 | 85 |     for (int i = 0; i < 5; i++) { | 
| 85 | 86 |       familyPaths.addAll(withFamilyPathsFor(family1, family2, family3)); | 
| 86 | 87 |     } | 
| 87 |  | -    when(regionServerServices.getConfiguration()).thenReturn(conf); | 
| 88 |  | -    when(regionServerServices.getCompactionRequestor()).thenReturn(compactionRequester); | 
| 89 |  | -    when(log.appendMarker(any(), any(), argThat(bulkLogWalEditType(WALEdit.BULK_LOAD)))) | 
| 90 |  | -        .thenAnswer(new Answer() { | 
| 91 |  | -          @Override | 
| 92 |  | -          public Object answer(InvocationOnMock invocation) { | 
| 93 |  | -            WALKeyImpl walKey = invocation.getArgument(1); | 
| 94 |  | -            MultiVersionConcurrencyControl mvcc = walKey.getMvcc(); | 
| 95 |  | -            if (mvcc != null) { | 
| 96 |  | -              MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); | 
| 97 |  | -              walKey.setWriteEntry(we); | 
|  | 88 | +    try { | 
|  | 89 | +      conf.setBoolean(COMPACTION_AFTER_BULKLOAD_ENABLE, true); | 
|  | 90 | +      when(regionServerServices.getConfiguration()).thenReturn(conf); | 
|  | 91 | +      when(regionServerServices.getCompactionRequestor()).thenReturn(compactionRequester); | 
|  | 92 | +      when(log.appendMarker(any(), any(), argThat(bulkLogWalEditType(WALEdit.BULK_LOAD)))) | 
|  | 93 | +          .thenAnswer(new Answer() { | 
|  | 94 | +            @Override | 
|  | 95 | +            public Object answer(InvocationOnMock invocation) { | 
|  | 96 | +              WALKeyImpl walKey = invocation.getArgument(1); | 
|  | 97 | +              MultiVersionConcurrencyControl mvcc = walKey.getMvcc(); | 
|  | 98 | +              if (mvcc != null) { | 
|  | 99 | +                MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); | 
|  | 100 | +                walKey.setWriteEntry(we); | 
|  | 101 | +              } | 
|  | 102 | +              return 01L; | 
| 98 | 103 |             } | 
| 99 |  | -            return 01L; | 
| 100 |  | -          } | 
| 101 |  | -        }); | 
|  | 104 | +          }); | 
| 102 | 105 | 
 | 
| 103 |  | -    Mockito.doNothing().when(compactionRequester).requestCompaction(any(), any(), any(), anyInt(), | 
| 104 |  | -      any(), any()); | 
| 105 |  | -    testRegionWithFamilies(family1, family2, family3).bulkLoadHFiles(familyPaths, false, null); | 
| 106 |  | -    // invoke three times for 3 families | 
| 107 |  | -    verify(compactionRequester, times(3)).requestCompaction(isA(HRegion.class), isA(HStore.class), | 
| 108 |  | -      isA(String.class), anyInt(), eq(CompactionLifeCycleTracker.DUMMY), eq(null)); | 
|  | 106 | +      Mockito.doNothing().when(compactionRequester).requestCompaction(any(), any(), any(), anyInt(), | 
|  | 107 | +        any(), any()); | 
|  | 108 | +      testRegionWithFamilies(family1, family2, family3).bulkLoadHFiles(familyPaths, false, null); | 
|  | 109 | +      // invoke three times for 3 families | 
|  | 110 | +      verify(compactionRequester, times(3)).requestCompaction(isA(HRegion.class), isA(HStore.class), | 
|  | 111 | +        isA(String.class), anyInt(), eq(CompactionLifeCycleTracker.DUMMY), eq(null)); | 
|  | 112 | +    } finally { | 
|  | 113 | +      conf.setBoolean(COMPACTION_AFTER_BULKLOAD_ENABLE, false); | 
|  | 114 | +    } | 
| 109 | 115 |   } | 
| 110 | 116 | } | 
0 commit comments