单元测试报connection is allready closed导致dailybuild中断的解决方案——类加载机制的应用
public void afterTestMethod(Object testInstance, Method testMethod, Throwable exception) throws Exception {
Assert.notNull(testInstance, "testInstance must not be null");
if (logger.isTraceEnabled()) {
logger.trace("afterTestMethod(): instance [" + testInstance + "], method [" + testMethod +
"], exception [" + exception + "]");
}
getTestContext().updateState(testInstance, testMethod, exception); // Traverse the TestExecutionListeners in reverse order to ensure proper
// "wrapper"-style execution of listeners.
List<TestExecutionListener> listenersReversed =
new ArrayList<TestExecutionListener>(getTestExecutionListeners());
Collections.reverse(listenersReversed); Exception afterTestMethodException = null;
for (TestExecutionListener testExecutionListener : listenersReversed) {
try {
testExecutionListener.afterTestMethod(getTestContext());
}
catch (Exception ex) {
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener +
"] to process 'after' execution for test: method [" + testMethod + "], instance [" +
testInstance + "], exception [" + exception + "]", ex);
if (afterTestMethodException == null) {
afterTestMethodException = ex;
}
}
}
if (afterTestMethodException != null) {
// 捕获这种异常,不再抛出
if (afterTestMethodException.getMessage ().indexOf ("Connection has already been closed") > -1) {
logger.error ("catch the exp!", afterTestMethodException);
return;
}
throw afterTestMethodException;
}
}
再次执行5次dailybuild,问题没有再现。
protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
synchronized (getClassLoadingLock(name)) {
// First, check if the class has already been loaded
Class c = findLoadedClass(name);
if (c == null) {// 找不到的时候才会作为新的类加载
long t0 = System.nanoTime();
try {
if (parent != null) {
c = parent.loadClass(name, false);
} else {
c = findBootstrapClassOrNull(name);
}
} catch (ClassNotFoundException e) {
// ClassNotFoundException thrown if class not found
// from the non-null parent class loader
} if (c == null) {
// If still not found, then invoke findClass in order
// to find the class.
long t1 = System.nanoTime();
c = findClass(name); // this is the defining class loader; record the stats
sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
sun.misc.PerfCounter.getFindClasses().increment();
}
}
if (resolve) {
resolveClass(c);
}
return c;
}
}
如上图,classloader先加载的是项目编译生成的class,因此,同一个类,如果在项目中存在的话,就不会再加载jar包中的类了。
单元测试报connection is allready closed导致dailybuild中断的解决方案——类加载机制的应用的更多相关文章
- Database mirroring connection error 4 'An error occurred while receiving data: '10054(An existing connection was forcibly closed by the remote host.)
公司一SQL Server镜像发生了故障转移(主备切换),检查SQL Server镜像发生主备切换的原因,在错误日志中发现下面错误: Date 2019/8/31 14:09:17 ...
- Spring事务报Connection is read-only
昨天做项目时,写了个方法,程序突然报了Connection is readonly. Queries leading to data modification are not allowed调了程序半 ...
- 安装好的虚拟机,外部通过ssh工具连接,报connection failed
今天,新装了一台ubuntu虚拟机,安装成功以后,准备利用Xshell从外部访问linux,以减少切换,但是,在连接时,总是会报:connection failed. 于是,写下这篇随笔,以增加记忆且 ...
- main方法或者junit单元测试报 类找不到异常
MyEclipse10.7+Maven项目junit单元测试报找不到类异常,附正常编译后的输出设置 1 首先想到的是输出路径错误 一般不是maven工程的项目编译后的.class文件会在/weba ...
- 【centOS】【xshell】xshell连接虚拟机上的centOS,操作途中突然断开连接,报错:connect closed by foreign host
如题 xshell连接虚拟机上的centOS,操作途中突然断开连接,报错:connect closed by foreign host 快捷解决方法: 在虚拟机上centOS重新启动网络,即可解决问 ...
- An existing connection was forcibly closed by the remote host
StackOverflow https://stackoverflow.com/questions/5420656/unable-to-read-data-from-the-transport-con ...
- junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题
junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题,说明代码是没问题的,配置也没问题.开始时怀疑是我使用junit版本 ...
- By default, the connection will be closed if the proxied server does not transmit any data within 60 seconds.
WebSocket proxying https://nginx.org/en/docs/http/websocket.html By default, the connection will be ...
- MySQL中char(36)被认为是GUID导致的BUG及解决方案
MySQL中char(36)被认为是GUID导致的BUG及解决方案 有时候在使用Toad或在程序中,偶尔会遇到如下的错误: System.FormatException GUID 应包含带 4 个短划 ...
随机推荐
- 用户权限模块之spring security
准备工作:数据库采用mysql(5.6及以上) CREATE TABLE `auth_system` ( `ID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'I ...
- caffe源码学习之Proto数据格式【1】
前言: 由于业务需要,接触caffe已经有接近半年,一直忙着阅读各种论文,重现大大小小的模型. 期间也总结过一些caffe源码学习笔记,断断续续,这次打算系统的记录一下caffe源码学习笔记,巩固一下 ...
- android studio IDE 下,设置ACTIVITY全屏
因为ANDROID STUDIO的JAVA类是继承AppCompatActivity的 ,所以常规的全屏设置并不管用.如果要设置全屏,请参照如下代码/ 1/首先,打开AndroidManifest.x ...
- sodu 命令场景分析
摘自:http://www.cnblogs.com/hazir/p/sudo_command.html sudo 命令情景分析 Linux 下使用 sudo 命令,可以让普通用户也能执行一些或者全 ...
- PHP中对汉字进行UNICODE编码和解码的实现
<?php /** PHP中对汉字进行UNICODE编码和解码的实现 **/ class Helper_Tool{ //php中的unicode编码转中文 static function uni ...
- [leetcode-598-Range Addition II]
Given an m * n matrix M initialized with all 0's and several update operations. Operations are repre ...
- [leetcode-521-Longest Uncommon Subsequence I]
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two ...
- 遇到报ClassNotFoundException: Didn't find class "...Activity" on path: DexPathList
有一个工程,本来运行是正常的,我想把它移植到另一台PC上,结果报: java.lang.RuntimeException: Unable to instantiate activity Compone ...
- 如何使用LIBSVM,从安装到基本实例使用
1.在eclipse上安装libsvm 下载libsvm压缩包解压到本地目录,下载地址http://www.csie.ntu.edu.tw/~cjlin/libsvm/index.html 如图: 2 ...
- JavaScript深入浅出补充——(一)数据类型,表达式和运算符
项目基本做完,在进行下一阶段学习之前先看视频学习回顾一下JavaScript 一.数据类型 JavaScript中有五种原始类型和一种对象类型 JavaScript弱类型语言中隐式转换 num-0 字 ...