shahrs87 commented on a change in pull request #2945:
URL: https://github.com/apache/hbase/pull/2945#discussion_r575555324



##########
File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSource.java
##########
@@ -590,5 +595,60 @@ public void testAbortTrueOnError() throws IOException {
       rss.stop("Done");
     }
   }
-}
 
+  /*
+    Testing age of oldest wal metric.
+  */
+  @Test
+  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("replication.source.maxretriesmultiplier", 1);
+      ReplicationPeer mockPeer = Mockito.mock(ReplicationPeer.class);
+      Mockito.when(mockPeer.getConfiguration()).thenReturn(conf);
+      Mockito.when(mockPeer.getPeerBandwidth()).thenReturn(0L);
+      ReplicationPeerConfig peerConfig = 
Mockito.mock(ReplicationPeerConfig.class);
+      Mockito.when(peerConfig.getReplicationEndpointImpl()).
+        thenReturn(DoNothingReplicationEndpoint.class.getName());
+      Mockito.when(mockPeer.getPeerConfig()).thenReturn(peerConfig);
+      ReplicationSourceManager manager = 
Mockito.mock(ReplicationSourceManager.class);
+      Mockito.when(manager.getTotalBufferUsed()).thenReturn(new AtomicLong());
+      Mockito.when(manager.getGlobalMetrics()).
+        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);
+
+      final Path log1 = new Path(logDir, "log-walgroup-a.8");
+      manualEdge.setValue(10);
+      // Diff of current time (10) and  log-walgroup-a.8 timestamp will be 2.
+      source.enqueueLog(log1);
+      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);
+      assertEquals(6, metricsSource1.getOldestWalAge());
+      // Clear all metrics.

Review comment:
       Added a test case for first point. 
   Don't know how test case will differ for RecoveredReplicationSource compared 
to regular ReplicationSource.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to