Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-25881: Create a chore to update age related metrics #3518

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test case
Rahul Kumar committed Jul 22, 2021
commit 34ba2b547d15ea9b2dac2cc3bb0b42c67a8b8dfe
Original file line number Diff line number Diff line change
@@ -22,7 +22,11 @@ public class MetricsReplicationSourceRefresherChore extends ScheduledChore {

public static final String DURATION = "hbase.metrics.replication.source.refresher.duration";
public static final int DEFAULT_DURATION = 60000;


public MetricsReplicationSourceRefresherChore(Stoppable stopper, ReplicationSource replicationSource) {
this(DEFAULT_DURATION, stopper, replicationSource);
}

public MetricsReplicationSourceRefresherChore(int duration, Stoppable stopper, ReplicationSource replicationSource) {
super("MetricsSourceRefresherChore", stopper, duration);
this.replicationSource = replicationSource;
Original file line number Diff line number Diff line change
@@ -47,7 +47,6 @@
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.regionserver.MetricsReplicationSourceRefresherChore;
import org.apache.hadoop.hbase.regionserver.MetricsSourceRefresherChore;
import org.apache.hadoop.hbase.regionserver.RSRpcServices;
import org.apache.hadoop.hbase.regionserver.RegionServerCoprocessorHost;
import org.apache.hadoop.hbase.replication.ChainWALEntryFilter;
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.apache.hadoop.hbase.replication.regionserver;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.PriorityBlockingQueue;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge;
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;

@Category({SmallTests.class})
public class TestMetricsReplicationSourceRefresherChore {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule
.forClass(TestMetricsReplicationSourceRefresherChore.class);

@Test
public void testOldestWalAgeMetricsRefresherCore() {
HRegionServer rs = mock(HRegionServer.class);
ReplicationSource mockSource = Mockito.mock(ReplicationSource.class);
MetricsSource mockMetricsSource = Mockito.mock(MetricsSource.class);
Mockito.when(mockSource.getSourceMetrics()).thenReturn(mockMetricsSource);
ManualEnvironmentEdge manualEdge = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge(manualEdge);
MetricsReplicationSourceRefresherChore mrsrChore = new MetricsReplicationSourceRefresherChore(10, rs, mockSource);

manualEdge.setValue(10);
final Path log1 = new Path("log-walgroup-a.8");
String walGroupId1 = "fake-walgroup-id-1";
Map<String, PriorityBlockingQueue<Path>> queues = new ConcurrentHashMap<>();
PriorityBlockingQueue<Path> queue = new PriorityBlockingQueue<>(1, new AbstractFSWALProvider.WALStartTimeComparator());
queue.put(log1);
queues.put(walGroupId1, queue);
Mockito.when(mockSource.getQueues()).thenReturn(queues);
mrsrChore.chore();
verify(mockMetricsSource, times(1)).setOldestWalAge(2);

manualEdge.setValue(20);
final Path log2 = new Path("log-walgroup-b.8");
String walGroupId2 = "fake-walgroup-id-2";
queue.put(log2);
queues.put(walGroupId2, queue);
mrsrChore.chore();
verify(mockMetricsSource, times(1)).setOldestWalAge(12);

}
}