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 ...
随机推荐
- CodeForces 570D DFS序 树状数组 Tree Requests
参考九野巨巨的博客. 查询一个子树内的信息,可以通过DFS序转成线形的,从而用数据结构来维护. #include <iostream> #include <cstdio> #i ...
- Python中的魔术方法详解(双下方法)
介绍 在Python中,所有以“__”双下划线包起来的方法,都统称为“Magic Method”,中文称『魔术方法』,例如类的初始化方法 __init__ ,Python中所有的魔术方法均在官方文档中 ...
- luogu3371 【模板】单源最短路径 dijkstra堆优化
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> ...
- Selenium WebDriver- 显式等待
推荐使用显示等待,元素出现就不会等待而继续执行了.节省时间. #encoding=utf-8 import unittest import time from selenium import webd ...
- datatable 修改点击列头进行排序顺序
一般点击排序时,是先升序后降序 可以通过如下代码修改排序规则 jQuery(function ($) { $(".datatable").dataTable({ "pag ...
- Struts2报错:No result defined for action xxx and result input
case如下: 1. 后台程序要升级, 修改了一些功能,但是没有修改或者添加action的参数. 2. 数据库需要升级,执行了一些sql,修改过action的值. 3. 当修改某个已经存在的记录,然后 ...
- 《人月神话》读书笔记(2)-week3
为了确保团队中的每个人都能保持系统概念上的完整性,关于项目的书面规格说明是必不可少的.手册要描绘用户可见的一切,但不应支配实现的过程.光有规格说明也是不够的,会议也是必要的.书中提到的周例会会迅捷地给 ...
- C# 时间与时间戳互转 13位|13位時間戳与日期换转
这里直接上代码 懂C# 的程序猿 一看便知道如何使用的... /// <summary> /// 将Unix时间戳转换为DateTime类型时间 /// </summary> ...
- hihoCoder #1117 战争年代
题目大意 对一棵树的节点染色.初始时每个点都染成颜色 $0$,然后进行 $m$ 轮操作.第 $i$ 轮操作:从 $[0,d_i]$ 中随机选出一个整数 $d$,将距离点 $x_i$ 不超过 $d$ 的 ...
- NOJ——聊天止于呵呵(string流重定向+map,水题)
[1645] 聊天止于呵呵 时间限制: 5000 ms 内存限制: 65535 K 问题描述 (现代版)俗话说:流言止于智者,聊天止于呵呵.输入一段聊天记录,你的任务是数一数有 多少段对话“止于呵呵” ...