From f3db30ccd8825faf3d6916d9574ca6a44f4b1433 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Eagles Date: Wed, 11 Dec 2013 17:50:26 +0000 Subject: [PATCH] YARN-1491. Upgrade JUnit3 TestCase to JUnit 4 (Chen He via jeagles) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1550204 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 2 ++ .../util/TestLinuxResourceCalculatorPlugin.java | 16 ++++++++-------- .../yarn/util/TestWindowsBasedProcessTree.java | 6 +++--- .../TestWindowsResourceCalculatorPlugin.java | 10 +++++----- .../hadoop/yarn/util/TestYarnVersionInfo.java | 8 ++++---- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 7edd4bba46..5b14f63151 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -157,6 +157,8 @@ Release 2.4.0 - UNRELEASED YARN-1481. Move internal services logic from AdminService to ResourceManager. (vinodkv via kasha) + YARN-1491. Upgrade JUnit3 TestCase to JUnit 4 (Chen He via jeagles) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestLinuxResourceCalculatorPlugin.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestLinuxResourceCalculatorPlugin.java index ce9fedd233..c9a33d0f29 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestLinuxResourceCalculatorPlugin.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestLinuxResourceCalculatorPlugin.java @@ -23,16 +23,16 @@ import java.io.IOException; import java.util.Random; -import junit.framework.TestCase; import org.apache.hadoop.fs.Path; import org.junit.Test; +import static org.junit.Assert.assertEquals; /** * A JUnit test to test {@link LinuxResourceCalculatorPlugin} * Create the fake /proc/ information and verify the parsing and calculation */ -public class TestLinuxResourceCalculatorPlugin extends TestCase { +public class TestLinuxResourceCalculatorPlugin { /** * LinuxResourceCalculatorPlugin with a fake timer */ @@ -145,7 +145,7 @@ public void advanceTime(long adv) { * @throws IOException */ @Test - public void testParsingProcStatAndCpuFile() throws IOException { + public void parsingProcStatAndCpuFile() throws IOException { // Write fake /proc/cpuinfo file. long numProcessors = 8; long cpuFrequencyKHz = 2392781; @@ -171,7 +171,7 @@ public void testParsingProcStatAndCpuFile() throws IOException { updateStatFile(uTime, nTime, sTime); assertEquals(plugin.getCumulativeCpuTime(), FAKE_JIFFY_LENGTH * (uTime + nTime + sTime)); - assertEquals(plugin.getCpuUsage(), (float)(LinuxResourceCalculatorPlugin.UNAVAILABLE)); + assertEquals(plugin.getCpuUsage(), (float)(LinuxResourceCalculatorPlugin.UNAVAILABLE),0.0); // Advance the time and sample again to test the CPU usage calculation uTime += 100L; @@ -179,13 +179,13 @@ public void testParsingProcStatAndCpuFile() throws IOException { updateStatFile(uTime, nTime, sTime); assertEquals(plugin.getCumulativeCpuTime(), FAKE_JIFFY_LENGTH * (uTime + nTime + sTime)); - assertEquals(plugin.getCpuUsage(), 6.25F); + assertEquals(plugin.getCpuUsage(), 6.25F, 0.0); // Advance the time and sample again. This time, we call getCpuUsage() only. uTime += 600L; plugin.advanceTime(300L); updateStatFile(uTime, nTime, sTime); - assertEquals(plugin.getCpuUsage(), 25F); + assertEquals(plugin.getCpuUsage(), 25F, 0.0); // Advance very short period of time (one jiffy length). // In this case, CPU usage should not be updated. @@ -194,7 +194,7 @@ public void testParsingProcStatAndCpuFile() throws IOException { updateStatFile(uTime, nTime, sTime); assertEquals(plugin.getCumulativeCpuTime(), FAKE_JIFFY_LENGTH * (uTime + nTime + sTime)); - assertEquals(plugin.getCpuUsage(), 25F); // CPU usage is not updated. + assertEquals(plugin.getCpuUsage(), 25F, 0.0); // CPU usage is not updated. } /** @@ -212,7 +212,7 @@ private void updateStatFile(long uTime, long nTime, long sTime) * @throws IOException */ @Test - public void testParsingProcMemFile() throws IOException { + public void parsingProcMemFile() throws IOException { long memTotal = 4058864L; long memFree = 99632L; long inactive = 567732L; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestWindowsBasedProcessTree.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestWindowsBasedProcessTree.java index ef1ee39c49..d5b5c37830 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestWindowsBasedProcessTree.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestWindowsBasedProcessTree.java @@ -22,10 +22,10 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.util.Shell; -import junit.framework.TestCase; import org.junit.Test; +import static org.junit.Assert.assertTrue; -public class TestWindowsBasedProcessTree extends TestCase { +public class TestWindowsBasedProcessTree { private static final Log LOG = LogFactory .getLog(TestWindowsBasedProcessTree.class); @@ -41,7 +41,7 @@ String getAllProcessInfoFromShell() { } @Test (timeout = 30000) - public void testTree() { + public void tree() { if( !Shell.WINDOWS) { LOG.info("Platform not Windows. Not testing"); return; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestWindowsResourceCalculatorPlugin.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestWindowsResourceCalculatorPlugin.java index 70dde32318..a9e20bc064 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestWindowsResourceCalculatorPlugin.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestWindowsResourceCalculatorPlugin.java @@ -18,10 +18,10 @@ package org.apache.hadoop.yarn.util; -import junit.framework.TestCase; import org.junit.Test; +import static org.junit.Assert.assertTrue; -public class TestWindowsResourceCalculatorPlugin extends TestCase { +public class TestWindowsResourceCalculatorPlugin { class WindowsResourceCalculatorPluginTester extends WindowsResourceCalculatorPlugin { @@ -33,7 +33,7 @@ String getSystemInfoInfoFromShell() { } @Test (timeout = 30000) - public void testParseSystemInfoString() { + public void parseSystemInfoString() { WindowsResourceCalculatorPluginTester tester = new WindowsResourceCalculatorPluginTester(); // info str derived from windows shell command has \r\n termination tester.infoStr = "17177038848,8589467648,15232745472,6400417792,1,2805000,6261812\r\n"; @@ -51,7 +51,7 @@ public void testParseSystemInfoString() { } @Test (timeout = 20000) - public void testRefreshAndCpuUsage() throws InterruptedException { + public void refreshAndCpuUsage() throws InterruptedException { WindowsResourceCalculatorPluginTester tester = new WindowsResourceCalculatorPluginTester(); // info str derived from windows shell command has \r\n termination tester.infoStr = "17177038848,8589467648,15232745472,6400417792,1,2805000,6261812\r\n"; @@ -75,7 +75,7 @@ public void testRefreshAndCpuUsage() throws InterruptedException { } @Test (timeout = 20000) - public void testErrorInGetSystemInfo() { + public void errorInGetSystemInfo() { WindowsResourceCalculatorPluginTester tester = new WindowsResourceCalculatorPluginTester(); // info str derived from windows shell command has \r\n termination tester.infoStr = null; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestYarnVersionInfo.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestYarnVersionInfo.java index 61795cae35..47ee822007 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestYarnVersionInfo.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestYarnVersionInfo.java @@ -18,23 +18,23 @@ package org.apache.hadoop.yarn.util; -import junit.framework.TestCase; import java.io.IOException; import org.apache.hadoop.yarn.util.YarnVersionInfo; import org.junit.Test; - +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; /** * A JUnit test to test {@link YarnVersionInfo} */ -public class TestYarnVersionInfo extends TestCase { +public class TestYarnVersionInfo { /** * Test the yarn version info routines. * @throws IOException */ @Test - public void testVersionInfoGenerated() throws IOException { + public void versionInfoGenerated() throws IOException { // can't easily know what the correct values are going to be so just // make sure they aren't Unknown