/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description: dengdagui
*
*/
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import lrapi.lr;
import java.util.Random;
import java.util.Calendar;
public class Actions
{
Client c = null;
String content;
int status = 0;
public int action() throws Throwable {
try {
lr.start_transaction("连接");
try{
c = new Client("pktest.pkmmo.com",40887);
}catch(Exception e){
lr.end_transaction("连接",lr.FAIL);
return 0;
}
if(c==null){
lr.end_transaction("连接",lr.FAIL);
return 0;
}
if(!c.connected()){
lr.end_transaction("连接",lr.FAIL);
return 0;
}
lr.end_transaction("连接",lr.PASS);
String room = "";
String uid = "";
String sid = "";
if("".equals(room) || "".equals(uid)|| "".equals(sid)){
lr.start_transaction("关闭2");
c.logout();
lr.end_transaction("关闭2",lr.PASS);
return 0 ;
}
lr.start_transaction("进入发送");
String content = "REGISTER "+room;
content +=" "+uid +" \n";
c.sendMessage(content);
lr.end_transaction("进入发送",lr.PASS);
lr.start_transaction("进入房间");
int i=0;
do{//--进入begin
//lr.start_transaction("进入3");
c.getMessage();
//lr.end_transaction("进入3",lr.PASS);
if(c.receiveMsg.size()>0){
String msg = c.receiveMsg.get(0);
c.receiveMsg.remove(0);
if(msg!=null && msg.indexOf("REGISTER")>-1){
if(msg!=null && msg.indexOf("ERR")>-1){
lr.end_transaction("进入房间", lr.PASS);
lr.start_transaction("进入房间f");
lr.end_transaction("进入房间f",lr.PASS);
c.logout();
return 0 ;
}else{
status = 1;
lr.end_transaction("进入房间", lr.PASS);
}
break;
}
}else{
try {
Thread.sleep(10);
} catch (InterruptedException e) {
lr.start_transaction("进入房间f1");
lr.end_transaction("进入房间f1",lr.PASS);
// TODO Auto-generated catch block
e.printStackTrace();
}
}
i++;
if(i>=200){
lr.end_transaction("进入房间", lr.FAIL);
lr.start_transaction("进入房间关闭");
c.logout();
lr.end_transaction("进入房间关闭",lr.PASS);
return 0;
}
}while(i<200);//进入end
lr.start_transaction("进入end");
lr.end_transaction("进入end",lr.PASS);
if(status == 1){
lr.start_transaction("买入发送");
content = "SITDOWN "+room+" "+sid+" "+uid+" 20 \n";
c.sendMessage(content);
lr.end_transaction("买入发送",lr.PASS);
lr.start_transaction("买入筹码");
int j=0;
do{//--买入begin
//lr.start_transaction("进入5");
c.getMessage();
//lr.end_transaction("进入5",lr.PASS);
if(c.receiveMsg.size()>0){
String msg = c.receiveMsg.get(0);
c.receiveMsg.remove(0);
if(msg.indexOf("SITDOWN")>-1 || msg.indexOf("SITFAIL")>-1){
if( msg!=null && msg.indexOf("SITFAIL")>-1 ||msg.indexOf("ERR")>-1 ){
lr.end_transaction("买入筹码", lr.FAIL);
lr.start_transaction("买入筹码关闭f2");
c.logout();
lr.end_transaction("买入筹码关闭f2",lr.PASS);
return 0;
}else{
status =2;
lr.end_transaction("买入筹码", lr.PASS);
}
break;
}
}else{
try {
Thread.sleep(10);
} catch (InterruptedException e) {
lr.start_transaction("买入筹码关闭f3");
lr.end_transaction("买入筹码关闭f3",lr.PASS);
// TODO Auto-generated catch block
e.printStackTrace();
}
}
j++;
if(j>=200){
lr.end_transaction("买入筹码", lr.FAIL);
lr.start_transaction("买入筹码关闭f");
c.logout();
lr.end_transaction("买入筹码关闭f",lr.PASS);
return 0;
}
}while(j<200);//--买end
lr.start_transaction("买end");
lr.end_transaction("买end",lr.PASS);
}
if(status == 2){
lr.start_transaction("退还筹码");
lr.start_transaction("退还发送");
content = "STANDUP "+room+" "+sid+" "+uid+" \n";
c.sendMessage(content);
lr.end_transaction("退还发送",lr.PASS);
int k=0;
do{//--退还begin
c.getMessage();
if(c.receiveMsg.size()>0){
String msg = c.receiveMsg.get(0);
c.receiveMsg.remove(0);
if(msg!=null && msg.indexOf("STANDUP")>-1){
status = 3;
lr.end_transaction("退还筹码", lr.PASS);
break;
}
}else{
try {
Thread.sleep(10);
} catch (InterruptedException e) {
lr.start_transaction("退还筹码关闭f2");
lr.end_transaction("退还筹码关闭f2",lr.PASS);
// TODO Auto-generated catch block
e.printStackTrace();
}
}
k++;
if(k>=200){
lr.end_transaction("退还筹码", lr.FAIL);
lr.start_transaction("退还筹码关闭f");
c.logout();
lr.end_transaction("退还筹码关闭f",lr.PASS);
return 0;
}
}while(k<200);//--退还end
lr.start_transaction("退还end");
lr.end_transaction("退还end",lr.PASS);
}
lr.start_transaction("离开房间_座位");
i=0;
content = "UNREGISTER "+room+"\n";
c.sendMessage(content);
do{//--离开begin
c.getMessage();
if(c.receiveMsg.size()>0){
String msg = c.receiveMsg.get(0);
c.receiveMsg.remove(0);
if(msg!=null && msg.indexOf("UNREGISTER")>-1){
lr.end_transaction("离开房间_座位", lr.PASS);
break;
}
}else{
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
i++;
if(i>=200){
lr.end_transaction("离开房间_座位", lr.FAIL);
lr.start_transaction("离开房间关闭");
c.logout();
lr.end_transaction("离开房间关闭",lr.PASS);
}
}while(i<200);//--离开end
} catch ( Exception e ) {
lr.start_transaction("关闭00");
lr.end_transaction("关闭00",lr.PASS);
if(c!=null)
c.logout();
c = null;
}
lr.start_transaction("关闭");
if(c!=null)
c.logout();
c = null;
lr.end_transaction("关闭",lr.PASS);
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
/*
初始化
*/
public int init() throws Throwable {
return 0;
}//end of init
}
阅读(872) | 评论(0) | 转发(0) |