hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject git commit: HBASE-11984 TestClassFinder failing on occasion FIX ATTEMPT
Date Tue, 16 Sep 2014 18:32:09 GMT
Repository: hbase
Updated Branches:
  refs/heads/master cc873713c -> cf3dab7ee


HBASE-11984 TestClassFinder failing on occasion FIX ATTEMPT


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/cf3dab7e
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/cf3dab7e
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/cf3dab7e

Branch: refs/heads/master
Commit: cf3dab7ee789c76be873d663ed3c59e951278d36
Parents: cc87371
Author: stack <stack@apache.org>
Authored: Tue Sep 16 11:23:57 2014 -0700
Committer: stack <stack@apache.org>
Committed: Tue Sep 16 11:31:53 2014 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/ClassFinder.java    |   4 +-
 .../apache/hadoop/hbase/TestClassFinder.java    | 113 ++++++++++++-------
 2 files changed, 74 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/cf3dab7e/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassFinder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassFinder.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassFinder.java
index 703d15d..c15ace9 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassFinder.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassFinder.java
@@ -107,7 +107,7 @@ public class ClassFinder {
       resourcePath = isJar ? matcher.group(1) : resourcePath;
       if (null == this.resourcePathFilter
           || this.resourcePathFilter.isCandidatePath(resourcePath, isJar)) {
-        LOG.debug("Will look for classes in " + resourcePath);
+        LOG.debug("Looking in " + resourcePath + "; isJar=" + isJar);
         if (isJar) {
           jars.add(resourcePath);
         } else {
@@ -186,7 +186,7 @@ public class ClassFinder {
       boolean proceedOnExceptions) throws ClassNotFoundException, LinkageError {
     Set<Class<?>> classes = new HashSet<Class<?>>();
     if (!baseDirectory.exists()) {
-      LOG.warn("Failed to find " + baseDirectory.getAbsolutePath());
+      LOG.warn(baseDirectory.getAbsolutePath() + " does not exist");
       return classes;
     }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/cf3dab7e/hbase-common/src/test/java/org/apache/hadoop/hbase/TestClassFinder.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestClassFinder.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestClassFinder.java
index 52a17c9..0b83d05 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestClassFinder.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestClassFinder.java
@@ -46,13 +46,18 @@ import org.apache.hadoop.hbase.testclassification.MiscTests;
 import org.apache.hadoop.hbase.testclassification.SmallTests;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+import org.mortbay.log.Log;
 
 @Category({MiscTests.class, SmallTests.class})
 public class TestClassFinder {
+  @Rule public TestName name = new TestName();
   private static final HBaseCommonTestingUtility testUtil = new HBaseCommonTestingUtility();
   private static final String BASEPKG = "tfcpkg";
+  private static final String PREFIX = "Prefix";
 
   // Use unique jar/class/package names in each test case with the help
   // of these global counters; we are mucking with ClassLoader in this test
@@ -74,6 +79,7 @@ public class TestClassFinder {
       deleteTestDir();
     }
     assertTrue(testDir.mkdirs());
+    Log.info("Using new, clean directory=" + testDir);
   }
 
   @AfterClass
@@ -113,8 +119,8 @@ public class TestClassFinder {
   @Test
   public void testClassFinderHandlesNestedPackages() throws Exception {
     final String NESTED = ".nested";
-    final String CLASSNAME1 = "c2";
-    final String CLASSNAME2 = "c3";
+    final String CLASSNAME1 = name.getMethodName() + "1";
+    final String CLASSNAME2 = name.getMethodName() + "2";
     long counter = testCounter.incrementAndGet();
     FileAndPath c1 = compileTestClass(counter, "", "c1");
     FileAndPath c2 = compileTestClass(counter, NESTED, CLASSNAME1);
@@ -134,55 +140,56 @@ public class TestClassFinder {
 
   @Test
   public void testClassFinderFiltersByNameInJar() throws Exception {
-    final String CLASSNAME = "c1";
-    final String CLASSNAMEEXCPREFIX = "c2";
-    long counter = testCounter.incrementAndGet();
-    FileAndPath c1 = compileTestClass(counter, "", CLASSNAME);
-    FileAndPath c2 = compileTestClass(counter, "", CLASSNAMEEXCPREFIX + "1");
-    FileAndPath c3 = compileTestClass(counter, "", CLASSNAMEEXCPREFIX + "2");
-    packageAndLoadJar(c1, c2, c3);
+    final long counter = testCounter.incrementAndGet();
+    final String classNamePrefix = name.getMethodName();
+    Log.info("Created jar " + createAndLoadJar("", classNamePrefix, counter));
 
     ClassFinder.FileNameFilter notExcNameFilter = new ClassFinder.FileNameFilter() {
       @Override
       public boolean isCandidateFile(String fileName, String absFilePath) {
-        return !fileName.startsWith(CLASSNAMEEXCPREFIX);
+        return !fileName.startsWith(PREFIX);
       }
     };
     ClassFinder incClassesFinder = new ClassFinder(null, notExcNameFilter, null);
     Set<Class<?>> incClasses = incClassesFinder.findClasses(
         makePackageName("", counter), false);
     assertEquals(1, incClasses.size());
-    Class<?> incClass = makeClass("", CLASSNAME, counter);
+    Class<?> incClass = makeClass("", classNamePrefix, counter);
     assertTrue(incClasses.contains(incClass));
   }
 
   @Test
   public void testClassFinderFiltersByClassInJar() throws Exception {
-    final String CLASSNAME = "c1";
-    final String CLASSNAMEEXCPREFIX = "c2";
-    long counter = testCounter.incrementAndGet();
-    FileAndPath c1 = compileTestClass(counter, "", CLASSNAME);
-    FileAndPath c2 = compileTestClass(counter, "", CLASSNAMEEXCPREFIX + "1");
-    FileAndPath c3 = compileTestClass(counter, "", CLASSNAMEEXCPREFIX + "2");
-    packageAndLoadJar(c1, c2, c3);
+    final long counter = testCounter.incrementAndGet();
+    final String classNamePrefix = name.getMethodName();
+    Log.info("Created jar " + createAndLoadJar("", classNamePrefix, counter));
 
     final ClassFinder.ClassFilter notExcClassFilter = new ClassFinder.ClassFilter() {
       @Override
       public boolean isCandidateClass(Class<?> c) {
-        return !c.getSimpleName().startsWith(CLASSNAMEEXCPREFIX);
+        return !c.getSimpleName().startsWith(PREFIX);
       }
     };
     ClassFinder incClassesFinder = new ClassFinder(null, null, notExcClassFilter);
     Set<Class<?>> incClasses = incClassesFinder.findClasses(
         makePackageName("", counter), false);
     assertEquals(1, incClasses.size());
-    Class<?> incClass = makeClass("", CLASSNAME, counter);
+    Class<?> incClass = makeClass("", classNamePrefix, counter);
     assertTrue(incClasses.contains(incClass));
   }
 
+  private static String createAndLoadJar(final String packageNameSuffix,
+      final String classNamePrefix, final long counter)
+  throws Exception {
+    FileAndPath c1 = compileTestClass(counter, packageNameSuffix, classNamePrefix);
+    FileAndPath c2 = compileTestClass(counter, packageNameSuffix, PREFIX + "1");
+    FileAndPath c3 = compileTestClass(counter, packageNameSuffix, PREFIX + classNamePrefix
+ "2");
+    return packageAndLoadJar(c1, c2, c3);
+  }
+
   @Test
   public void testClassFinderFiltersByPathInJar() throws Exception {
-    final String CLASSNAME = "c1";
+    final String CLASSNAME = name.getMethodName();
     long counter = testCounter.incrementAndGet();
     FileAndPath c1 = compileTestClass(counter, "", CLASSNAME);
     FileAndPath c2 = compileTestClass(counter, "", "c2");
@@ -212,50 +219,74 @@ public class TestClassFinder {
 
   @Test
   public void testClassFinderCanFindClassesInDirs() throws Exception {
-    // Well, technically, we are not guaranteed that the classes will
-    // be in dirs, but during normal build they would be.
+    // Make some classes for us to find.  Class naming and packaging is kinda cryptic.
+    // TODO: Fix.
+    final long counter = testCounter.incrementAndGet();
+    final String classNamePrefix = name.getMethodName();
+    String pkgNameSuffix = name.getMethodName();
+    Log.info("Created jar " + createAndLoadJar(pkgNameSuffix, classNamePrefix, counter));
     ClassFinder allClassesFinder = new ClassFinder();
-    String pkg = this.getClass().getPackage().getName();
-    Set<Class<?>> allClasses = allClassesFinder.findClasses(pkg, false);
-    assertTrue("Classes in " + pkg, allClasses.size() > 0);
-    assertTrue(allClasses.contains(this.getClass()));
-    assertTrue(allClasses.contains(ClassFinder.class));
+    String pkgName = makePackageName(pkgNameSuffix, counter);
+    Set<Class<?>> allClasses = allClassesFinder.findClasses(pkgName, false);
+    assertTrue("Classes in " + pkgName, allClasses.size() > 0);
+    String classNameToFind = classNamePrefix + counter;
+    assertTrue(contains(allClasses, classNameToFind));
+  }
+
+  private static boolean contains(final Set<Class<?>> classes, final String simpleName)
{
+    for (Class<?> c: classes) {
+      if (c.getSimpleName().equals(simpleName)) return true;
+    }
+    return false;
   }
 
   @Test
   public void testClassFinderFiltersByNameInDirs() throws Exception {
-    final String thisName = this.getClass().getSimpleName();
+    // Make some classes for us to find.  Class naming and packaging is kinda cryptic.
+    // TODO: Fix.
+    final long counter = testCounter.incrementAndGet();
+    final String classNamePrefix = name.getMethodName();
+    String pkgNameSuffix = name.getMethodName();
+    Log.info("Created jar " + createAndLoadJar(pkgNameSuffix, classNamePrefix, counter));
+    final String classNameToFilterOut = classNamePrefix + counter;
     final ClassFinder.FileNameFilter notThisFilter = new ClassFinder.FileNameFilter() {
       @Override
       public boolean isCandidateFile(String fileName, String absFilePath) {
-        return !fileName.equals(thisName + ".class");
+        return !fileName.equals(classNameToFilterOut + ".class");
       }
     };
-    String thisPackage = this.getClass().getPackage().getName();
+    String pkgName = makePackageName(pkgNameSuffix, counter);
     ClassFinder allClassesFinder = new ClassFinder();
-    Set<Class<?>> allClasses = allClassesFinder.findClasses(thisPackage, false);
-    assertTrue("Classes in " + thisPackage, allClasses.size() > 0);
+    Set<Class<?>> allClasses = allClassesFinder.findClasses(pkgName, false);
+    assertTrue("Classes in " + pkgName, allClasses.size() > 0);
     ClassFinder notThisClassFinder = new ClassFinder(null, notThisFilter, null);
-    Set<Class<?>> notAllClasses = notThisClassFinder.findClasses(thisPackage,
false);
-    assertFalse(notAllClasses.contains(this.getClass()));
+    Set<Class<?>> notAllClasses = notThisClassFinder.findClasses(pkgName, false);
+    assertFalse(contains(notAllClasses, classNameToFilterOut));
     assertEquals(allClasses.size() - 1, notAllClasses.size());
   }
 
   @Test
   public void testClassFinderFiltersByClassInDirs() throws Exception {
+    // Make some classes for us to find.  Class naming and packaging is kinda cryptic.
+    // TODO: Fix.
+    final long counter = testCounter.incrementAndGet();
+    final String classNamePrefix = name.getMethodName();
+    String pkgNameSuffix = name.getMethodName();
+    Log.info("Created jar " + createAndLoadJar(pkgNameSuffix, classNamePrefix, counter));
+    final Class<?> clazz = makeClass(pkgNameSuffix, classNamePrefix, counter);
     final ClassFinder.ClassFilter notThisFilter = new ClassFinder.ClassFilter() {
       @Override
       public boolean isCandidateClass(Class<?> c) {
-        return c != TestClassFinder.class;
+        return c != clazz;
       }
     };
-    String thisPackage = this.getClass().getPackage().getName();
+    String pkgName = makePackageName(pkgNameSuffix, counter);
     ClassFinder allClassesFinder = new ClassFinder();
-    Set<Class<?>> allClasses = allClassesFinder.findClasses(thisPackage, false);
-    assertTrue("Classes in " + thisPackage, allClasses.size() > 0);
+    Set<Class<?>> allClasses = allClassesFinder.findClasses(pkgName, false);
+    assertTrue("Classes in " + pkgName, allClasses.size() > 0);
     ClassFinder notThisClassFinder = new ClassFinder(null, null, notThisFilter);
-    Set<Class<?>> notAllClasses = notThisClassFinder.findClasses(thisPackage,
false);
-    assertFalse(notAllClasses.contains(this.getClass()));
+    Set<Class<?>> notAllClasses = notThisClassFinder.findClasses(pkgName, false);
+    assertFalse(contains(notAllClasses, clazz.getSimpleName()));
     assertEquals(allClasses.size() - 1, notAllClasses.size());
   }
 


Mime
View raw message