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耗尽的更多相关文章

  1. PyCharm里面执行代码没问题,Jenkins执行时找不到第三方库

    在PyCharm里面代码执行没问题 本地cmd执行也没问题 Jenkins执行时报错 原因是第三方库是用PyCharm安装的,后来在Jenkins服务器上用pip装好第三方库后,就可以执行了 再执行 ...

  2. maven执行单元测试失败后,继续生成Jacoco&Sonar报告

    为保证生成单元测试覆盖 sonarqube或者jacoco与maven集成时,如果pom文件配置了sonarqube或者Jacoco的相关配置, 那么在pom文件所在目录执行mvn clean ins ...

  3. jenkins执行shell命令提示找不到命令解决办法

    用jenkins执行shell脚本,执行一条命令: #唤醒休眠手机 adb shell input keyevent 提示: [adb] $ /bin/sh -xe /Users/xxxxx/tool ...

  4. Java+Selenium 3.x 实现Web自动化 - Maven打包TestNG,利用jenkins执行测试

    1. Jenkins本地执行测试 or 服务器端执行测试 测试代码计划通过jenkins执行时,通过网上查询各种教程,大多数为本地执行测试,由此可见,本地执行是大多数人的选择. 经过探讨,最终决定采用 ...

  5. 让Jenkins执行GitHub上的pipeline脚本

    本文是<Jenkins流水线(pipeline)实战>系列的第二篇,上一篇搭建好了Jenkins环境并执行了一个简单的pipeline任务,当时我们直接在Jenkins网页上编写pipel ...

  6. 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 ...

  7. 【maven】【spring boot】【单元测试】 使用controller 执行单元测试类

    存在这样一个场景: 当项目启动时间过长,又没办法缩短的时候,写单元测试就是一个十分耗时的工作, 这工作不在于使用编写代码,而在于每次run junit test 都需要完整启动一次项目,白白浪费宝贵的 ...

  8. Jenkins执行脚本文件

    Jenkins执行脚本文件如下(startup.sh): #!/bin/bash #这里可替换为你自己的执行程序,其他代码无需更改 export JAVA_HOME=/usr/src/java/jdk ...

  9. Magicodes.IE编写多框架版本支持和执行单元测试

    背景 很多情况下,我们编写了一些工具库之后,往往在某些框架版本中会出现一些问题,比如本人最近写的一个导入导出的工具库Magicodes.IE(GitHub:https://github.com/xin ...

随机推荐

  1. [转载]关于typedef的用法总结

    不管实在C还是C++代码中,typedef这个词都不少见,当然出现频率较高的还是在C代码中.typedef与#define有些相似,但更多 的是不同,特别是在一些复杂的用法上,就完全不同了,看了网上一 ...

  2. edge浏览器识别ip地址为手机号的解决办法

    edge浏览器识别ip地址为手机号的解决办法 今天突然发现类似101.231.70.242的ip地址会在edge浏览器里面识别为可点击的链接,后来看了一下,原因就是被识别为手机号了,因为我发现点击的时 ...

  3. luogu1736 创意吃鱼法

    好的题解使人一下就懂啊-- s1[i][j]表示(i,j)最多向左(或右)延伸多少个格子,使这些格子中的数都是0(不包括(i,j)) s2[i][j]表示(i,j)最多向上延伸多少个格子,使这些格子中 ...

  4. Java集合数据类型

    Java集合如Map.Set.List等所有集合只能存放引用类型数据,它们都是存放引用类型数据的容器,不能存放如int.long.float.double等基础类型的数据. 1. 集合存储对象 Jav ...

  5. python - 字符串的内建函数

    # -*- coding:utf-8 -*- '''@project: jiaxy@author: Jimmy@file: study_3_str_内建函数.py@ide: PyCharm Commu ...

  6. 0014.Linux环境搭建 Python环境搭建

    -安装Linux-- 找了了老男孩19期的运维班安装视频,尼玛真心不想看书,文字枯燥的要死,还不如直接看视频进行安装... 可怜了我的C盘只有1GB了...绝对不能安装在C盘...那就安装在E盘吧,足 ...

  7. solr 创建core

    mkdir /var/solr/data/CORE_NAME cp -r /opt/solr/server/solr/configsets/basic_configs/* /var/solr/data ...

  8. css3制作扇形菜单

    工作中网页中有一个扇形的导航菜单,以前没有接触过,参考了http://www.w3cplus.com/css3/building-a-circular-navigation-with-css-tran ...

  9. BZOJ4556 [Tjoi2016&Heoi2016]字符串 【后缀数组 + 主席树 + 二分 + ST表】

    题目 佳媛姐姐过生日的时候,她的小伙伴从某东上买了一个生日礼物.生日礼物放在一个神奇的箱子中.箱子外边写了 一个长为n的字符串s,和m个问题.佳媛姐姐必须正确回答这m个问题,才能打开箱子拿到礼物,升职 ...

  10. python 缺少包

    https://pypi.python.org/pypi/pdfminer/20140328 到这里下载相应的包,再进行安装. tar  –xivf  pybloomfilter-1.0 cd  py ...