博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jenkins执行单元测试,会产生大量临时文件,要及时删除,不然会把inode耗尽
阅读量:5290 次
发布时间:2019-06-14

本文共 1964 字,大约阅读时间需要 6 分钟。

  jenkins的build命令:clean test -U findbugs:findbugs pmd:pmd sonar:sonar -Djava.io.tmpdir=/tmp/ -Dsonar.projectKey=xxxxx -Dsonar.projectName=xxxxxx -Dsonar.branch=xxxxx,这条命令执行单测的时候,会产生大量的临时文件到linux的/tmp/目录,日积月累,会最终消耗殆尽inode,从而不能使用硬盘再创建文件和文件夹

 

  原因:在做java单元测试的时候,创建了一些临时文件,没有及时删除:https://garygregory.wordpress.com/2010/01/20/junit-tip-use-rules-to-manage-temporary-files-and-folders/

  You can remove the burden of deleting temporary files and folders from your test code by using a JUnit TemporaryFolder Rule. Rules themselves are new in JUnit 4.7 and are used to change the behavior of tests. For example, the following test creates and deletes a temporary file and folder:

  In order to enable this feature, you must use the annotation @Rule on the declaration of the TemporaryFolder instance variable. The TemporaryFolder creates a folder in the default temporary file directory specified by the system property java.io.tmpdir. The method newFile creates a new file in the temporary directory and newFolder creates a new folder.

  When the test method finishes, JUnit automatically deletes all files and directories in and including the TemporaryFolder. JUnit guarantees to delete the resources, whether the test passes or fails.

package test; import java.io.File;import java.io.IOException; import org.junit.Rule;import org.junit.Test;import org.junit.rules.TemporaryFolder; public class TestTemporaryFolderRule {    @Rule    public TemporaryFolder testFolder = new TemporaryFolder();     @Test    public void testInTempFolder() throws IOException {        File tempFile = testFolder.newFile("file.txt");        File tempFolder = testFolder.newFolder("folder");        System.out.println("Test folder: " + testFolder.getRoot());        // test...    }}

 

  

Tests fail when java.io.tmpdir does not exist:https://ops4j1.jira.com/browse/PAXEXAM-294

  

Java.io.tmpdir介绍: https://www.cnblogs.com/nbjin/p/7392541.html

 

转载于:https://www.cnblogs.com/shengulong/p/9069251.html

你可能感兴趣的文章
活久现
查看>>
asp.net mvc中配置全局异常过滤器
查看>>
B/S神思SS628(100)身份证阅读器开发
查看>>
Do What you want
查看>>
IPv6 关于路由器配置静态IPv6路由的命令
查看>>
查看linux 用户登录信息及ip
查看>>
Linux系统测试端口连通性的方法
查看>>
联想think system sr550信息
查看>>
linux系统物理cpu信息查询
查看>>
shell 符号的定义(一)
查看>>
开源网络漏洞扫描软件
查看>>
yum 命令跳过特定(指定)软件包升级方法
查看>>
Python学习笔记(三)——类型与变量
查看>>
比较表变量和临时表
查看>>
为什么判断UITextField判断为空不能用isEqualToString:@""
查看>>
Spring框架的事务管理的分类
查看>>
Mysql Join语法以及性能优化
查看>>
【干货】移动端基础知识技巧总结
查看>>
python高级-面向对象(11)
查看>>
《算法导论》插入排序
查看>>