/** * Create a custom compaction request and be sure that we can track it through the queue, knowing * when the compaction is completed. */ public void testTrackingCompactionRequest() throws Exception { // setup a compact/split thread on a mock server HRegionServer mockServer = Mockito.mock(HRegionServer.class); Mockito.when(mockServer.getConfiguration()).thenReturn(r.getConf()); CompactSplitThread thread = new CompactSplitThread(mockServer); Mockito.when(mockServer.getCompactSplitThread()).thenReturn(thread); // simple stop for the metrics - we ignore any updates in the test RegionServerMetrics mockMetrics = Mockito.mock(RegionServerMetrics.class); Mockito.when(mockServer.getMetrics()).thenReturn(mockMetrics); // setup a region/store with some files Store store = r.getStore(COLUMN_FAMILY); createStoreFile(r); for (int i = 0; i < MAX_FILES_TO_COMPACT + 1; i++) { createStoreFile(r); } CountDownLatch latch = new CountDownLatch(1); TrackableCompactionRequest request = new TrackableCompactionRequest(r, store, latch); thread.requestCompaction(r, store, "test custom comapction", Store.PRIORITY_USER, request); // wait for the latch to complete. latch.await(); thread.interruptIfNecessary(); }
public void testMultipleCustomCompactionRequests() throws Exception { // setup a compact/split thread on a mock server HRegionServer mockServer = Mockito.mock(HRegionServer.class); Mockito.when(mockServer.getConfiguration()).thenReturn(r.getConf()); CompactSplitThread thread = new CompactSplitThread(mockServer); Mockito.when(mockServer.getCompactSplitThread()).thenReturn(thread); // simple stop for the metrics - we ignore any updates in the test RegionServerMetrics mockMetrics = Mockito.mock(RegionServerMetrics.class); Mockito.when(mockServer.getMetrics()).thenReturn(mockMetrics); // setup a region/store with some files int numStores = r.getStores().size(); List<CompactionRequest> requests = new ArrayList<CompactionRequest>(numStores); CountDownLatch latch = new CountDownLatch(numStores); // create some store files and setup requests for each store on which we want to do a // compaction for (Store store : r.getStores().values()) { createStoreFile(r, store.getColumnFamilyName()); createStoreFile(r, store.getColumnFamilyName()); createStoreFile(r, store.getColumnFamilyName()); requests.add(new TrackableCompactionRequest(r, store, latch)); } thread.requestCompaction(r, "test mulitple custom comapctions", Store.PRIORITY_USER, Collections.unmodifiableList(requests)); // wait for the latch to complete. latch.await(); thread.interruptIfNecessary(); }
/** * @return Region server metrics instance. */ public RegionServerMetrics getMetrics() { return this.metrics; }