aboutsummaryrefslogtreecommitdiffstats
path: root/tests/netx
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2012-05-28 11:00:49 +0200
committerJiri Vanek <[email protected]>2012-05-28 11:00:49 +0200
commit056ac3746d71b2cd92d4643f136ed28a20765227 (patch)
tree9e6bea5b5afa80b9091c6bcc745bfc71f96bf92f /tests/netx
parent1705caf0db175cb9537313e5c1d9df14186f5bea (diff)
Get rid of repeated sout/serr in reproducers testcases/unit tests and introduce bottleneck for loging.
Diffstat (limited to 'tests/netx')
-rw-r--r--tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java93
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java3
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java9
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java5
4 files changed, 100 insertions, 10 deletions
diff --git a/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java
index 0ca3a56..106f1f6 100644
--- a/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java
+++ b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java
@@ -116,6 +116,10 @@ public class ServerAccess {
* all terminated processes are stored here. As wee need to 'wait' to termination to be finished.
*/
private static Set<Thread> terminated = new HashSet<Thread>();
+ /**
+ * this flag is indicating whether output of executeProcess should be logged. By default true.
+ */
+ public static boolean PROCESS_LOG = true;
/**
* main method of this class prints out random free port
@@ -720,9 +724,87 @@ public class ServerAccess {
return executeProcess(args, dir, null, null);
}
- public static ProcessResult executeProcess(final List<String> args,File dir,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception {
+ private static String createConnectionMessage(ThreadedProcess t) {
+ return "Connecting " + t.getCommandLine();
+ }
+
+ /**
+ * Proceed message s to logging with request to reprint to System.err
+ * @param s
+ */
+ public static void logErrorReprint(String s) {
+ log(s, false, true);
+ }
+
+ /**
+ * Proceed message s to logging with request to reprint to System.out
+ * @param s
+ */
+ public static void logOutputReprint(String s) {
+ log(s, true, false);
+ }
+
+ /**
+ * Proceed message s to logging withhout request to reprint
+ * @param s
+ */
+ public static void logNoReprint(String s) {
+ log(s, false, false);
+ }
+
+ private static void log(String message, boolean printToOut, boolean printToErr) {
+ String idded;
+ StackTraceElement ste = getTestMethod();
+ String fullId = ste.getClassName() + "." + ste.getMethodName();
+ if (message.contains("\n")) {
+ idded = fullId + ": \n" + message + "\n" + fullId + " ---";
+ } else {
+ idded = fullId + ": " + message;
- ThreadedProcess t = new ThreadedProcess(args,dir);
+ }
+ if (printToOut) {
+ System.out.println(idded);
+ }
+ if (printToErr) {
+ System.err.println(idded);
+ }
+ }
+
+ private static StackTraceElement getTestMethod() {
+ return getTestMethod(Thread.currentThread().getStackTrace());
+ }
+
+ private static StackTraceElement getTestMethod(StackTraceElement[] stack) {
+ //0 is always thread
+ //1 is net.sourceforge.jnlp.ServerAccess
+ StackTraceElement result = stack[1];
+ String baseClass = stack[1].getClassName();
+ int i = 2;
+ for (; i < stack.length; i++) {
+ result = stack[i];//at least moving up
+ if (!baseClass.equals(stack[i].getClassName())) {
+ break;
+ }
+ }
+ //now we are out of net.sourceforge.jnlp.ServerAccess
+ //method we need (the test) is highest from following class
+ baseClass = stack[i].getClassName();
+ for (; i < stack.length; i++) {
+ if (!baseClass.equals(stack[i].getClassName())) {
+ break;
+ }
+ result = stack[i];
+ }
+
+ return result;
+ }
+
+ public static ProcessResult executeProcess(final List<String> args, File dir, ContentReaderListener stdoutl, ContentReaderListener stderrl) throws Exception {
+ ThreadedProcess t = new ThreadedProcess(args, dir);
+ if (PROCESS_LOG) {
+ String connectionMesaage = createConnectionMessage(t);
+ log(connectionMesaage, true, true);
+ }
ProcessAssasin pa = new ProcessAssasin(t, PROCESS_TIMEOUT);
pa.start();
t.start();
@@ -753,7 +835,12 @@ public class ServerAccess {
pa.setCanRun(false);
// System.out.println(t.getP().exitValue()); when process is killed, this throws exception
- return new ProcessResult(crs.getContent(), cre.getContent(), t.getP(), pa.wasTerminated(), t.getExitCode(), null);
+ ProcessResult pr=new ProcessResult(crs.getContent(), cre.getContent(), t.getP(), pa.wasTerminated(), t.getExitCode(), null);
+ if (PROCESS_LOG) {
+ log(pr.stdout, true, false);
+ log(pr.stderr, false, true);
+ }
+ return pr;
}
/**
diff --git a/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java b/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java
index 7a8dc92..fbc6f95 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java
@@ -40,6 +40,7 @@ package net.sourceforge.jnlp.cache;
import static org.junit.Assert.assertTrue;
import java.io.File;
+import net.sourceforge.jnlp.ServerAccess;
import net.sourceforge.jnlp.config.DeploymentConfiguration;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
@@ -90,7 +91,7 @@ public class CacheLRUWrapperTest {
}
double avg = sum / time.length;
- System.err.println("Average = " + avg + "ns");
+ ServerAccess.logErrorReprint("Average = " + avg + "ns");
// wait more than 100 microseconds for noLoops = 1000 and noEntries=1000 is bad
assertTrue("load() must not take longer than 100 µs, but took in avg " + avg/1000 + "µs", avg < 100 * 1000);
diff --git a/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java b/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java
index 2e2602a..85d323f 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java
@@ -48,6 +48,7 @@ import net.sourceforge.jnlp.LaunchException;
import net.sourceforge.jnlp.ParseException;
import net.sourceforge.jnlp.ResourcesDesc;
import net.sourceforge.jnlp.SecurityDesc;
+import net.sourceforge.jnlp.ServerAccess;
import net.sourceforge.jnlp.runtime.JNLPClassLoader;
import net.sourceforge.jnlp.runtime.JNLPClassLoader.CodeBaseClassLoader;
@@ -86,13 +87,13 @@ public class CodeBaseClassLoaderTest {
classLoader.findResource("net/sourceforge/jnlp/about/Main.class");
stopTime = System.nanoTime();
long timeOnFirstTry = stopTime - startTime;
- System.err.println(timeOnFirstTry);
+ ServerAccess.logErrorReprint(""+timeOnFirstTry);
startTime = System.nanoTime();
classLoader.findResource("net/sourceforge/jnlp/about/Main.class");
stopTime = System.nanoTime();
long timeOnSecondTry = stopTime - startTime;
- System.err.println(timeOnSecondTry);
+ ServerAccess.logErrorReprint(""+timeOnSecondTry);
assertTrue(timeOnSecondTry < (timeOnFirstTry / 10));
}
@@ -128,13 +129,13 @@ public class CodeBaseClassLoaderTest {
classLoader.findResource("net/sourceforge/jnlp/about/Main_FOO_.class");
stopTime = System.nanoTime();
long timeOnFirstTry = stopTime - startTime;
- System.err.println(timeOnFirstTry);
+ ServerAccess.logErrorReprint(""+timeOnFirstTry);
startTime = System.nanoTime();
classLoader.findResource("net/sourceforge/jnlp/about/Main_FOO_.class");
stopTime = System.nanoTime();
long timeOnSecondTry = stopTime - startTime;
- System.err.println(timeOnSecondTry);
+ ServerAccess.logErrorReprint(""+timeOnSecondTry);
assertTrue(timeOnSecondTry < (timeOnFirstTry / 10));
}
diff --git a/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java b/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java
index 5bd12d6..4771085 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java
@@ -41,6 +41,7 @@ import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
+import net.sourceforge.jnlp.ServerAccess;
import org.junit.Assert;
import org.junit.Test;
@@ -72,13 +73,13 @@ public class BASE64EncoderTest {
// sun.misc.BASE64Encoder e1 = new sun.misc.BASE64Encoder();
// e1.encode(data, out1);
// byte[] encoded1 = out1.toByteArray();
-// System.out.println(Arrays.toString(encoded1));
+// ServerAccess.logErrorReprint(Arrays.toString(encoded1));
ByteArrayOutputStream out2 = new ByteArrayOutputStream();
BASE64Encoder e2 = new BASE64Encoder();
e2.encodeBuffer(data, out2);
byte[] encoded2 = out2.toByteArray();
Assert.assertArrayEquals(encoded, encoded2);
-// System.out.println(Arrays.toString(encoded2));
+// ServerAccess.logErrorReprint(Arrays.toString(encoded2));