Jacoco使用TCP服务器方法进行代码插桩。

huangapple go评论78阅读模式
英文:

Jacoco instrumentation using tcp server method

问题

以下是您要翻译的内容:

我正在尝试在远程服务器上对我的Java代码运行集成测试,因此每当我的测试命中我的代码服务器时,Jacoco都会记录它。

我对Jacoco还不太了解,到目前为止,我已经了解到有一种无需重新启动的TCP服务器方法。
1)我在我的/etc/profile中添加了以下行。

export JAVA_OPTS="-javaagent:/home/vansh/jacoco/lib/jacocoagent.jar=address=*,port=57026,destfile=/home/vansh/jacoco/jacoco.exec,output=tcpserver"

2)但是当我尝试使用以下命令进行转储时 -

java -jar jacococli.jar dump --address localhost --port  57026 --destfile /home/vansh/jacoco/jacoco-it.exec
错误:

[INFO] 正在连接到 localhost/127.0.0.1:57026。
[WARN] 拒绝连接 (Connection refused)[INFO] 正在连接到 localhost/127.0.0.1:57026。
Exception in thread "main" java.net.ConnectException: 拒绝连接 (Connection refused)
    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)

我检查了一下,端口57026上没有任何运行的内容,我的第一个javaagent命令是正确的吗?

英文:

I am trying to run integration tests on my java code from remote server, so whenever my tests hit my code server, jacoco records it.

I am new to jacoco, till now i have gather that there is tcp server method which doesnot require any restart.

  1. I have added below line in my /etc/profile.
export JAVA_OPTS="-javaagent:/home/vansh/jacoco/lib/jacocoagent.jar=address=*,port=57026,destfile=/home/vansh/jacoco/jacoco.exec,output=tcpserver"

2)but when i am trying to take dump using below command -

java -jar jacococli.jar dump --address localhost --port  57026 --destfile /home/vansh/jacoco/jacoco-it.exec
ERROR:

[INFO] Connecting to localhost/127.0.0.1:57026.
[WARN] Connection refused (Connection refused).
[INFO] Connecting to localhost/127.0.0.1:57026.
Exception in thread "main" java.net.ConnectException: Connection refused (Connection refused)
    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)

I checked that there is nothing run on port 57026, is my first command javaagent one is correct?

答案1

得分: 1

我在一年前做过同样的事情,在我的情况下,我运行一个TCP_Client的jar文件来收集dump,有多种方式(周期性地/带有和不带有重置先前覆盖的选项)。

我设置了JAVA_OPTS如下,

-javaagent: <jacoco_agent的文件路径>/jacocoagent.jar=output=tcpserver,address=*,port=6300

这是我TCP客户端的仓库链接 - 点击此处进入链接

将固定的参数设置到代码中或使用此仓库创建一个jar文件

如果你从这段代码中运行一个jar文件,

你可以通过传递“address”“port”“dump文件夹路径”“定期转储时间”“每次转储都重置选项”参数来运行这个jar文件。

示例:java -jar ExecutedDataDump.jar“127.0.0.1”“6300”“D:\server-dumplog\”“5”“noreset”

你将会在每5秒钟的时间间隔内得到带有时间戳的jacoco.exec文件,并且由于noreset选项,每个jacoco.exec文件都会获得累积报告

希望这对你有所帮助。

英文:

I have done same thing a year ago, In my case I run a TCP_Client jar for collecting the dump with many ways(periodically/with and without resetting previous coverage).

I set JAVA_OPTS as follows,

-javaagent:&lt;file_Path_for_jacoco_agent&gt;/jacocoagent.jar=output=tcpserver,address=*,port=6300

Here is my repo link of tcp client - enter link description here

set fixed arguments to the code or create a jar with this repo

If you are running a jar from this code,

You can run this jar with passing "address" "port" "dump-folder-path" "periodic-time-for-dumping" "resetting-option-with-every-dump" arguments.

example : java -jar ExecutedDataDump.jar &quot;127.0.0.1&quot; &quot;6300&quot; &quot;D:\\server-dumplog\\&quot; &quot;5&quot; &quot;noreset&quot;

You will get get jacoco.exec files with time stamp in every 5 secs time and due to noreset every jacoco.exec is get cumulative report

Hope this will helpful for you.

huangapple
  • 本文由 发表于 2020年9月27日 03:24:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/64081697.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定