You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/04/04 21:01:42 UTC

[GitHub] [geode] pivotal-jbarrett commented on a diff in pull request #7551: GEODE-10216: Add test for existence of VM stats

pivotal-jbarrett commented on code in PR #7551:
URL: https://github.com/apache/geode/pull/7551#discussion_r842135856


##########
geode-core/src/distributedTest/java/org/apache/geode/internal/statistics/StatisticsDistributedTest.java:
##########
@@ -490,6 +490,53 @@ public void testPubAndSubCustomStats() throws Exception {
         combinedUpdateEvents == combinedPuts);
   }
 
+  @Test
+  public void testExistenceOfVMStats() {
+    String regionName = "region_1";
+    VM vm = getHost(0).getVM(0);
+
+    vm.invoke(() -> {
+      Properties props = new Properties();
+      props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
+      props.setProperty(STATISTIC_SAMPLE_RATE, "1000");
+
+      InternalDistributedSystem system = getSystem(props);
+
+      // assert that sampler is working as expected
+      GemFireStatSampler sampler = system.getStatSampler();
+      assertTrue(sampler.isSamplingEnabled());
+      assertTrue(sampler.isAlive());
+
+      await("awaiting SampleCollector to exist")
+          .until(() -> sampler.getSampleCollector() != null);
+
+      SampleCollector sampleCollector = sampler.getSampleCollector();
+      assertNotNull(sampleCollector);
+
+      StatisticsType VMStatsType = getSystem().findType("VMStats");
+      Statistics vmStats = getSystem().findStatisticsByType(VMStatsType)[0];
+
+      try {
+        vmStats.get("pendingFinalization");

Review Comment:
   What happens if the exception falls through rather than being caught, does that not have the same affect as failing the test?



##########
geode-core/src/distributedTest/java/org/apache/geode/internal/statistics/StatisticsDistributedTest.java:
##########
@@ -490,6 +490,53 @@ public void testPubAndSubCustomStats() throws Exception {
         combinedUpdateEvents == combinedPuts);
   }
 
+  @Test
+  public void testExistenceOfVMStats() {
+    String regionName = "region_1";
+    VM vm = getHost(0).getVM(0);
+
+    vm.invoke(() -> {
+      Properties props = new Properties();
+      props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
+      props.setProperty(STATISTIC_SAMPLE_RATE, "1000");
+
+      InternalDistributedSystem system = getSystem(props);
+
+      // assert that sampler is working as expected
+      GemFireStatSampler sampler = system.getStatSampler();
+      assertTrue(sampler.isSamplingEnabled());
+      assertTrue(sampler.isAlive());
+
+      await("awaiting SampleCollector to exist")
+          .until(() -> sampler.getSampleCollector() != null);
+
+      SampleCollector sampleCollector = sampler.getSampleCollector();
+      assertNotNull(sampleCollector);
+
+      StatisticsType VMStatsType = getSystem().findType("VMStats");
+      Statistics vmStats = getSystem().findStatisticsByType(VMStatsType)[0];
+
+      try {
+        vmStats.get("pendingFinalization");
+        vmStats.get("loadedClasses");
+        vmStats.get("unloadedClasses");
+        vmStats.get("daemonThreads");
+        vmStats.get("peakThreads");
+        vmStats.get("threads");
+        vmStats.get("threadStarts");
+        vmStats.get("cpus");
+        vmStats.get("freeMemory");
+        vmStats.get("totalMemory");
+        vmStats.get("maxMemory");
+        vmStats.get("processCpuTime");
+        vmStats.get("fdsOpen");
+        vmStats.get("fdLimit");
+      } catch (IllegalArgumentException e) {
+        fail("Stats do not exist: " + e.getMessage());

Review Comment:
   I would love to see us shy away from the this style of testing where we catch exceptions and then `fail`. I prefer that we either let the exception be thrown, and that in itself fails the tests or AssertJ's `assertThatNoException().isThrownBy(() -> {something()})`.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org