You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2017/10/13 20:45:35 UTC

[geode] 03/03: GEODE-3716 - Clarify the description of stat cpuSteal. Use the junit temp folder for temp files. Use the RestoreSystemProperties rule since the test is setting some properties. Remove setting a field in the test to null.

This is an automated email from the ASF dual-hosted git repository.

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

commit c44eb4c3e2d4b18108b43c565f7f03cb7f265e12
Author: Charlie Black <ch...@github.com>
AuthorDate: Thu Oct 12 22:28:33 2017 -0700

    GEODE-3716 - Clarify the description of stat cpuSteal.
    Use the junit temp folder for temp files.
    Use the RestoreSystemProperties rule since the test is setting some properties.
    Remove setting a field in the test to null.
---
 .../statistics/platform/LinuxSystemStats.java      |  2 +-
 .../internal/statistics/LinuxSystemStatsTest.java  | 62 +++++++++++++---------
 2 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java
index 8dbb2df..c3150b6 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/platform/LinuxSystemStats.java
@@ -145,7 +145,7 @@ public class LinuxSystemStats {
                 "The percentage of total available time that has been used to execute non-user code.(includes system, iowait, irq, softirq etc.)",
                 "%"),
             f.createIntGauge("cpuSteal",
-                "Stolen time, which is the time spent in their operating systems when running in a virtualized environment.",
+                "Steal time is the amount of time the operating system wanted to execute, but was not allowed to by the hypervisor.",
                 "%"),
 
             f.createLongCounter("loopbackPackets",
diff --git a/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java b/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java
index 009eefa..c7ef560 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/statistics/LinuxSystemStatsTest.java
@@ -15,14 +15,23 @@
 
 package org.apache.geode.internal.statistics;
 
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.commons.io.IOUtils;
-import org.apache.geode.CancelCriterion;
-import org.apache.geode.Statistics;
-import org.apache.geode.internal.statistics.platform.LinuxProcFsStatistics;
-import org.apache.geode.internal.statistics.platform.LinuxSystemStats;
-import org.apache.geode.test.junit.categories.IntegrationTest;
 import org.apache.tools.ant.filters.StringInputStream;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
@@ -33,15 +42,11 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyString;
+import org.apache.geode.CancelCriterion;
+import org.apache.geode.Statistics;
+import org.apache.geode.internal.statistics.platform.LinuxProcFsStatistics;
+import org.apache.geode.internal.statistics.platform.LinuxSystemStats;
+import org.apache.geode.test.junit.categories.IntegrationTest;
 
 /**
  * Technically a linux only test - the file handling is all mocked up so the test can run on any
@@ -51,9 +56,10 @@ import static org.mockito.ArgumentMatchers.anyString;
 @RunWith(PowerMockRunner.class)
 @PowerMockIgnore("*.IntegrationTest")
 @PrepareForTest(LinuxProcFsStatistics.class)
-@Ignore
 public class LinuxSystemStatsTest extends StatSamplerTestCase {
   @Rule
+  public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+  @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
   private int[] ints;
   private long[] longs;
@@ -83,7 +89,6 @@ public class LinuxSystemStatsTest extends StatSamplerTestCase {
     StatisticsTypeFactoryImpl.clear();
     if (this.statisticsFactory != null) {
       this.statisticsFactory.close();
-      this.statisticsFactory = null;
     }
   }
 
@@ -130,7 +135,6 @@ public class LinuxSystemStatsTest extends StatSamplerTestCase {
     Answer<FileInputStream> answer = new MyStealTimeAnswer(results);
     PowerMockito.whenNew(FileInputStream.class).withArguments(anyString()).thenAnswer(answer);
 
-
     LinuxProcFsStatistics.refreshSystem(ints, longs, doubles);
     LinuxProcFsStatistics.refreshSystem(ints, longs, doubles);
 
@@ -150,14 +154,19 @@ public class LinuxSystemStatsTest extends StatSamplerTestCase {
     });
   }
 
-  private File writeStringToFile(String string) throws IOException {
-    File file = File.createTempFile("LinuxSystemStatsTest", ".test");
-    file.deleteOnExit();
-    StringInputStream sis = new StringInputStream(string);
-    FileOutputStream fos = new FileOutputStream(file);
-    IOUtils.copy(sis, fos);
-    IOUtils.closeQuietly(fos);
-    return file;
+  /**
+   * This method will allow junit to mock up how Linux reports the CPU information though a file
+   * called "/proc/stat". We need to create a new file for each call since each file could represent
+   * another phase in the mock test.
+   */
+  private File writeStringToFile(String mockProcStatFileContents) throws IOException {
+
+    File mockFile = temporaryFolder.newFile();
+    StringInputStream sis = new StringInputStream(mockProcStatFileContents);
+    FileOutputStream mockFileOutputStream = new FileOutputStream(mockFile);
+    IOUtils.copy(sis, mockFileOutputStream);
+    IOUtils.closeQuietly(mockFileOutputStream);
+    return mockFile;
   }
 
   @Override
@@ -180,6 +189,7 @@ public class LinuxSystemStatsTest extends StatSamplerTestCase {
 
     @Override
     public FileInputStream answer(InvocationOnMock invocation) throws Throwable {
+      // Since we are mocking the test we can run this test on any OS.
       if ("/proc/stat".equals(invocation.getArgument(0))) {
         return results.remove(0);
       }

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.