Permalink
Browse files

Estimate persistent daemon: run the suite multiple times (must build …

…with "mvn clean install -DskipITs")
  • Loading branch information...
luontola committed Feb 9, 2013
1 parent f6e818c commit 9c8e64f2995031179216171e49b2eb40d65c1c42
@@ -17,7 +17,7 @@
import fi.jumi.core.util.*;
import javax.annotation.concurrent.NotThreadSafe;
import java.io.PrintStream;
import java.io.*;
import java.net.*;
import java.nio.file.*;
import java.util.*;
@@ -34,7 +34,7 @@
private ExecutorService actorThreadPool;
ExecutorService testThreadPool;
ClassLoader testClassLoader;
URLClassLoader testClassLoader;
private TestFileFinder testFileFinder;
private CompositeDriverFinder driverFinder;
private RunIdSequence runIdSequence;
@@ -109,9 +109,16 @@ public void close() {
if (testThreadPool != null) {
testThreadPool.shutdownNow();
}
if (testClassLoader != null) {
try {
testClassLoader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static ClassLoader createClassLoader(List<URI> classpath) {
private static URLClassLoader createClassLoader(List<URI> classpath) {
try {
return new URLClassLoader(asUrls(classpath));
} catch (MalformedURLException e) {
@@ -12,6 +12,7 @@
import org.junit.*;
import java.io.PrintStream;
import java.net.URLClassLoader;
import java.util.concurrent.*;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -49,7 +50,7 @@ public void run() {
spy.add(Thread.currentThread().getContextClassLoader());
}
});
ClassLoader contextClassLoader = spy.take();
URLClassLoader contextClassLoader = (URLClassLoader) spy.take();
assertThat(contextClassLoader, is(factory.testClassLoader));
}
@@ -10,6 +10,7 @@
import fi.jumi.core.api.SuiteListener;
import fi.jumi.core.config.SuiteConfiguration;
import fi.jumi.core.events.SuiteListenerEventizer;
import fi.jumi.core.events.suiteListener.OnSuiteFinishedEvent;
import fi.jumi.core.network.*;
import fi.jumi.core.suite.SuiteFactory;
import fi.jumi.core.util.timeout.*;
@@ -50,9 +51,48 @@ public void onMessage(Event<CommandListener> message) {
message.fireOn(this);
}
private int iterations = 0;
@Override
public void runTests(SuiteConfiguration suite) {
SuiteListener suiteListener = new SuiteListenerEventizer().newFrontend(sender);
public void runTests(final SuiteConfiguration suite) {
final long start = System.currentTimeMillis();
SuiteListener suiteListener = new SuiteListenerEventizer().newFrontend(new MessageSender<Event<SuiteListener>>() {
@Override
public void send(Event<SuiteListener> message) {
// don't end the suite until we have done enough iterations
if (message.getClass() != OnSuiteFinishedEvent.class) {
sender.send(message);
return;
}
long end = System.currentTimeMillis();
long duration = end - start;
System.out.println(iterations + ": took " + duration + " ms");
iterations++;
if (iterations < 11) {
new Thread(new Runnable() {
@Override
public void run() {
// release resources
suiteFactory.close();
try {
// must be done in a new thread, because else the above call would interrupt this
Thread.sleep(5000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// restart suite
runTests(suite);
}
}).start();
} else {
sender.send(message); // last iteration, end the suite
}
}
});
suiteFactory.configure(suite);
suiteFactory.start(suiteListener);
}

0 comments on commit 9c8e64f

Please sign in to comment.