java模拟连接超时_Java:使用Toxiproxy模拟各种连接问题
生活随笔
收集整理的這篇文章主要介紹了
java模拟连接超时_Java:使用Toxiproxy模拟各种连接问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
java模擬連接超時
用Toxiproxy和Java的HttpURLConnection模擬各種連接問題,以查看產生了什么樣的錯誤:連接超時vs.讀取超時vs.連接被拒絕…。
結果:
系統:openjdk 11.0.1 2018-10-16
(我還無法模擬(但是)“連接中斷/斷開”。)
設置
先決條件
向/etc/hosts添加:
127.0.0.1 proxied.google.com毒物替代品設置
開始使用抗氧化劑:
docker pull shopify/toxiproxy # BEFORE we `run` it: case #3 docker run --rm -p 5555:5555 -p 6666:6666 -p 8474:8474 --name toxiproxy -it shopify/toxiproxy配置它(我們可以只發布到:8474但是使用CLI更容易):
$ docker exec -it toxiproxy /bin/sh / # cd /go/bin/ # ./toxiproxy-cli create google -l 0.0.0.0:6666 -u www.google.com:443 # BEFORE this is run: case #4 # ./toxiproxy-cli toxic add google -t latency -a latency=5000 # case #2 Added downstream latency toxic 'latency_downstream' on proxy 'google # ./toxiproxy-cli toxic remove google -n latency_downstream Removed toxic 'latency_downstream' on proxy 'google'# ./toxiproxy-cli toxic add google -t timeout -a timeout=2000 # case #2 Added downstream timeout toxic 'timeout_downstream' on proxy 'google' # ./toxiproxy-cli toxic remove google -n timeout_downstream Removed toxic 'timeout_downstream' on proxy 'google'# ./toxiproxy-cli toxic add google -t limit_data -a bytes=5000 # case #5 Added downstream limit_data toxic 'limit_data_downstream' on proxy 'google'測試代碼
(import '[java.net URL HttpURLConnection]) (->(doto ^HttpURLConnection (.openConnection (URL. "https://proxied.google.com:6666/"));; BEWARE: JVM *must* be started with `-Dsun.net.http.allowRestrictedHeaders=true` to allow setting the Host:(.setRequestProperty "Host" "www.google.com")(.setConnectTimeout 1000)(.setReadTimeout 1000))(.getInputStream)slurp)巴克特
閱讀我的toxiproxy模擬網絡超時以了解為什么我們需要打擾/etc/hosts和Host標頭。
翻譯自: https://www.javacodegeeks.com/2018/11/java-simulating-connection-problems.html
java模擬連接超時
總結
以上是生活随笔為你收集整理的java模拟连接超时_Java:使用Toxiproxy模拟各种连接问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux动态库链接顺序(linux动态
- 下一篇: 境外ddos(海外ddos怎么做)