You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-commits@hadoop.apache.org by to...@apache.org on 2009/12/15 02:26:21 UTC

svn commit: r890595 - in /hadoop/mapreduce/branches/branch-0.21: CHANGES.txt src/test/mapred/org/apache/hadoop/util/TestReflectionUtils.java

Author: tomwhite
Date: Tue Dec 15 01:26:20 2009
New Revision: 890595

URL: http://svn.apache.org/viewvc?rev=890595&view=rev
Log:
Merge -r 890592:890593 from trunk to 0.21 branch. Fixes: MAPREDUCE-1209.

Modified:
    hadoop/mapreduce/branches/branch-0.21/CHANGES.txt
    hadoop/mapreduce/branches/branch-0.21/src/test/mapred/org/apache/hadoop/util/TestReflectionUtils.java

Modified: hadoop/mapreduce/branches/branch-0.21/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/branch-0.21/CHANGES.txt?rev=890595&r1=890594&r2=890595&view=diff
==============================================================================
--- hadoop/mapreduce/branches/branch-0.21/CHANGES.txt (original)
+++ hadoop/mapreduce/branches/branch-0.21/CHANGES.txt Tue Dec 15 01:26:20 2009
@@ -436,6 +436,9 @@
     MAPREDUCE-1229. Allow customization of job submission policy in Mumak.
     (Hong Tang via cdouglas)
 
+    MAPREDUCE-1209. Move common specific part of the test TestReflectionUtils
+    out of mapred into common. (Todd Lipcon via tomwhite)
+
   BUG FIXES
 
     MAPREDUCE-1089. Fix NPE in fair scheduler preemption when tasks are  

Modified: hadoop/mapreduce/branches/branch-0.21/src/test/mapred/org/apache/hadoop/util/TestReflectionUtils.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/branch-0.21/src/test/mapred/org/apache/hadoop/util/TestReflectionUtils.java?rev=890595&r1=890594&r2=890595&view=diff
==============================================================================
--- hadoop/mapreduce/branches/branch-0.21/src/test/mapred/org/apache/hadoop/util/TestReflectionUtils.java (original)
+++ hadoop/mapreduce/branches/branch-0.21/src/test/mapred/org/apache/hadoop/util/TestReflectionUtils.java Tue Dec 15 01:26:20 2009
@@ -16,109 +16,33 @@
  * limitations under the License.
  */
 
-package org.apache.hadoop.util;
-
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.HashMap;
+package org.apache.hadoop.util;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.JobConfigurable;
-
-import junit.framework.TestCase;
-
-public class TestReflectionUtils extends TestCase {
-
-  private static Class toConstruct[] = { String.class, TestReflectionUtils.class, HashMap.class };
-  private Throwable failure = null;
-
-  public void setUp() {
-    ReflectionUtils.clearCache();
-  }
-    
-  public void testCache() throws Exception {
-    assertEquals(0, cacheSize());
-    doTestCache();
-    assertEquals(toConstruct.length, cacheSize());
-    ReflectionUtils.clearCache();
-    assertEquals(0, cacheSize());
-  }
-    
-    
-  @SuppressWarnings("unchecked")
-  private void doTestCache() {
-    for (int i=0; i<toConstruct.length; i++) {
-      Class cl = toConstruct[i];
-      Object x = ReflectionUtils.newInstance(cl, null);
-      Object y = ReflectionUtils.newInstance(cl, null);
-      assertEquals(cl, x.getClass());
-      assertEquals(cl, y.getClass());
-    }
-  }
-    
-  public void testThreadSafe() throws Exception {
-    Thread[] th = new Thread[32];
-    for (int i=0; i<th.length; i++) {
-      th[i] = new Thread() {
-          public void run() {
-            try {
-              doTestCache();
-            } catch (Throwable t) {
-              failure = t;
-            }
-          }
-        };
-      th[i].start();
-    }
-    for (int i=0; i<th.length; i++) {
-      th[i].join();
-    }
-    if (failure != null) {
-      failure.printStackTrace();
-      fail(failure.getMessage());
-    }
-  }
-    
-  private int cacheSize() throws Exception {
-    return ReflectionUtils.getCacheSize();
-  }
-    
-  public void testCantCreate() {
-    try {
-      ReflectionUtils.newInstance(NoDefaultCtor.class, null);
-      fail("invalid call should fail");
-    } catch (RuntimeException rte) {
-      assertEquals(NoSuchMethodException.class, rte.getCause().getClass());
-    }
-  }
-    
-  @SuppressWarnings("unchecked")
-  public void testCacheDoesntLeak() throws Exception {
-    int iterations=9999; // very fast, but a bit less reliable - bigger numbers force GC
-    for (int i=0; i<iterations; i++) {
-      URLClassLoader loader = new URLClassLoader(new URL[0], getClass().getClassLoader());
-      Class cl = Class.forName("org.apache.hadoop.util.TestReflectionUtils$LoadedInChild", false, loader);
-      Object o = ReflectionUtils.newInstance(cl, null);
-      assertEquals(cl, o.getClass());
-    }
-    System.gc();
-    assertTrue(cacheSize()+" too big", cacheSize()<iterations);
-  }
-    
-  private static class LoadedInChild {
-  }
-    
-  public static class NoDefaultCtor {
-    public NoDefaultCtor(int x) {}
+
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test for the JobConf-related parts of common's ReflectionUtils
+ * class.
+ */
+public class TestReflectionUtils {
+  @Before
+  public void setUp() {
+    ReflectionUtils.clearCache();
   }
-  
+
   /**
    * This is to test backward compatibility of ReflectionUtils for 
    * JobConfigurable objects. 
    * This should be made deprecated along with the mapred package HADOOP-1230. 
    * Should be removed when mapred package is removed.
    */
+  @Test
   public void testSetConf() {
     JobConfigurableOb ob = new JobConfigurableOb();
     ReflectionUtils.setConf(ob, new Configuration());
@@ -132,5 +56,5 @@
     public void configure(JobConf job) {
       configured = true;
     }
-  }
-}
+  }
+}