So I got the job of testing the new java engine. The programmer who created it made me a test jar file so I can test some crashmoments and loadbalancing.
所以我得到了测试新的java引擎的工作。创建它的程序员为我创建了一个测试jar文件,这样我就可以测试一些突发事件和负载平衡。
I know it's a load of text here, but I hope someone can give me a great answer! Thanks in advance for reading!
我知道这里有很多文章,但我希望有人能给我一个很好的答案!提前感谢您的阅读!
I wanted to automate the testing process so I created a bash file.
我想自动化测试过程,所以我创建了一个bash文件。
So far what it does is loop for a couple of times, in which it starts the jar file:
到目前为止,它所做的是多次循环,其中它启动jar文件:
java -jar /mnt/nas/i/testsail/clusteng.jar 2>> /dev/null &
After that it gets the processId of the just started java app:
之后,它获得了刚刚启动的java应用程序的进程:
process_ids[$i]=$!
So eventually I have like 5 instances of that jar, all with their related processId.
最后我有5个jar实例,都有相关的过程。
Now my problem is, the programmer added a little shell around the app, in which I can tell it at what moment to crash. If I just start the engine from the commandline, it shows me that shell and I can just type 'fail moment_Of_Faillure' and it will ungracefully fail there.
现在我的问题是,程序员在应用程序周围添加了一个小shell,在这个shell中,我可以告诉它什么时候崩溃。如果我从命令行启动引擎,它会显示shell和我可以键入“fail moment_Of_Faillure”,它会在那里失败。
Ofcourse now I want to give each instance another failmoment, and I want to randomize that from the bash script.
当然,现在我想给每个实例另一个失败时刻,我想从bash脚本中随机化它。
My question is; How can I give commands to each instance from within the bash script?
我的问题是;如何从bash脚本中向每个实例发出命令?
I will post the complete bash script here:
我将在这里发布完整的bash脚本:
#!/bin/bash
# Engine testing script; Starts multiple engine instances and shoots one every 20 seconds
clear
echo "#####################"
echo "# Start $1 processes #"
echo "#####################"
echo ""
# create number of processes
for (( i = 1 ; i <= $1; i++ ))
do
if test $i == 1
then
echo "Starting process: $i -> Master Process"
else
echo "Starting process: $i"
fi
#$! = last started process
java -jar /mnt/nas/i/testsail/clusteng.jar 2>> /dev/null &
process_ids[$i]=$!
echo "PID $!"
echo ""
sleep 20
done
sleep 20
for (( i = 1 ; i <= $1; i++ ))
do
echo "Kill PID:${process_ids[$i]}"
#ech `FAIL BEFORE_RANK_DISTRIBUTION` > fifo$i
kill -9 ${process_ids[$i]}
echo ""
if test $i != $1
then
sleep 20
fi
done
# run errorcheck
. `./checklogs`
1 个解决方案
#1
3
You could use named pipes (fifos) to send commands to the backgrounded processes.
您可以使用命名管道(fifos)向后台进程发送命令。
For some hints and advice see here:
这里有一些提示和建议:
Send command to a background process
向后台进程发送命令
#1
3
You could use named pipes (fifos) to send commands to the backgrounded processes.
您可以使用命名管道(fifos)向后台进程发送命令。
For some hints and advice see here:
这里有一些提示和建议:
Send command to a background process
向后台进程发送命令