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
Show file tree
Hide file tree
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
Fix RelicationSOource tests
  • Loading branch information
Rahul Kumar committed Jul 30, 2021
commit 4cba9045abfe9fcb0e1d9d210320c3bcd3461fa5
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public ExecutorService getExecutorService() {

@Override
public ChoreService getChoreService() {
return null;
return new ChoreService(getClass().getSimpleName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ public void testTerminateTimeout() throws Exception {
testConf.setInt("replication.source.maxretriesmultiplier", 1);
ReplicationSourceManager manager = Mockito.mock(ReplicationSourceManager.class);
Mockito.when(manager.getTotalBufferUsed()).thenReturn(new AtomicLong());
source.init(testConf, null, manager, null, mockPeer, null, "testPeer",
RegionServerServices rss =
TEST_UTIL.createMockRegionServerService(ServerName.parseServerName("a.b.c,1,1"));
source.init(testConf, null, manager, null, mockPeer, rss, "testPeer",
null, p -> OptionalLong.empty(), null);
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<?> future = executor.submit(
Expand All @@ -289,7 +291,9 @@ public void testTerminateClearsBuffer() throws Exception {
ReplicationPeer mockPeer = mock(ReplicationPeer.class);
Mockito.when(mockPeer.getPeerBandwidth()).thenReturn(0L);
Configuration testConf = HBaseConfiguration.create();
source.init(testConf, null, mockManager, null, mockPeer, null,
RegionServerServices rss =
TEST_UTIL.createMockRegionServerService(ServerName.parseServerName("a.b.c,1,1"));
source.init(testConf, null, mockManager, null, mockPeer, rss,
"testPeer", null, p -> OptionalLong.empty(), mock(MetricsSource.class));
ReplicationSourceWALReader reader = new ReplicationSourceWALReader(null,
conf, null, 0, null, source, null);
Expand Down Expand Up @@ -635,10 +639,10 @@ public void testAgeOfOldestWal() throws Exception {
try {
ManualEnvironmentEdge manualEdge = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge(manualEdge);

String id = "1";
MetricsSource metrics = new MetricsSource(id);
Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
conf.setInt(MetricsReplicationSourceRefresherChore.DURATION, 1000);
conf.setInt("replication.source.maxretriesmultiplier", 1);
ReplicationPeer mockPeer = Mockito.mock(ReplicationPeer.class);
Mockito.when(mockPeer.getConfiguration()).thenReturn(conf);
Expand All @@ -653,7 +657,6 @@ public void testAgeOfOldestWal() throws Exception {
thenReturn(mock(MetricsReplicationGlobalSourceSource.class));
RegionServerServices rss =
TEST_UTIL.createMockRegionServerService(ServerName.parseServerName("a.b.c,1,1"));

ReplicationSource source = new ReplicationSource();
source.init(conf, null, manager, null, mockPeer, rss, id, null,
p -> OptionalLong.empty(), metrics);
Expand All @@ -662,12 +665,16 @@ public void testAgeOfOldestWal() throws Exception {
manualEdge.setValue(10);
// Diff of current time (10) and log-walgroup-a.8 timestamp will be 2.
source.enqueueLog(log1);
// Sleep for chore to update WAL age
Thread.sleep(1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Waiter.waitFor method to wait on some condition. That way if the jenkins machine are slow, it will not create flaky tests.

MetricsReplicationSourceSource metricsSource1 = getSourceMetrics(id);
assertEquals(2, metricsSource1.getOldestWalAge());

final Path log2 = new Path(logDir, "log-walgroup-b.4");
// Diff of current time (10) and log-walgroup-b.4 will be 6 so oldestWalAge should be 6
source.enqueueLog(log2);
// Sleep for chore to update WAL age
Thread.sleep(1000);
assertEquals(6, metricsSource1.getOldestWalAge());
// Clear all metrics.
metrics.clear();
Expand Down