Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made handling of test results concurrent

  • Loading branch information...
commit 43aae7a72b563135624d36a1bea85fcfa562fc1a 1 parent 3c541e9
@belaban authored
Showing with 26 additions and 17 deletions.
  1. +26 −17 src/org/jgroups/util/JUnitXMLReporter.java
View
43 src/org/jgroups/util/JUnitXMLReporter.java
@@ -12,6 +12,7 @@
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
/**
@@ -35,11 +36,14 @@
private PrintStream old_stdout=System.out;
private PrintStream old_stderr=System.err;
- private final ConcurrentMap<Class<?>,List<ITestResult>> classes=new ConcurrentHashMap<Class<?>,List<ITestResult>>();
+ private final ConcurrentMap<Class<?>,Collection<ITestResult>> classes=new ConcurrentHashMap<Class<?>,Collection<ITestResult>>();
/** Map to keep systemout and systemerr associated with a class */
private final ConcurrentMap<Class<?>,Tuple<StringBuffer,StringBuffer>> outputs=new ConcurrentHashMap<Class<?>,Tuple<StringBuffer,StringBuffer>>();
+ // Keeps track of already gnerated reports, so we don't generate the same report multiple times
+ protected final Set<Class<?>> generated_reports=new HashSet<Class<?>>();
+
public static InheritableThreadLocal<Class<?>> local=new InheritableThreadLocal<Class<?>>();
class MyOutput extends PrintStream {
@@ -116,10 +120,10 @@ public void beforeInvocation(IInvokedMethod method, ITestResult tr) {
local.set(real_class);
- List<ITestResult> results=classes.get(real_class);
+ Collection<ITestResult> results=classes.get(real_class);
if(results == null) {
results=new LinkedList<ITestResult>();
- classes.putIfAbsent(real_class, results);
+ classes.putIfAbsent(real_class,results);
}
outputs.putIfAbsent(real_class, new Tuple<StringBuffer,StringBuffer>(new StringBuffer(), new StringBuffer())) ;
@@ -177,21 +181,26 @@ private static void print(PrintStream out, String msg, String classname, String
}
private void addTest(Class<?> clazz, ITestResult result) {
- List<ITestResult> results=classes.get(clazz);
+ Collection<ITestResult> results=classes.get(clazz);
if(results == null) {
- results=new LinkedList<ITestResult>();
- classes.putIfAbsent(clazz, results);
+ results=new ConcurrentLinkedQueue<ITestResult>();
+ Collection<ITestResult> tmp=classes.putIfAbsent(clazz,results);
+ if(tmp != null)
+ results=tmp;
}
-
- results=classes.get(clazz);
results.add(result);
ITestNGMethod[] testMethods=result.getMethod().getTestClass().getTestMethods();
int enabledCount = enabledMethods(testMethods);
boolean allTestsInClassCompleted = results.size() >= enabledCount;
- if(allTestsInClassCompleted){
+ if(allTestsInClassCompleted) {
+ boolean do_generate=false;
+ synchronized(generated_reports) {
+ do_generate=generated_reports.add(clazz);
+ }
try {
- generateReport(clazz, results);
+ if(do_generate)
+ generateReport(clazz, results);
}
catch(IOException e) {
print(old_stderr, "Failed generating report: ", clazz.getName(), "");
@@ -199,7 +208,7 @@ private void addTest(Class<?> clazz, ITestResult result) {
}
}
- private int enabledMethods(ITestNGMethod[] testMethods) {
+ private static int enabledMethods(ITestNGMethod[] testMethods) {
int count = testMethods.length;
for(ITestNGMethod testNGMethod:testMethods) {
Method m = testNGMethod.getMethod();
@@ -248,7 +257,7 @@ public void onFinish(ITestContext context) {
/**
* generate the XML report given what we know from all the test results
*/
- protected void generateReport(Class<?> clazz, List<ITestResult> results) throws IOException {
+ protected void generateReport(Class<?> clazz, Collection<ITestResult> results) throws IOException {
int num_failures=getFailures(results);
int num_skips=getSkips(results);
@@ -287,7 +296,7 @@ protected void generateReport(Class<?> clazz, List<ITestResult> results) throws
}
out.write("\n</properties>\n");
- for(ITestResult result:results) {
+ for(ITestResult result: results) {
if(result == null)
continue;
long time=result.getEndMillis() - result.getStartMillis();
@@ -394,7 +403,7 @@ private static String escape(String message) {
return message != null? message.replaceAll("<", LT).replaceAll(">", GT) : message;
}
- private static long getTotalTime(List<ITestResult> results) {
+ private static long getTotalTime(Collection<ITestResult> results) {
long start=0, stop=0;
for(ITestResult result:results) {
if(result == null)
@@ -415,7 +424,7 @@ private static long getTotalTime(List<ITestResult> results) {
return stop - start;
}
- private static int getFailures(List<ITestResult> results) {
+ private static int getFailures(Collection<ITestResult> results) {
int retval=0;
for(ITestResult result:results) {
if(result != null && result.getStatus() == ITestResult.FAILURE)
@@ -424,7 +433,7 @@ private static int getFailures(List<ITestResult> results) {
return retval;
}
- private static int getErrors(List<ITestResult> results) {
+ private static int getErrors(Collection<ITestResult> results) {
int retval=0;
for(ITestResult result:results) {
if(result != null && result.getStatus() != ITestResult.SUCCESS
@@ -435,7 +444,7 @@ private static int getErrors(List<ITestResult> results) {
return retval;
}
- private static int getSkips(List<ITestResult> results) {
+ private static int getSkips(Collection<ITestResult> results) {
int retval=0;
for(ITestResult result:results) {
if(result != null && result.getStatus() == ITestResult.SKIP)
Please sign in to comment.
Something went wrong with that request. Please try again.