[infinispan-commits] Infinispan SVN: r600 - in trunk: core/src/main/java/org/infinispan/remoting/rpc and 9 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue Jul 21 10:29:25 EDT 2009


Author: manik.surtani at jboss.com
Date: 2009-07-21 10:29:24 -0400 (Tue, 21 Jul 2009)
New Revision: 600

Added:
   trunk/tools/src/test/
   trunk/tools/src/test/java/
   trunk/tools/src/test/java/org/
   trunk/tools/src/test/java/org/infinispan/
   trunk/tools/src/test/java/org/infinispan/test/
   trunk/tools/src/test/java/org/infinispan/test/fwk/
   trunk/tools/src/test/java/org/infinispan/test/fwk/TestNameVerifier.java
Removed:
   trunk/core/src/test/java/org/infinispan/test/fwk/TestNameVerifier.java
Modified:
   trunk/core/src/main/java/org/infinispan/interceptors/TxInterceptor.java
   trunk/core/src/main/java/org/infinispan/remoting/rpc/RpcManagerImpl.java
   trunk/tools/src/main/java/org/infinispan/tools/doclet/jmx/JmxDoclet.java
Log:
ISPN-101 ( Move test name verifier from the core module to the tools module )

Modified: trunk/core/src/main/java/org/infinispan/interceptors/TxInterceptor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/interceptors/TxInterceptor.java	2009-07-21 14:26:19 UTC (rev 599)
+++ trunk/core/src/main/java/org/infinispan/interceptors/TxInterceptor.java	2009-07-21 14:29:24 UTC (rev 600)
@@ -223,6 +223,10 @@
       this.statsEnabled = enabled;
    }
 
+   public boolean isStatisticsEnabled() {
+      return this.statsEnabled;
+   }
+
    @ManagedAttribute(description = "number of transaction prepares")
    public long getPrepares() {
       return prepares.get();

Modified: trunk/core/src/main/java/org/infinispan/remoting/rpc/RpcManagerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/remoting/rpc/RpcManagerImpl.java	2009-07-21 14:26:19 UTC (rev 599)
+++ trunk/core/src/main/java/org/infinispan/remoting/rpc/RpcManagerImpl.java	2009-07-21 14:29:24 UTC (rev 600)
@@ -47,6 +47,7 @@
    private Transport t;
    private final AtomicLong replicationCount = new AtomicLong(0);
    private final AtomicLong replicationFailures = new AtomicLong(0);
+   @ManagedAttribute(name = "StatisticsEnabled", description = "Enables or disables the gathering of statistics by this component", writable = true)
    boolean statisticsEnabled = false; // by default, don't gather statistics.
    private volatile Address currentStateTransferSource;
    private boolean stateTransferEnabled;
@@ -209,9 +210,9 @@
             rpc = cf.buildSingleRpcCommand(rpc);
          }
          List rsps;
-            rsps = invokeRemotely(recipients, rpc, getResponseMode(sync), timeout, usePriorityQueue);
-            if (trace) log.trace("responses=" + rsps);
-            if (sync) checkResponses(rsps);
+         rsps = invokeRemotely(recipients, rpc, getResponseMode(sync), timeout, usePriorityQueue);
+         if (trace) log.trace("responses=" + rsps);
+         if (sync) checkResponses(rsps);
       }
    }
 
@@ -288,7 +289,6 @@
       return String.valueOf(replicationFailures.get());
    }
 
-   @ManagedAttribute(name = "StatisticsEnabled", description = "Enables or disables the gathering of statistics by this component", writable = true)   
    public boolean isStatisticsEnabled() {
       return statisticsEnabled;
    }

Deleted: trunk/core/src/test/java/org/infinispan/test/fwk/TestNameVerifier.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/fwk/TestNameVerifier.java	2009-07-21 14:26:19 UTC (rev 599)
+++ trunk/core/src/test/java/org/infinispan/test/fwk/TestNameVerifier.java	2009-07-21 14:29:24 UTC (rev 600)
@@ -1,219 +0,0 @@
-package org.infinispan.test.fwk;
-
-import org.testng.annotations.Test;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileReader;
-import java.io.FilenameFilter;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Class that tests that test names are correclty set for each test.
- *
- * @author Mircea.Markus at jboss.com
- */
- at Test(groups = "functional", testName = "test.fwk.TestNameVerifier")
-public class TestNameVerifier {
-   String dir = "src/test/java/org/infinispan";
-   public List<String> modules = new ArrayList<String>();
-
-
-   Pattern packageLinePattern = Pattern.compile("package org.infinispan[^;]*");
-   Pattern classLinePattern = Pattern.compile("(abstract\\s*)??(public\\s*)(abstract\\s*)??class [^\\s]*");
-   Pattern atAnnotationPattern = Pattern.compile("@Test[^)]*");
-   Pattern testNamePattern = Pattern.compile("testName\\s*=\\s*\"[^\"]*\"");
-
-   String fileCache;
-
-   FilenameFilter javaFilter = new FilenameFilter() {
-      public boolean accept(File dir, String name) {
-         if (dir.getAbsolutePath().contains("testng")) return false;
-         return name.endsWith(".java");
-      }
-   };
-
-   FileFilter onlyDirs = new FileFilter() {
-      public boolean accept(File pathname) {
-         return pathname.isDirectory();
-      }
-   };
-
-   @Test(enabled = false, description = "Do not enable this unless you want your files to be updated with test names!!!")
-   public void process() throws Exception {
-      File[] javaFiles = getAllJavaFiles();
-      for (File file : javaFiles) {
-         if (needsUpdate(file)) {
-            System.out.println("Updating file: " + file.getAbsolutePath());
-            updateFile(file);
-         }
-      }
-   }
-
-   private void updateFile(File file) throws Exception {
-      String javaString = fileCache;
-      String testName = getTestName(javaString, file.getName());
-      String testNameStr = ", testName = \"" + testName + "\"";
-      javaString = replaceAtTestAnnotation(javaString, testNameStr);
-      persistNewFile(file, javaString);
-   }
-
-   private void persistNewFile(File file, String javaString) throws Exception {
-      if (file.delete()) {
-         System.out.println("!!!!!!!!!! error porcessing file " + file.getName());
-         return;
-      }
-      file.createNewFile();
-      PrintWriter writter = new PrintWriter(file);
-      writter.append(javaString);
-      writter.close();
-   }
-
-   private String replaceAtTestAnnotation(String javaString, String testNameStr) {
-      Matcher matcher = atAnnotationPattern.matcher(javaString);
-      boolean found = matcher.find();
-      assert found;
-      String theMatch = matcher.group();
-      return matcher.replaceFirst(theMatch + testNameStr);
-   }
-
-   private String getTestName(String javaString, String filename) {
-      String classNamePart = getClassNamePart(javaString, filename);
-
-      //abstract classes do not require test names
-      if (classNamePart.indexOf("abstract") >= 0) return null;
-
-      classNamePart = classNamePart.substring("public class ".length());
-      String packagePart = getPackagePart(javaString, filename);
-      //if the test is in org.infinispan package then make sure no . is prepanded
-      String packagePrepend = ((packagePart != null) && (packagePart.length() > 0)) ? packagePart + "." : "";
-      return packagePrepend + classNamePart;
-   }
-
-   private String getClassNamePart(String javaString, String filename) {
-      Matcher matcher = classLinePattern.matcher(javaString);
-      boolean found = matcher.find();
-      assert found : "could not determine class name for file: " + filename;
-      return matcher.group();
-   }
-
-   private String getPackagePart(String javaString, String filename) {
-      Matcher matcher = packageLinePattern.matcher(javaString);
-      boolean found = matcher.find();
-      assert found : "Could not determine package name for file: " + filename;
-      String theMatch = matcher.group();
-      String partial = theMatch.substring("package org.infinispan".length());
-      if (partial.trim().length() == 0) return partial.trim();
-      return partial.substring(1);//drop the leading dot.
-   }
-
-
-   private boolean needsUpdate(File file) throws Exception {
-      String javaFileStr = getFileAsString(file);
-      if (javaFileStr.indexOf(" testName = \"") > 0) return false;
-      int atTestIndex = javaFileStr.indexOf("@Test");
-      int classDeclarationIndex = javaFileStr.indexOf("public class");
-      return atTestIndex > 0 && atTestIndex < classDeclarationIndex;
-   }
-
-   private String getFileAsString(File file) throws Exception {
-      StringBuilder builder = new StringBuilder();
-      BufferedReader fileReader = new BufferedReader(new FileReader(file));
-      String line;
-      while ((line = fileReader.readLine()) != null) {
-         builder.append(line + "\n");
-      }
-      this.fileCache = builder.toString();
-      return fileCache;
-   }
-
-   // Loop through the list of module names and pass it to the getFilesFromModule()
-   private File[] getAllJavaFiles() {
-      populateModuleList();
-      List<File> listOfFiles = new ArrayList<File>();
-      for (String module : modules) {
-         // Take in the list from the getFilesFromModule() and add it to the collection here to be converted into an
-         // array and then returned.
-         listOfFiles.addAll(getFilesFromModule(module));
-      }
-      return listOfFiles.toArray(new File[listOfFiles.size()]);
-   }
-
-   private void addJavaFiles(File file, ArrayList<File> result) {
-      assert file.isDirectory();
-      File[] javaFiles = file.listFiles(javaFilter);
-//      printFiles(javaFiles);
-      result.addAll(Arrays.asList(javaFiles));
-      for (File dir : file.listFiles(onlyDirs)) {
-         addJavaFiles(dir, result);
-      }
-   }
-
-   private void printFiles(File[] javaFiles) {
-      for (File f : javaFiles) {
-         System.out.println(f.getAbsolutePath());
-      }
-   }
-
-   public void verifyTestName() throws Exception {
-      File[] javaFiles = getAllJavaFiles();
-      StringBuilder errorMessage = new StringBuilder("Following test class(es) do not have an appropriate test name: \n");
-      boolean hasErrors = false;
-      for (File file : javaFiles) {
-         String expectedName = incorrectTestName(file);
-         if (expectedName != null) {
-            errorMessage.append(file.getAbsoluteFile()).append(" expected test name is: '").append(expectedName).append("' \n");
-            hasErrors = true;
-         }
-      }
-      assert !hasErrors : errorMessage.append("The rules for writting UTs are being descibed here: https://www.jboss.org/community/docs/DOC-13315");
-   }
-
-   private String incorrectTestName(File file) throws Exception {
-      String fileAsStr = getFileAsString(file);
-
-      boolean containsTestAnnotation = atAnnotationPattern.matcher(fileAsStr).find();
-      if (!containsTestAnnotation) return null;
-
-      String expectedTestName = getTestName(fileAsStr, file.getName());
-      if (expectedTestName == null) return null; //this happens when the class is abstract
-      Matcher matcher = this.testNamePattern.matcher(fileAsStr);
-      if (!matcher.find()) return expectedTestName;
-      String name = matcher.group().trim();
-      int firstIndexOfQuote = name.indexOf('"');
-      String existingTestName = name.substring(firstIndexOfQuote + 1, name.length() - 1); //to ignore last quote
-      if (!existingTestName.equals(expectedTestName)) return expectedTestName;
-      return null;
-   }
-
-   // method that populates the list of module names
-   private void populateModuleList() {
-      modules.add("core");
-      modules.add("cachestore/s3");
-      modules.add("cachestore/bdbje");
-      modules.add("cachestore/jdbc");
-      modules.add("cachestore/jdbm");
-      modules.add("jopr-plugin");
-      modules.add("tree");
-   }
-
-   // Old method that Mircea wrote that originally returned an array. Now returns a list and will be added to the list in getAllJavaFiles()
-   private List<File> getFilesFromModule(String moduleName) {
-      File file = new File(dir);
-      if (!file.exists()) {
-         // try prepending dir with module name
-         file = new File(moduleName + File.separator + dir);
-      }
-      assert file.isDirectory();
-      ArrayList<File> result = new ArrayList<File>();
-      addJavaFiles(file, result);
-      return result;
-
-   }
-}
\ No newline at end of file

Modified: trunk/tools/src/main/java/org/infinispan/tools/doclet/jmx/JmxDoclet.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/doclet/jmx/JmxDoclet.java	2009-07-21 14:26:19 UTC (rev 599)
+++ trunk/tools/src/main/java/org/infinispan/tools/doclet/jmx/JmxDoclet.java	2009-07-21 14:29:24 UTC (rev 600)
@@ -133,8 +133,10 @@
 
       // and field level annotations
       for (FieldDoc field : cd.fields(false)) {
+
          for (AnnotationDesc a : field.annotations()) {
             String annotationName = a.annotationType().qualifiedTypeName();
+
             if (annotationName.equals(ManagedAttribute.class.getName())) {
                isMBean = true;
                MBeanAttribute attr = new MBeanAttribute();
@@ -150,6 +152,7 @@
       if (isMBean) {
          Collections.sort(mbc.attributes);
          Collections.sort(mbc.operations);
+
          return mbc;
       } else {
          return null;

Added: trunk/tools/src/test/java/org/infinispan/test/fwk/TestNameVerifier.java
===================================================================
--- trunk/tools/src/test/java/org/infinispan/test/fwk/TestNameVerifier.java	                        (rev 0)
+++ trunk/tools/src/test/java/org/infinispan/test/fwk/TestNameVerifier.java	2009-07-21 14:29:24 UTC (rev 600)
@@ -0,0 +1,231 @@
+package org.infinispan.test.fwk;
+
+import org.testng.annotations.Test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileReader;
+import java.io.FilenameFilter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Class that tests that test names are correclty set for each test.
+ *
+ * @author Mircea.Markus at jboss.com
+ */
+ at Test(groups = "functional", testName = "test.fwk.TestNameVerifier")
+public class TestNameVerifier {
+   String dir = "src/test/java/org/infinispan";
+   public List<String> modules = new ArrayList<String>();
+
+
+   Pattern packageLinePattern = Pattern.compile("package org.infinispan[^;]*");
+   Pattern classLinePattern = Pattern.compile("(abstract\\s*)??(public\\s*)(abstract\\s*)??class [^\\s]*");
+   Pattern atAnnotationPattern = Pattern.compile("@Test[^)]*");
+   Pattern testNamePattern = Pattern.compile("testName\\s*=\\s*\"[^\"]*\"");
+
+   String fileCache;
+
+   FilenameFilter javaFilter = new FilenameFilter() {
+      public boolean accept(File dir, String name) {
+         if (dir.getAbsolutePath().contains("testng")) return false;
+         return name.endsWith(".java");
+      }
+   };
+
+   FileFilter onlyDirs = new FileFilter() {
+      public boolean accept(File pathname) {
+         return pathname.isDirectory();
+      }
+   };
+
+   @Test(enabled = false, description = "Do not enable this unless you want your files to be updated with test names!!!")
+   public void process() throws Exception {
+      File[] javaFiles = getAllJavaFiles();
+      for (File file : javaFiles) {
+         if (needsUpdate(file)) {
+            System.out.println("Updating file: " + file.getAbsolutePath());
+            updateFile(file);
+         }
+      }
+   }
+
+   private void updateFile(File file) throws Exception {
+      String javaString = fileCache;
+      String testName = getTestName(javaString, file.getName());
+      String testNameStr = ", testName = \"" + testName + "\"";
+      javaString = replaceAtTestAnnotation(javaString, testNameStr);
+      persistNewFile(file, javaString);
+   }
+
+   private void persistNewFile(File file, String javaString) throws Exception {
+      if (file.delete()) {
+         System.out.println("!!!!!!!!!! error porcessing file " + file.getName());
+         return;
+      }
+      file.createNewFile();
+      PrintWriter writter = new PrintWriter(file);
+      writter.append(javaString);
+      writter.close();
+   }
+
+   private String replaceAtTestAnnotation(String javaString, String testNameStr) {
+      Matcher matcher = atAnnotationPattern.matcher(javaString);
+      boolean found = matcher.find();
+      assert found;
+      String theMatch = matcher.group();
+      return matcher.replaceFirst(theMatch + testNameStr);
+   }
+
+   private String getTestName(String javaString, String filename) {
+      String classNamePart = getClassNamePart(javaString, filename);
+
+      //abstract classes do not require test names
+      if (classNamePart.indexOf("abstract") >= 0) return null;
+
+      classNamePart = classNamePart.substring("public class ".length());
+      String packagePart = getPackagePart(javaString, filename);
+      //if the test is in org.infinispan package then make sure no . is prepanded
+      String packagePrepend = ((packagePart != null) && (packagePart.length() > 0)) ? packagePart + "." : "";
+      return packagePrepend + classNamePart;
+   }
+
+   private String getClassNamePart(String javaString, String filename) {
+      Matcher matcher = classLinePattern.matcher(javaString);
+      boolean found = matcher.find();
+      assert found : "could not determine class name for file: " + filename;
+      return matcher.group();
+   }
+
+   private String getPackagePart(String javaString, String filename) {
+      Matcher matcher = packageLinePattern.matcher(javaString);
+      boolean found = matcher.find();
+      assert found : "Could not determine package name for file: " + filename;
+      String theMatch = matcher.group();
+      String partial = theMatch.substring("package org.infinispan".length());
+      if (partial.trim().length() == 0) return partial.trim();
+      return partial.substring(1);//drop the leading dot.
+   }
+
+
+   private boolean needsUpdate(File file) throws Exception {
+      String javaFileStr = getFileAsString(file);
+      if (javaFileStr.indexOf(" testName = \"") > 0) return false;
+      int atTestIndex = javaFileStr.indexOf("@Test");
+      int classDeclarationIndex = javaFileStr.indexOf("public class");
+      return atTestIndex > 0 && atTestIndex < classDeclarationIndex;
+   }
+
+   private String getFileAsString(File file) throws Exception {
+      StringBuilder builder = new StringBuilder();
+      BufferedReader fileReader = new BufferedReader(new FileReader(file));
+      String line;
+      while ((line = fileReader.readLine()) != null) {
+         builder.append(line + "\n");
+      }
+      this.fileCache = builder.toString();
+      return fileCache;
+   }
+
+   // Loop through the list of module names and pass it to the getFilesFromModule()
+   private File[] getAllJavaFiles() {
+      populateModuleList();
+      List<File> listOfFiles = new ArrayList<File>();
+      for (String module : modules) {
+         // Take in the list from the getFilesFromModule() and add it to the collection here to be converted into an
+         // array and then returned.
+         listOfFiles.addAll(getFilesFromModule(module));
+      }
+      return listOfFiles.toArray(new File[listOfFiles.size()]);
+   }
+
+   private void addJavaFiles(File file, ArrayList<File> result) {
+      assert file.isDirectory();
+      File[] javaFiles = file.listFiles(javaFilter);
+//      printFiles(javaFiles);
+      result.addAll(Arrays.asList(javaFiles));
+      for (File dir : file.listFiles(onlyDirs)) {
+         addJavaFiles(dir, result);
+      }
+   }
+
+   private void printFiles(File[] javaFiles) {
+      for (File f : javaFiles) {
+         System.out.println(f.getAbsolutePath());
+      }
+   }
+
+   public void verifyTestName() throws Exception {
+      File[] javaFiles = getAllJavaFiles();
+      StringBuilder errorMessage = new StringBuilder("Following test class(es) do not have an appropriate test names: \n");
+      boolean hasErrors = false;
+      for (File file : javaFiles) {
+         String expectedName = incorrectTestName(file);
+         if (expectedName != null) {
+            errorMessage.append(file.getAbsoluteFile()).append(" (Expected test name '").append(expectedName).append("', was '").append(existingTestName(file)).append("'\n");
+            hasErrors = true;
+         }
+      }
+      assert !hasErrors : errorMessage.append("The rules for writing unit tests are described on http://www.jboss.org/community/wiki/ParallelTestSuite");
+   }
+
+   private String incorrectTestName(File file) throws Exception {
+      String fileAsStr = getFileAsString(file);
+
+      boolean containsTestAnnotation = atAnnotationPattern.matcher(fileAsStr).find();
+      if (!containsTestAnnotation) return null;
+
+      String expectedTestName = getTestName(fileAsStr, file.getName());
+      if (expectedTestName == null) return null; //this happens when the class is abstract
+
+      String existingTestName = existingTestName(file);
+      if (existingTestName == null || !existingTestName.equals(expectedTestName)) return expectedTestName;
+      return null;
+   }
+
+   private String existingTestName(File file) throws Exception {
+      String fileAsStr = getFileAsString(file);
+
+      boolean containsTestAnnotation = atAnnotationPattern.matcher(fileAsStr).find();
+      if (!containsTestAnnotation) return null;
+
+      String expectedTestName = getTestName(fileAsStr, file.getName());
+      if (expectedTestName == null) return null; //this happens when the class is abstract
+      Matcher matcher = this.testNamePattern.matcher(fileAsStr);
+      if (!matcher.find()) return expectedTestName;
+      String name = matcher.group().trim();
+      int firstIndexOfQuote = name.indexOf('"');
+      return name.substring(firstIndexOfQuote + 1, name.length() - 1);
+   }
+
+   // method that populates the list of module names
+   private void populateModuleList() {
+      modules.add("core");
+      modules.add("cachestore/s3");
+      modules.add("cachestore/bdbje");
+      modules.add("cachestore/jdbc");
+      modules.add("cachestore/jdbm");
+      modules.add("jopr-plugin");
+      modules.add("tree");
+   }
+
+   // Old method that Mircea wrote that originally returned an array. Now returns a list and will be added to the list in getAllJavaFiles()
+   private List<File> getFilesFromModule(String moduleName) {
+      File file = new File(dir);
+      if (!file.exists()) {
+         // try prepending dir with module name
+         file = new File(moduleName + File.separator + dir);
+      }
+      assert file.isDirectory();
+      ArrayList<File> result = new ArrayList<File>();
+      addJavaFiles(file, result);
+      return result;
+
+   }
+}
\ No newline at end of file


Property changes on: trunk/tools/src/test/java/org/infinispan/test/fwk/TestNameVerifier.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF



More information about the infinispan-commits mailing list