liusheng / liusheng.github.io

Liusheng's blog
http://liusheng.github.io
5 stars 1 forks source link

Maven 调试test case #17

Open liusheng opened 4 years ago

liusheng commented 4 years ago
export JAVA_HOME=`dirname $(dirname $(update-alternatives --list javac))`
export PATH=/home/zuul/src/github.com/liusheng/hive/apache-maven-3.6.1/bin:$PATH
export PATH=$JAVA_HOME/bin:$PATH
mvn -Dtest=org.apache.hadoop.hive.llap.tezplugins.TestLlapTaskCommunicator test

注意,直接使用mvn test命令,会执行编译,检查等操作,如果想直接执行test,可以用surefire:test, 注意:这种方式必须要先cd到对应的module下面,也就是pom.xml所在的目录。

  mvn surefire:test -Dtest=TestAuxServices

如果要指定具体的子项目(module)下面执行特定的用例,可以用下面的方法:

  mvn surefire:test -Dtest=TestAuxServices  -pl org.apache.hadoop:hadoop-yarn-server-nodemanager

使用use设置sourcepath,否则无法使用list命令,注意,一般设置到/java那一级

Time-limited test[1] use /home/zuul/src/github.com/liusheng/hadoop/hadoop-common-project/hadoop-auth/src/test/java/
Time-limited test[1] use
/home/zuul/src/github.com/liusheng/hadoop/hadoop-common-project/hadoop-auth/src/test/java/
Time-limited test[1] list
239        }
240      }
241
242      protected void _testAuthenticationHttpClient(Authenticator authenticator, boolean doPost) throws Exception {
243 =>     start();
244        try {
245          HttpClient httpClient = getHttpClient();
246          doHttpClientRequest(httpClient, new HttpGet(getBaseURL()));
247
248          // Always do a GET before POST to trigger the SPNego negotiation

列出项目内所有的子模块:

mvn --also-make dependency:tree|grep maven-dependency-plugin | awk '{print $(NF-1)}'

列出依赖包:

mvn --also-make dependency:tree|grep maven-dependency-plugin | awk '{print $(NF-1)}'
mvn -e -B test -pl hadoop-kms

如果项目是Gradle管理的,怎么用jdb来调试?

首先执行命令:

export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

然后在执行gradle命令

./gradlew -i --console=plain --no-daemon --continue -DskipFormat test --tests TestKuduBinaryJarExtractor.testIsKuduBinaryJarOnClasspath -Dorg.gradle.debug=true

再新开一个窗口执行:

jdb -attach 127.0.0.1:5005

其他和Maven一致