jenkins执行单元测试,会产生大量临时文件,要及时删除,不然会把inode耗尽
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...
}
}
What is the correct way to write to temp file during unit tests with Maven?
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
jenkins执行单元测试,会产生大量临时文件,要及时删除,不然会把inode耗尽的更多相关文章
- PyCharm里面执行代码没问题,Jenkins执行时找不到第三方库
在PyCharm里面代码执行没问题 本地cmd执行也没问题 Jenkins执行时报错 原因是第三方库是用PyCharm安装的,后来在Jenkins服务器上用pip装好第三方库后,就可以执行了 再执行 ...
- maven执行单元测试失败后,继续生成Jacoco&Sonar报告
为保证生成单元测试覆盖 sonarqube或者jacoco与maven集成时,如果pom文件配置了sonarqube或者Jacoco的相关配置, 那么在pom文件所在目录执行mvn clean ins ...
- jenkins执行shell命令提示找不到命令解决办法
用jenkins执行shell脚本,执行一条命令: #唤醒休眠手机 adb shell input keyevent 提示: [adb] $ /bin/sh -xe /Users/xxxxx/tool ...
- Java+Selenium 3.x 实现Web自动化 - Maven打包TestNG,利用jenkins执行测试
1. Jenkins本地执行测试 or 服务器端执行测试 测试代码计划通过jenkins执行时,通过网上查询各种教程,大多数为本地执行测试,由此可见,本地执行是大多数人的选择. 经过探讨,最终决定采用 ...
- 让Jenkins执行GitHub上的pipeline脚本
本文是<Jenkins流水线(pipeline)实战>系列的第二篇,上一篇搭建好了Jenkins环境并执行了一个简单的pipeline任务,当时我们直接在Jenkins网页上编写pipel ...
- Jenkins服务使用 宿主机的docker、docker-compose (Jenkins 执行sudo命令时出现“sudo: no tty present and no askpass program specified”,以及 docker-compose command not found解决办法)
若要转载本文,请务必声明出处:https://www.cnblogs.com/zhongyuanzhao000/p/11681474.html 原因: 本人最近正在尝试CI/CD,所以就使用了 Jen ...
- 【maven】【spring boot】【单元测试】 使用controller 执行单元测试类
存在这样一个场景: 当项目启动时间过长,又没办法缩短的时候,写单元测试就是一个十分耗时的工作, 这工作不在于使用编写代码,而在于每次run junit test 都需要完整启动一次项目,白白浪费宝贵的 ...
- Jenkins执行脚本文件
Jenkins执行脚本文件如下(startup.sh): #!/bin/bash #这里可替换为你自己的执行程序,其他代码无需更改 export JAVA_HOME=/usr/src/java/jdk ...
- Magicodes.IE编写多框架版本支持和执行单元测试
背景 很多情况下,我们编写了一些工具库之后,往往在某些框架版本中会出现一些问题,比如本人最近写的一个导入导出的工具库Magicodes.IE(GitHub:https://github.com/xin ...
随机推荐
- 3224: Tyvj 1728 普通平衡树(新板子)
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 17048 Solved: 7429[Submit][St ...
- 线程中更新ui方法汇总
一.为何写作此文 你是不是经常看到很多书籍中说:不能在子线程中操作ui,不然会报错.你是不是也遇到了如下的疑惑(见下面的代码): @Override protected void onCreate ...
- 了解JavaScript核心精髓(一)
ES5 1.声明脚本 <script type="text/javascript"></script> 2.DOM与BOM DOM(Document Obj ...
- Leetcode37--->Sudoku Solver(填充数独)
题目: 给定一个不完整的数独,要求填充好数独:最初给出的数独是有效的,且假设一定有答案: 举例: A sudoku puzzle... 解题思路: 该题与青蛙走迷宫问题很相似,都是用深度优先: 代码如 ...
- 【bzoj2843】极地旅行社 LCT
题目描述 不久之前,Mirko建立了一个旅行社,名叫“极地之梦”.这家旅行社在北极附近购买了N座冰岛,并且提供观光服务.当地最受欢迎的当然是帝企鹅了,这些小家伙经常成群结队的游走在各个冰岛之间.Mir ...
- 【Luogu】P3317重建(高斯消元+矩阵树定理)
题目链接 因为这个专门跑去学了矩阵树定理和高斯消元qwq 不过不是很懂.所以这里只放题解 玫葵之蝶的题解 某未知dalao的矩阵树定理 代码 #include<cstdio> #inclu ...
- kb-07线段树-05-区间整体修改查询;(水)
/* */ #include<iostream> #include<cstring> #include<cstdio> using namespace std; s ...
- [luoguP1963] [NOI2009]变换序列(二分图最大匹配)
传送门 根据公式xjb推一下,然后就可以连边. 考虑到字典序最小,和匈牙利算法的实现过程,要倒序匹配. #include <cmath> #include <cstdio> # ...
- java面试题之@Autowired和@Resource的区别
@Autowired和@Resource的区别: 1.都可以用来装配bean,都可以写在字段或者方法上: 2. @Autowired默认按类型装配,默认情况下必须要求依赖对象必须存在,如果允许为nul ...
- APUE 学习笔记(七) 信号
1.信号是软件中断,提供一种异步处理事件的方法 很多事件产生信号: (1)用户按下某些中断键,如 Ctrl + C键产生 SIGINT信号 (2)硬件异常产生信号,比如 除数为0,无效的内存引用 ( ...