[ 
https://issues.apache.org/jira/browse/GEODE-8520?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17202129#comment-17202129
 ] 

ASF GitHub Bot commented on GEODE-8520:
---------------------------------------

demery-pivotal commented on a change in pull request #5536:
URL: https://github.com/apache/geode/pull/5536#discussion_r494449040



##########
File path: 
geode-core/src/test/java/org/apache/geode/management/internal/beans/stats/GCStatsMonitorTest.java
##########
@@ -33,16 +45,94 @@
 
   @Before
   public void setUp() {
-    gcStatsMonitor = new GCStatsMonitor(testName.getMethodName());
+    ValueMonitor valueMonitor = mock(ValueMonitor.class);
+    gcStatsMonitor = new GCStatsMonitor(testName.getMethodName(), 
valueMonitor);
+
     assertThat(gcStatsMonitor).isNotNull();
-    assertThat(gcStatsMonitor.getStatistic("collections")).isEqualTo(0L);
-    assertThat(gcStatsMonitor.getStatistic("collectionTime")).isEqualTo(0L);
+    assertThat(gcStatsMonitor.getCollections()).isEqualTo(0L);
+    assertThat(gcStatsMonitor.getCollectionTime()).isEqualTo(0L);
   }
 
   @Test
   public void getStatisticShouldReturnZeroForUnknownStatistics() {
     assertThat(gcStatsMonitor.getStatistic("unknownStatistic")).isEqualTo(0);
   }
 
+  @Test
+  public void addStatsToMonitor() throws Exception {
+    Statistics stats = mock(Statistics.class);
+    when(stats.getUniqueId()).thenReturn(11L);
+    StatisticDescriptor d1 = mock(StatisticDescriptor.class);
+    when(d1.getName()).thenReturn(StatsKey.VM_GC_STATS_COLLECTIONS);
+    StatisticDescriptor d2 = mock(StatisticDescriptor.class);
+    when(d2.getName()).thenReturn(StatsKey.VM_GC_STATS_COLLECTION_TIME);
+    StatisticDescriptor[] descriptors = {d1, d2};
+    StatisticsType type = mock(StatisticsType.class);
+    when(stats.getType()).thenReturn(type);
+    when(type.getStatistics()).thenReturn(descriptors);
+
+    when(stats.get(any(StatisticDescriptor.class))).thenReturn(8L, 300L);

Review comment:
       This way of specifying return values unnecessarily couples the test to 
the current implementation—it insists that the implementation must call 
`stats.get(sd)` this many times, and in this specific order.
   
   On this line and the two later ones, it would be better to associate each 
value with the appropriate statistic descriptor, the way the other test does.




----------------------------------------------------------------
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:
us...@infra.apache.org


> GarbageCollectionCount metric is showing negative values
> --------------------------------------------------------
>
>                 Key: GEODE-8520
>                 URL: https://issues.apache.org/jira/browse/GEODE-8520
>             Project: Geode
>          Issue Type: Bug
>          Components: management
>    Affects Versions: 1.13.0
>            Reporter: Jinmei Liao
>            Priority: Major
>              Labels: GeodeOperationAPI, pull-request-available
>             Fix For: 1.14.0
>
>
> sometimes the memberMBean's garbageCollectionCount and garbageCollectionTime 
> metriics are showing negative values.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to