use of org.junit.runner.notification.RunListener in project camel by apache.
the class UnitTestCommand method executeTest.
@Override
public UnitTestResult executeTest(final ITestConfig config, String component) throws Exception {
logger.info("Spring-Boot test configuration {}", config);
Pattern pattern = Pattern.compile(config.getUnitTestInclusionPattern());
logger.info("Scaning the classpath for test classes");
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new RegexPatternTypeFilter(pattern));
Set<BeanDefinition> defs = scanner.findCandidateComponents(config.getUnitTestBasePackage());
List<String> testClasses = new LinkedList<>();
for (BeanDefinition bd : defs) {
testClasses.add(bd.getBeanClassName());
}
if (config.getUnitTestExclusionPattern() != null) {
Pattern exclusionPattern = Pattern.compile(config.getUnitTestExclusionPattern());
for (Iterator<String> it = testClasses.iterator(); it.hasNext(); ) {
String cn = it.next();
if (exclusionPattern.matcher(cn).matches()) {
logger.warn("Excluding Test Class: {}", cn);
it.remove();
}
}
}
final List<Class<?>> classes = new ArrayList<>();
for (String cn : testClasses) {
try {
Class<?> clazz = Class.forName(cn);
if (isAdmissible(clazz)) {
logger.info("Found admissible test class: {}", cn);
classes.add(clazz);
}
} catch (Throwable t) {
logger.warn("Test class {} has thrown an exception during initialization", cn);
logger.debug("Exception for test cass " + cn + " is:", t);
}
}
logger.info("Run JUnit tests on {} test classes", classes.size());
JUnitCore runner = new JUnitCore();
runner.addListener(new RunListener() {
@Override
public void testStarted(Description description) throws Exception {
disableJmx(config.getJmxDisabledNames());
}
});
Result result = runner.run(classes.toArray(new Class[] {}));
logger.info(config.getModuleName() + " unit tests. " + "Success: " + result.wasSuccessful() + " - Test Run: " + result.getRunCount() + " - Failures: " + result.getFailureCount() + " - Ignored Tests: " + result.getIgnoreCount());
for (Failure f : result.getFailures()) {
logger.warn("Failed test description: {}", f.getDescription());
logger.warn("Message: {}", f.getMessage());
if (f.getException() != null) {
logger.warn("Exception thrown from test", f.getException());
}
}
if (!result.wasSuccessful()) {
Assert.fail("Some unit tests failed (" + result.getFailureCount() + "/" + result.getRunCount() + "), check the logs for more details");
}
if (result.getRunCount() == 0 && config.getUnitTestsExpectedNumber() == null) {
Assert.fail("No tests have been found");
}
Integer expectedTests = config.getUnitTestsExpectedNumber();
if (expectedTests != null && expectedTests != result.getRunCount()) {
Assert.fail("Wrong number of tests: expected " + expectedTests + " found " + result.getRunCount());
}
return new UnitTestResult(result);
}
use of org.junit.runner.notification.RunListener in project undertow by undertow-io.
the class DefaultServer method run.
@Override
public void run(final RunNotifier notifier) {
notifier.addListener(new RunListener() {
@Override
public void testStarted(Description description) throws Exception {
DebuggingSlicePool.currentLabel = description.getClassName() + "." + description.getMethodName();
super.testStarted(description);
}
@Override
public void testFinished(Description description) throws Exception {
if (!DebuggingSlicePool.BUFFERS.isEmpty()) {
try {
Thread.sleep(200);
if (!DebuggingSlicePool.BUFFERS.isEmpty()) {
Thread.sleep(2000);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
for (DebuggingSlicePool.DebuggingBuffer b : DebuggingSlicePool.BUFFERS) {
b.getAllocationPoint().printStackTrace();
notifier.fireTestFailure(new Failure(description, new RuntimeException("Buffer Leak " + b.getLabel(), b.getAllocationPoint())));
}
DebuggingSlicePool.BUFFERS.clear();
}
super.testFinished(description);
}
});
runInternal(notifier);
super.run(notifier);
}
use of org.junit.runner.notification.RunListener in project undertow by undertow-io.
the class DefaultServer method runInternal.
private static void runInternal(final RunNotifier notifier) {
if (openssl && OPENSSL_FAILURE != null) {
throw new RuntimeException(OPENSSL_FAILURE);
}
if (first) {
first = false;
xnio = Xnio.getInstance("nio", DefaultServer.class.getClassLoader());
try {
worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_IO_THREADS, 8).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 30).set(Options.WORKER_TASK_MAX_THREADS, 30).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.BACKLOG, 1000).set(Options.REUSE_ADDRESSES, true).set(Options.BALANCING_TOKENS, 1).set(Options.BALANCING_CONNECTIONS, 2).getMap();
final SSLContext serverContext = createSSLContext(loadKeyStore(SERVER_KEY_STORE), loadKeyStore(SERVER_TRUST_STORE), false);
UndertowXnioSsl ssl = new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, SSL_BUFFER_POOL, serverContext);
if (ajp) {
openListener = new AjpOpenListener(pool);
acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
if (apache) {
int port = 8888;
server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), port), acceptListener, serverOptions);
} else {
server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), 7777 + PROXY_OFFSET), acceptListener, serverOptions);
proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
proxyOpenListener.setRootHandler(new ProxyHandler(loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("ajp", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null)), 120000, HANDLE_404));
proxyServer.resumeAccepts();
}
} else if (h2 && isAlpnEnabled()) {
openListener = new Http2OpenListener(pool, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true, UndertowOptions.HTTP2_PADDING_SIZE, 10));
acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(new AlpnOpenListener(pool).addProtocol(Http2OpenListener.HTTP2, (io.undertow.server.DelegateOpenListener) openListener, 10)));
SSLContext clientContext = createSSLContext(loadKeyStore(CLIENT_KEY_STORE), loadKeyStore(CLIENT_TRUST_STORE), true);
server = ssl.createSslConnectionServer(worker, new InetSocketAddress(getHostAddress("default"), 7777 + PROXY_OFFSET), acceptListener, serverOptions);
server.resumeAccepts();
proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
ProxyHandler proxyHandler = new ProxyHandler(loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("h2", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null), null, new UndertowXnioSsl(xnio, OptionMap.EMPTY, SSL_BUFFER_POOL, clientContext), OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)), 120000, HANDLE_404);
setupProxyHandlerForSSL(proxyHandler);
proxyOpenListener.setRootHandler(proxyHandler);
proxyServer.resumeAccepts();
} else if (h2c || h2cUpgrade) {
openListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true, UndertowOptions.HTTP2_PADDING_SIZE, 10));
acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
InetSocketAddress targetAddress = new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT) + PROXY_OFFSET);
server = worker.createStreamConnectionServer(targetAddress, acceptListener, serverOptions);
proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
ProxyHandler proxyHandler = new ProxyHandler(loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI(h2cUpgrade ? "http" : "h2c-prior", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null), null, null, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)), 30000, HANDLE_404);
setupProxyHandlerForSSL(proxyHandler);
proxyOpenListener.setRootHandler(proxyHandler);
proxyServer.resumeAccepts();
} else if (https) {
XnioSsl clientSsl = new UndertowXnioSsl(xnio, OptionMap.EMPTY, SSL_BUFFER_POOL, createClientSslContext());
openListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
server = ssl.createSslConnectionServer(worker, new InetSocketAddress(getHostAddress("default"), 7777 + PROXY_OFFSET), acceptListener, serverOptions);
server.getAcceptSetter().set(acceptListener);
server.resumeAccepts();
proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
ProxyHandler proxyHandler = new ProxyHandler(loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("https", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null), clientSsl), 30000, HANDLE_404);
setupProxyHandlerForSSL(proxyHandler);
proxyOpenListener.setRootHandler(proxyHandler);
proxyServer.resumeAccepts();
} else {
if (h2) {
UndertowLogger.ROOT_LOGGER.error("HTTP2 selected but Netty ALPN was not on the boot class path");
}
openListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true, UndertowOptions.ENABLE_CONNECTOR_STATISTICS, true));
acceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(openListener));
if (!proxy) {
server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), acceptListener, serverOptions);
} else {
InetSocketAddress targetAddress = new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT) + PROXY_OFFSET);
server = worker.createStreamConnectionServer(targetAddress, acceptListener, serverOptions);
proxyOpenListener = new HttpOpenListener(pool, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true));
proxyAcceptListener = ChannelListeners.openListenerAdapter(wrapOpenListener(proxyOpenListener));
proxyServer = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(getHostAddress(DEFAULT)), getHostPort(DEFAULT)), proxyAcceptListener, serverOptions);
ProxyHandler proxyHandler = new ProxyHandler(loadBalancingProxyClient = new LoadBalancingProxyClient(GSSAPIAuthenticationMechanism.EXCLUSIVITY_CHECKER).addHost(new URI("http", null, getHostAddress(DEFAULT), getHostPort(DEFAULT) + PROXY_OFFSET, "/", null, null)), 30000, HANDLE_404);
setupProxyHandlerForSSL(proxyHandler);
proxyOpenListener.setRootHandler(proxyHandler);
proxyServer.resumeAccepts();
}
}
if (h2cUpgrade) {
openListener.setRootHandler(new Http2UpgradeHandler(rootHandler));
} else {
openListener.setRootHandler(rootHandler);
}
server.resumeAccepts();
} catch (Exception e) {
throw new RuntimeException(e);
}
notifier.addListener(new RunListener() {
@Override
public void testRunFinished(final Result result) throws Exception {
server.close();
stopSSLServer();
worker.shutdown();
}
});
}
}
use of org.junit.runner.notification.RunListener in project ACS by ACS-Community.
the class TATJUnitRunner method runMain.
/**
* Modified version of {@link JUnitCore#runMain(JUnitSystem, String...)}.
* We restrict ourselves to running only one test class (or suite) at a time.
* This method is not thread-safe!
* @param testClass
* @return the result
* @throws IOException
*/
public Result runMain(Class<?> testClass) throws IOException {
Result result = null;
try {
keepTestOutput = testClass.isAnnotationPresent(KeepTestOutput.class);
createStreams(testClass);
redirectSysStreams();
JUnitSystem system = new JUnitSystem() {
public void exit(int code) {
System.exit(code);
}
public PrintStream out() {
return resultOut;
}
};
system.out().println("JUnit version " + Version.id());
RunListener listener = new TextListener(system);
// or should we listen directly?
delegate.addListener(listener);
result = delegate.run(testClass);
} finally {
restoreSysStreams();
closeStreams();
}
// in either case print a summary which automated tools can analyze (SPR ALMASW2005121)
int total = result.getRunCount();
int success = total - result.getFailureCount();
String runnerReport = "TEST_RUNNER_REPORT success/total: " + success + "/" + total;
System.out.println(runnerReport);
if (result.wasSuccessful()) {
System.out.println("JUnit test run succeeded");
if (!keepTestOutput) {
sysOutFile.delete();
sysErrFile.delete();
resultFile.delete();
}
} else {
System.err.println("JUnitRunner: Errors and/or failures during test execution!\n");
// Dump the JUnit test runner output, the captured stdout, and the captured stderr of the text execution to System.err.
dumpAndDeleteCapturedFile(resultFile, "Test execution trace:");
dumpAndDeleteCapturedFile(sysOutFile, "System.out during test execution:");
dumpAndDeleteCapturedFile(sysErrFile, "System.err during test execution:");
}
return result;
}
use of org.junit.runner.notification.RunListener in project lucene-solr by apache.
the class TestMaxFailuresRule method testMaxFailures.
@Test
public void testMaxFailures() {
LuceneTestCase.replaceMaxFailureRule(new TestRuleIgnoreAfterMaxFailures(2));
JUnitCore core = new JUnitCore();
final StringBuilder results = new StringBuilder();
core.addListener(new RunListener() {
char lastTest;
@Override
public void testStarted(Description description) throws Exception {
// success.
lastTest = 'S';
}
@Override
public void testAssumptionFailure(Failure failure) {
// assumption failure.
lastTest = 'A';
}
@Override
public void testFailure(Failure failure) throws Exception {
// failure
lastTest = 'F';
}
@Override
public void testFinished(Description description) throws Exception {
results.append(lastTest);
}
});
Result result = core.run(Nested.class);
Assert.assertEquals(500, result.getRunCount());
Assert.assertEquals(0, result.getIgnoreCount());
Assert.assertEquals(2, result.getFailureCount());
// Make sure we had exactly two failures followed by assumption-failures
// resulting from ignored tests.
Assert.assertTrue(results.toString(), results.toString().matches("(S*F){2}A+"));
}
Aggregations