8181import org .mockito .Mockito ;
8282import org .mockito .invocation .InvocationOnMock ;
8383import org .mockito .stubbing .Answer ;
84+ import org .slf4j .Logger ;
85+ import org .slf4j .LoggerFactory ;
8486
8587/**
8688 * Test compaction framework and common functions
@@ -90,10 +92,13 @@ public class TestCompaction {
9092
9193 @ ClassRule
9294 public static final HBaseClassTestRule CLASS_RULE =
93- HBaseClassTestRule .forClass (TestCompaction .class );
95+ HBaseClassTestRule .forClass (TestCompaction .class );
9496
95- @ Rule public TestName name = new TestName ();
96- private static final HBaseTestingUtility UTIL = HBaseTestingUtility .createLocalHTU ();
97+ private static final Logger LOG = LoggerFactory .getLogger (TestCompaction .class );
98+
99+ @ Rule
100+ public TestName name = new TestName ();
101+ private static final HBaseTestingUtility UTIL = new HBaseTestingUtility ();
97102 protected Configuration conf = UTIL .getConfiguration ();
98103
99104 private HRegion r = null ;
@@ -150,7 +155,6 @@ public void tearDown() throws Exception {
150155 /**
151156 * Verify that you can stop a long-running compaction
152157 * (used during RS shutdown)
153- * @throws Exception
154158 */
155159 @ Test
156160 public void testInterruptCompaction () throws Exception {
@@ -177,7 +181,7 @@ public void testInterruptCompaction() throws Exception {
177181 }
178182
179183 HRegion spyR = spy (r );
180- doAnswer (new Answer () {
184+ doAnswer (new Answer < Object > () {
181185 @ Override
182186 public Object answer (InvocationOnMock invocation ) throws Throwable {
183187 r .writestate .writesEnabled = false ;
@@ -231,15 +235,14 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
231235
232236 private int count () throws IOException {
233237 int count = 0 ;
234- for (HStoreFile f : this .r .stores .
235- get (COLUMN_FAMILY_TEXT ).getStorefiles ()) {
238+ for (HStoreFile f : this .r .stores .get (COLUMN_FAMILY_TEXT ).getStorefiles ()) {
236239 HFileScanner scanner = f .getReader ().getScanner (false , false );
237240 if (!scanner .seekTo ()) {
238241 continue ;
239242 }
240243 do {
241244 count ++;
242- } while (scanner .next ());
245+ } while (scanner .next ());
243246 }
244247 return count ;
245248 }
@@ -264,7 +267,8 @@ public void testCompactionWithCorruptResult() throws Exception {
264267
265268 Collection <HStoreFile > storeFiles = store .getStorefiles ();
266269 DefaultCompactor tool = (DefaultCompactor )store .storeEngine .getCompactor ();
267- tool .compactForTesting (storeFiles , false );
270+ CompactionRequestImpl request = new CompactionRequestImpl (storeFiles );
271+ tool .compact (request , NoLimitThroughputController .INSTANCE , null );
268272
269273 // Now lets corrupt the compacted file.
270274 FileSystem fs = store .getFileSystem ();
@@ -283,7 +287,7 @@ public void testCompactionWithCorruptResult() throws Exception {
283287 // in the 'tmp' directory;
284288 assertTrue (fs .exists (origPath ));
285289 assertFalse (fs .exists (dstPath ));
286- System . out . println ("testCompactionWithCorruptResult Passed" );
290+ LOG . info ("testCompactionWithCorruptResult Passed" );
287291 return ;
288292 }
289293 fail ("testCompactionWithCorruptResult failed since no exception was" +
@@ -338,28 +342,27 @@ public void testCompactionFailure() throws Exception {
338342 Mockito .when (mockRegion .checkSplit ()).
339343 thenThrow (new RuntimeException ("Thrown intentionally by test!" ));
340344
341- MetricsRegionWrapper metricsWrapper = new MetricsRegionWrapperImpl (r );
345+ try ( MetricsRegionWrapperImpl metricsWrapper = new MetricsRegionWrapperImpl (r )) {
342346
343- long preCompletedCount = metricsWrapper .getNumCompactionsCompleted ();
344- long preFailedCount = metricsWrapper .getNumCompactionsFailed ();
347+ long preCompletedCount = metricsWrapper .getNumCompactionsCompleted ();
348+ long preFailedCount = metricsWrapper .getNumCompactionsFailed ();
345349
346- CountDownLatch latch = new CountDownLatch (1 );
347- Tracker tracker = new Tracker (latch );
348- thread .requestCompaction (mockRegion , store , "test custom comapction" , PRIORITY_USER ,
349- tracker , null );
350- // wait for the latch to complete.
351- latch .await (120 , TimeUnit .SECONDS );
352-
353- // compaction should have completed and been marked as failed due to error in split request
354- long postCompletedCount = metricsWrapper .getNumCompactionsCompleted ();
355- long postFailedCount = metricsWrapper .getNumCompactionsFailed ();
356-
357- assertTrue ("Completed count should have increased (pre=" + preCompletedCount +
358- ", post=" +postCompletedCount +")" ,
359- postCompletedCount > preCompletedCount );
360- assertTrue ("Failed count should have increased (pre=" + preFailedCount +
361- ", post=" + postFailedCount + ")" ,
362- postFailedCount > preFailedCount );
350+ CountDownLatch latch = new CountDownLatch (1 );
351+ Tracker tracker = new Tracker (latch );
352+ thread .requestCompaction (mockRegion , store , "test custom comapction" , PRIORITY_USER , tracker ,
353+ null );
354+ // wait for the latch to complete.
355+ latch .await (120 , TimeUnit .SECONDS );
356+
357+ // compaction should have completed and been marked as failed due to error in split request
358+ long postCompletedCount = metricsWrapper .getNumCompactionsCompleted ();
359+ long postFailedCount = metricsWrapper .getNumCompactionsFailed ();
360+
361+ assertTrue ("Completed count should have increased (pre=" + preCompletedCount + ", post=" +
362+ postCompletedCount + ")" , postCompletedCount > preCompletedCount );
363+ assertTrue ("Failed count should have increased (pre=" + preFailedCount + ", post=" +
364+ postFailedCount + ")" , postFailedCount > preFailedCount );
365+ }
363366 }
364367
365368 /**
0 commit comments