8585import org .mockito .Mockito ;
8686import org .mockito .invocation .InvocationOnMock ;
8787import org .mockito .stubbing .Answer ;
88+ import org .slf4j .Logger ;
89+ import org .slf4j .LoggerFactory ;
8890
8991/**
9092 * Test compaction framework and common functions
@@ -94,9 +96,12 @@ public class TestCompaction {
9496
9597 @ ClassRule
9698 public static final HBaseClassTestRule CLASS_RULE =
97- HBaseClassTestRule .forClass (TestCompaction .class );
99+ HBaseClassTestRule .forClass (TestCompaction .class );
98100
99- @ Rule public TestName name = new TestName ();
101+ private static final Logger LOG = LoggerFactory .getLogger (TestCompaction .class );
102+
103+ @ Rule
104+ public TestName name = new TestName ();
100105 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility ();
101106 protected Configuration conf = UTIL .getConfiguration ();
102107
@@ -154,7 +159,6 @@ public void tearDown() throws Exception {
154159 /**
155160 * Verify that you can stop a long-running compaction
156161 * (used during RS shutdown)
157- * @throws Exception
158162 */
159163 @ Test
160164 public void testInterruptCompactionBySize () throws Exception {
@@ -180,7 +184,7 @@ public void testInterruptCompactionBySize() throws Exception {
180184 }
181185
182186 HRegion spyR = spy (r );
183- doAnswer (new Answer () {
187+ doAnswer (new Answer < Object > () {
184188 @ Override
185189 public Object answer (InvocationOnMock invocation ) throws Throwable {
186190 r .writestate .writesEnabled = false ;
@@ -256,7 +260,7 @@ public void testInterruptCompactionByTime() throws Exception {
256260 }
257261
258262 HRegion spyR = spy (r );
259- doAnswer (new Answer () {
263+ doAnswer (new Answer < Object > () {
260264 @ Override
261265 public Object answer (InvocationOnMock invocation ) throws Throwable {
262266 r .writestate .writesEnabled = false ;
@@ -311,15 +315,14 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
311315
312316 private int count () throws IOException {
313317 int count = 0 ;
314- for (HStoreFile f : this .r .stores .
315- get (COLUMN_FAMILY_TEXT ).getStorefiles ()) {
318+ for (HStoreFile f : this .r .stores .get (COLUMN_FAMILY_TEXT ).getStorefiles ()) {
316319 HFileScanner scanner = f .getReader ().getScanner (false , false );
317320 if (!scanner .seekTo ()) {
318321 continue ;
319322 }
320323 do {
321324 count ++;
322- } while (scanner .next ());
325+ } while (scanner .next ());
323326 }
324327 return count ;
325328 }
@@ -344,7 +347,8 @@ public void testCompactionWithCorruptResult() throws Exception {
344347
345348 Collection <HStoreFile > storeFiles = store .getStorefiles ();
346349 DefaultCompactor tool = (DefaultCompactor )store .storeEngine .getCompactor ();
347- tool .compactForTesting (storeFiles , false );
350+ CompactionRequestImpl request = new CompactionRequestImpl (storeFiles );
351+ tool .compact (request , NoLimitThroughputController .INSTANCE , null );
348352
349353 // Now lets corrupt the compacted file.
350354 FileSystem fs = store .getFileSystem ();
@@ -363,7 +367,7 @@ public void testCompactionWithCorruptResult() throws Exception {
363367 // in the 'tmp' directory;
364368 assertTrue (fs .exists (origPath ));
365369 assertFalse (fs .exists (dstPath ));
366- System . out . println ("testCompactionWithCorruptResult Passed" );
370+ LOG . info ("testCompactionWithCorruptResult Passed" );
367371 return ;
368372 }
369373 fail ("testCompactionWithCorruptResult failed since no exception was" +
@@ -418,28 +422,27 @@ public void testCompactionFailure() throws Exception {
418422 Mockito .when (mockRegion .checkSplit ()).
419423 thenThrow (new RuntimeException ("Thrown intentionally by test!" ));
420424
421- MetricsRegionWrapper metricsWrapper = new MetricsRegionWrapperImpl (r );
425+ try ( MetricsRegionWrapperImpl metricsWrapper = new MetricsRegionWrapperImpl (r )) {
422426
423- long preCompletedCount = metricsWrapper .getNumCompactionsCompleted ();
424- long preFailedCount = metricsWrapper .getNumCompactionsFailed ();
427+ long preCompletedCount = metricsWrapper .getNumCompactionsCompleted ();
428+ long preFailedCount = metricsWrapper .getNumCompactionsFailed ();
425429
426- CountDownLatch latch = new CountDownLatch (1 );
427- Tracker tracker = new Tracker (latch );
428- thread .requestCompaction (mockRegion , store , "test custom comapction" , PRIORITY_USER ,
429- tracker , null );
430- // wait for the latch to complete.
431- latch .await (120 , TimeUnit .SECONDS );
432-
433- // compaction should have completed and been marked as failed due to error in split request
434- long postCompletedCount = metricsWrapper .getNumCompactionsCompleted ();
435- long postFailedCount = metricsWrapper .getNumCompactionsFailed ();
436-
437- assertTrue ("Completed count should have increased (pre=" + preCompletedCount +
438- ", post=" +postCompletedCount +")" ,
439- postCompletedCount > preCompletedCount );
440- assertTrue ("Failed count should have increased (pre=" + preFailedCount +
441- ", post=" + postFailedCount + ")" ,
442- postFailedCount > preFailedCount );
430+ CountDownLatch latch = new CountDownLatch (1 );
431+ Tracker tracker = new Tracker (latch );
432+ thread .requestCompaction (mockRegion , store , "test custom comapction" , PRIORITY_USER , tracker ,
433+ null );
434+ // wait for the latch to complete.
435+ latch .await (120 , TimeUnit .SECONDS );
436+
437+ // compaction should have completed and been marked as failed due to error in split request
438+ long postCompletedCount = metricsWrapper .getNumCompactionsCompleted ();
439+ long postFailedCount = metricsWrapper .getNumCompactionsFailed ();
440+
441+ assertTrue ("Completed count should have increased (pre=" + preCompletedCount + ", post=" +
442+ postCompletedCount + ")" , postCompletedCount > preCompletedCount );
443+ assertTrue ("Failed count should have increased (pre=" + preFailedCount + ", post=" +
444+ postFailedCount + ")" , postFailedCount > preFailedCount );
445+ }
443446 }
444447
445448 /**
0 commit comments