geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcmellaw...@apache.org
Subject [geode] branch develop updated: GEODE-6143: remove PowerMock from VMStatsMonitorTest (#2984)
Date Wed, 12 Dec 2018 21:22:12 GMT
This is an automated email from the ASF dual-hosted git repository.

mcmellawatt pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 82dd208  GEODE-6143: remove PowerMock from VMStatsMonitorTest (#2984)
82dd208 is described below

commit 82dd2089d042122c432700b1838c84aa2b733def
Author: Xiaojian Zhou <gesterzhou@users.noreply.github.com>
AuthorDate: Wed Dec 12 13:22:02 2018 -0800

    GEODE-6143: remove PowerMock from VMStatsMonitorTest (#2984)
---
 .../internal/beans/stats/VMStatsMonitor.java       | 11 ++++++----
 .../internal/beans/stats/VMStatsMonitorTest.java   | 25 +++-------------------
 2 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/stats/VMStatsMonitor.java
b/geode-core/src/main/java/org/apache/geode/management/internal/beans/stats/VMStatsMonitor.java
index 431996d..6830448 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/stats/VMStatsMonitor.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/stats/VMStatsMonitor.java
@@ -60,21 +60,24 @@ public class VMStatsMonitor extends MBeanStatsMonitor {
     return lastProcessCpuTime;
   }
 
-  public VMStatsMonitor(String name) {
+  public VMStatsMonitor(String name, boolean processCPUTimeAvailable) {
     super(name);
-    processCPUTimeAvailable = MBeanJMXAdapter.isAttributeAvailable(PROCESS_CPU_TIME_ATTRIBUTE,
-        ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
+    this.processCPUTimeAvailable = processCPUTimeAvailable;
     if (!processCPUTimeAvailable) {
       cpuUsage = VALUE_NOT_AVAILABLE;
     }
   }
 
+  public VMStatsMonitor(String name) {
+    this(name, MBeanJMXAdapter.isAttributeAvailable(PROCESS_CPU_TIME_ATTRIBUTE,
+        ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME));
+  }
+
   long currentTimeMillis() {
     return TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
   }
 
   /**
-   *
    * @param systemTime Current system time.
    * @param cpuTime Last gathered cpu time.
    * @return The time (as a percentage) that this member's process time with respect to Statistics
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/beans/stats/VMStatsMonitorTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/beans/stats/VMStatsMonitorTest.java
index 5180971..6284ff7 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/beans/stats/VMStatsMonitorTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/beans/stats/VMStatsMonitorTest.java
@@ -16,7 +16,6 @@ package org.apache.geode.management.internal.beans.stats;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.within;
-import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -26,47 +25,30 @@ import java.time.Instant;
 import java.time.ZonedDateTime;
 import java.time.temporal.ChronoUnit;
 
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.TestName;
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 
-import org.apache.geode.management.internal.MBeanJMXAdapter;
 import org.apache.geode.test.junit.categories.StatisticsTest;
 
 @Category(StatisticsTest.class)
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore("*.UnitTest")
-@PrepareForTest(MBeanJMXAdapter.class)
 public class VMStatsMonitorTest {
   @Rule
   public TestName testName = new TestName();
 
   private VMStatsMonitor vmStatsMonitor;
 
-  @Before
-  public void setUp() {
-    PowerMockito.mockStatic(MBeanJMXAdapter.class);
-  }
-
   @Test
   public void statisticInitialValueShouldBeZeroWhenTheProcessCpuTimeJmxAttributeIsAvailable()
{
-    when(MBeanJMXAdapter.isAttributeAvailable(anyString(), anyString())).thenReturn(true);
-    vmStatsMonitor = new VMStatsMonitor(testName.getMethodName());
+    vmStatsMonitor = new VMStatsMonitor(testName.getMethodName(), true);
     assertThat(vmStatsMonitor).isNotNull();
     assertThat(vmStatsMonitor.getCpuUsage()).isEqualTo(0);
   }
 
   @Test
   public void statisticInitialValueShouldBeUndefinedWhenTheProcessCpuTimeJmxAttributeIsNotAvailable()
{
-    when(MBeanJMXAdapter.isAttributeAvailable(anyString(), anyString())).thenReturn(false);
-    vmStatsMonitor = new VMStatsMonitor(testName.getMethodName());
+    vmStatsMonitor = new VMStatsMonitor(testName.getMethodName(), false);
     assertThat(vmStatsMonitor).isNotNull();
     assertThat(vmStatsMonitor.getCpuUsage()).isEqualTo(VMStatsMonitor.VALUE_NOT_AVAILABLE);
   }
@@ -107,8 +89,7 @@ public class VMStatsMonitorTest {
   @Test
   public void refreshStatsShouldUpdateCpuUsage() {
     ZonedDateTime now = ZonedDateTime.now();
-    when(MBeanJMXAdapter.isAttributeAvailable(anyString(), anyString())).thenReturn(true);
-    vmStatsMonitor = spy(new VMStatsMonitor(testName.getMethodName()));
+    vmStatsMonitor = spy(new VMStatsMonitor(testName.getMethodName(), true));
     assertThat(vmStatsMonitor).isNotNull();
     assertThat(vmStatsMonitor.getCpuUsage()).isEqualTo(0);
     Number processCpuTime = spy(Number.class);


Mime
View raw message