1、安装funambol(具体请参照https://www.forge.funambol.org/DomainHome.html)
2、下载funambol的javademo的源码(https://core.forge.funambol.org/svn/core/trunk/funambol/clients/javademo)
3、下载funambol-client-sdk(http://funambol.com/opensource/download.php?file_id=funambol-client-sdk-9.0.0.zip&path=client-sdk/v9&_=d)
4、在javademo的基础上写自己的测试类:
package com.funambol.syncclient.testcase; import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import com.funambol.syncclient.spdm.DMException; import com.funambol.syncclient.spds.SyncException; import com.funambol.syncclient.spds.SyncManager; import com.funambol.syncclient.spds.event.SyncEvent; import com.funambol.syncclient.spds.event.SyncItemEvent; import com.funambol.syncclient.spds.event.SyncItemListener; import com.funambol.syncclient.spds.event.SyncListener; import com.funambol.syncclient.spds.event.SyncSourceEvent; import com.funambol.syncclient.spds.event.SyncSourceListener; import com.funambol.syncclient.spds.event.SyncStatusEvent; import com.funambol.syncclient.spds.event.SyncStatusListener; import com.funambol.syncclient.spds.event.SyncTransportEvent; import com.funambol.syncclient.spds.event.SyncTransportListener; public class UploadTest extends SyncInitialize implements SyncItemListener, SyncListener, SyncSourceListener, SyncStatusListener, SyncTransportListener { /** * @param args */ public static void main(String[] args) { UploadTest test = new UploadTest(); Options opt = new Options(); opt.addOption("d", "directory", true, "root directory"); CommandLineParser parser = new BasicParser(); CommandLine cl = null; try { cl = parser.parse(opt, args); if (cl.hasOption("d") && cl.getOptionValue("d") != null) { test.sync(cl.getOptionValue("d")); } } catch (ParseException e) { // do nothing } } public void sync(String rootDirectory) { super.init(rootDirectory); long startTime = 0; long endTime = 0; startTime = System.nanoTime(); try { SyncManager syncManager = SyncManager.getSyncManager(""); syncManager.addSyncItemListener(this); syncManager.addSyncListener(this); syncManager.addSyncSourceListener(this); syncManager.addSyncStatusListener(this); syncManager.addSyncTransportListener(this); syncManager.sync(); endTime = System.nanoTime(); System.out.println("upload time=" + (endTime - startTime) / (1000 * 1000)); } catch (SyncException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DMException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void sendDataBegin(SyncTransportEvent event) { // TODO Auto-generated method stub } @Override public void sendDataEnd(SyncTransportEvent event) { // TODO Auto-generated method stub } @Override public void receiveDataBegin(SyncTransportEvent event) { // TODO Auto-generated method stub } @Override public void dataReceived(SyncTransportEvent event) { // TODO Auto-generated method stub } @Override public void receiveDataEnd(SyncTransportEvent event) { // TODO Auto-generated method stub } @Override public void statusReceived(SyncStatusEvent event) { // TODO Auto-generated method stub } @Override public void statusToSend(SyncStatusEvent event) { // TODO Auto-generated method stub } @Override public void syncBegin(SyncSourceEvent event) { // TODO Auto-generated method stub } @Override public void syncEnd(SyncSourceEvent event) { // TODO Auto-generated method stub } @Override public void syncBegin(SyncEvent event) { // TODO Auto-generated method stub } @Override public void syncEnd(SyncEvent event) { // TODO Auto-generated method stub } @Override public void sendInitialization(SyncEvent event) { // TODO Auto-generated method stub } @Override public void sendModification(SyncEvent event) { // TODO Auto-generated method stub } @Override public void sendFinalization(SyncEvent event) { // TODO Auto-generated method stub } @Override public void syncError(SyncEvent event) { // TODO Auto-generated method stub } @Override public void itemAddedByServer(SyncItemEvent event) { // TODO Auto-generated method stub } @Override public void itemDeletedByServer(SyncItemEvent event) { // TODO Auto-generated method stub } @Override public void itemUpdatedByServer(SyncItemEvent event) { // TODO Auto-generated method stub } @Override public void itemAddedByClient(SyncItemEvent event) { // TODO Auto-generated method stub } @Override public void itemDeletedByClient(SyncItemEvent event) { // TODO Auto-generated method stub } @Override public void itemUpdatedByClient(SyncItemEvent event) { // TODO Auto-generated method stub } }5、将4中的类导出为可运行的jar包(sync.jar)
6、为sync.jar编写cmd或者sh脚本
7、使用Loadrunner录制cmd脚本:
8、在vuser_init部分添加计算syncml协议中的last和next标签的值的变量
int time_millitm; int get_time; int real_time; int length; char currentTime[14]; char currentDate[10]; char s_time_millitm[10]={0}; char s_get_time[60]={0}; char s_real_time[30]={0}; char last[60]={"0"}; vuser_init() { return 0; }
/********************************************************* // This file contains the body sections // recorded for web_custom_request function. **********************************************************/ const char * const body_variable_1 = "Body=<SyncML>\n <SyncHdr>\n <VerDTD>1.1</VerDTD>\n <VerProto>SyncML/1.1</VerProto>\n <SessionID>12345678</SessionID>\n <MsgID>2</MsgID>\n <Target><LocURI>null</LocURI></Target>\n <Source><LocURI>123</LocURI></Source>\n </SyncHdr>\n <SyncBody>\n <Status>\n <CmdID>1</CmdID>\n <MsgRef>1</MsgRef>\n <CmdRef>0</CmdRef>\n <Cmd>SyncHdr</Cmd>\n <TargetRef>123</TargetRef>\n <SourceRef" ">null</SourceRef>\n <Data>200</Data>\n </Status>\n <Status>\n<CmdID>2</CmdID>\n<MsgRef>1</MsgRef><CmdRef>1</CmdRef><Cmd>Alert</Cmd>\n<TargetRef>card</TargetRef>\n<SourceRef>card</SourceRef>\n<Data>200</Data>\n<Item>\n<Data>\n<Anchor xmlns=\"syncml:metinf\"><Next>1331709003765</Next></Anchor>\n</Data>\n</Item>\n</Status>\n<Sync>\n<CmdID>3</CmdID>\n<Target><LocURI>card</LocURI></Target>\n<Source><LocURI>card</LocURI></Source>\n<Replace>\n<CmdID>4</CmdID>\n<Meta>\n<Type xmlns=\"" "syncml:metinf\">text/x-vcard</Type>\n</Meta>\n<Item>\n<Source><LocURI>21879230459545</LocURI></Source>\n<Data>BEGIN:VCARD\r\nVERSION:2.1\r\nN;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:;=E8=92=8B=E6=9C=89=E4=B8=BA;;;\r\nFN;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:=E8=92=8B=E6=9C=89=E4=B8=BA\r\nTEL;VOICE;HOME:13590949158\r\nREV:26630430T040034\r\nEND:VCARD\r\n</Data>\n</Item>\n<Item>\n<Source><LocURI>21879038489371</LocURI></Source>\n<Data>BEGIN:VCARD\r\nVERSION:2.1\r\nN;ENCODING=QUOTED-PRINTABLE;" "CHARSET=UTF-8:;=E8=92=8B=E6=9C=89=E4=B8=BA;;;\r\nFN;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:=E8=92=8B=E6=9C=89=E4=B8=BA\r\nTEL;VOICE;HOME:13590949158\r\nREV:26630427T224102\r\nEND:VCARD\r\n</Data>\n</Item>\n<Item>\n<Source><LocURI>21879348891267</LocURI></Source>\n<Data>BEGIN:VCARD\r\nVERSION:2.1\r\nN;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:;=E8=92=8B=E6=9C=89=E4=B8=BA;;;\r\nFN;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:=E8=92=8B=E6=9C=89=E4=B8=BA\r\nTEL;VOICE;HOME:13590949158\r\nREV:26630501T125427" "\r\nEND:VCARD\r\n</Data>\n</Item>\n\n</Replace>\n</Sync><Final" "/>\n </SyncBody>\n</SyncML>\n\n";10、修改action部分:
Action() { char s0[10]={"0"}; char s00[10]={"00"}; time_millitm=666; get_time=time(0); itoa(get_time,s_get_time,10); itoa(time_millitm,s_time_millitm,10); length=strlen(s_time_millitm); if(length<3) { if (length==1) { strcat(s00,s_time_millitm); strcat(s_get_time,s00); } if (length==2) { strcat(s0,s_time_millitm); strcat(s_get_time,s0); } } else { strcat(s_get_time,s_time_millitm); } lr_save_string(last,"param_last"); lr_save_string(s_get_time,"param_s_get_time"); web_reg_save_param("temp", "LB=jsessionid=", "RB=</RespURI>", "Ord=1", "Search=All", LAST); web_custom_request("ds", "URL=http://127.0.0.1:8080/funambol/ds", "Method=POST", "Resource=0", "RecContentType=application/vnd.syncml+xml", "Referer=", "Mode=HTML", "EncType=application/vnd.syncml+xml; charset=UTF-8", "Body=<SyncML>\n <SyncHdr>\n <VerDTD>1.1</VerDTD>\n <VerProto>SyncML/1.1</VerProto>\n <SessionID>12345678</SessionID>\n <MsgID>1</MsgID>\n <Target>\n <LocURI>http://127.0.0.1:8080/funambol/ds</LocURI>\n </Target>\n <Source>\n <LocURI>{device}</LocURI>\n </Source>\n <Cred>\n <Meta>\n <Type xmlns=\"syncml:metinf\">syncml:auth-basic</Type>\n </Meta>\n <Data" ">{key}</Data>\n </Cred>\n\t<Meta>\n <MaxMsgSize>250000</MaxMsgSize>\n <MaxObjSize>4000000</MaxObjSize>\n </Meta>\n </SyncHdr>\n <SyncBody>\n <Alert>\n<CmdID>1</CmdID>\n<Data>200</Data>\n<Item>\n<Target><LocURI>card</LocURI></Target>\n<Source><LocURI>card</LocURI></Source>\n<Meta>\n<Anchor xmlns=\"syncml:metinf\">\n<Last>{param_last}</Last>\n<Next>{param_s_get_time}</Next>\n</Anchor>\n</Meta>\n</Item>\n</Alert>\n\n <Final/>\n </SyncBody" ">\n</SyncML>\n", LAST); web_custom_request("ds;jsessionid={temp}", "URL=http://127.0.0.1:8080/funambol/ds;jsessionid={temp}", "Method=POST", "Resource=0", "RecContentType=application/vnd.syncml+xml", "Referer=", "Mode=HTML", "EncType=application/vnd.syncml+xml; charset=UTF-8", body_variable_1, LAST); web_custom_request("ds;jsessionid={temp}", "URL=http://127.0.0.1 :8080/funambol/ds;jsessionid={temp}", "Method=POST", "Resource=0", "RecContentType=application/vnd.syncml+xml", "Referer=", "Mode=HTML", "EncType=application/vnd.syncml+xml; charset=UTF-8", "Body=<SyncML>\n <SyncHdr>\n <VerDTD>1.1</VerDTD>\n <VerProto>SyncML/1.1</VerProto>\n <SessionID>12345678</SessionID>\n <MsgID>3</MsgID>\n <Target><LocURI>http://127.0.0.1:8080/funambol/ds;jsessionid={temp}</LocURI></Target>\n <Source><LocURI>{device}</LocURI></Source>\n </SyncHdr>\n <SyncBody>\n <Status>\n <CmdID>1</CmdID>\n <MsgRef>2</MsgRef>\n <CmdRef>0</CmdRef>\n <Cmd" ">SyncHdr</Cmd>\n <TargetRef>http://127.0.0.1:8080/funambol/ds;jsessionid={temp}</TargetRef>\n <SourceRef>{device}</SourceRef>\n <Data>200</Data>\n </Status>\n <Alert>\n <CmdID>2</CmdID>\n <Data>222</Data>\n <Item>\n <Target><LocURI>http://127.0.0.1:8080/funambol/ds;jsessionid={temp}</LocURI></Target>\n <Source><LocURI>{device}</LocURI><" "/Source>\n </Item>\n </Alert>\n </SyncBody>\n</SyncML>\n\n", LAST); web_custom_request("ds;jsessionid={temp}", "URL=http://127.0.0.1:8080/funambol/ds;jsessionid={temp}", "Method=POST", "Resource=0", "RecContentType=application/vnd.syncml+xml", "Referer=", "Mode=HTML", "EncType=application/vnd.syncml+xml; charset=UTF-8", "Body=<SyncML>\n <SyncHdr>\n <VerDTD>1.1</VerDTD>\n <VerProto>SyncML/1.1</VerProto>\n <SessionID>12345678</SessionID>\n <MsgID>4</MsgID>\n <Target><LocURI>null</LocURI></Target>\n <Source><LocURI>{device}</LocURI></Source>\n </SyncHdr>\n <SyncBody>\n <Status>\n <CmdID>1</CmdID>\n <MsgRef>1</MsgRef>\n <CmdRef>0</CmdRef>\n <Cmd>SyncHdr</Cmd>\n <TargetRef>{device}</TargetRef>\n <SourceRef" ">null</SourceRef>\n <Data>200</Data>\n </Status>\n \n </SyncBody>\n</SyncML>\n\n", LAST); web_custom_request("ds;jsessionid={temp}", "URL=http://127.0.0.1:8080/funambol/ds;jsessionid={temp}", "Method=POST", "Resource=0", "RecContentType=application/vnd.syncml+xml", "Referer=", "Mode=HTML", "EncType=application/vnd.syncml+xml; charset=UTF-8", "Body=<SyncML>\n <SyncHdr>\n <VerDTD>1.1</VerDTD>\n <VerProto>SyncML/1.1</VerProto>\n <SessionID>12345678</SessionID>\n <MsgID>5</MsgID>\n <Target><LocURI>null</LocURI></Target>\n <Source><LocURI>{device}</LocURI></Source>\n </SyncHdr>\n <SyncBody>\n <Status>\n <CmdID>1</CmdID>\n <MsgRef>1</MsgRef>\n <CmdRef>0</CmdRef>\n <Cmd>SyncHdr</Cmd>\n <TargetRef>{device}</TargetRef>\n <SourceRef" ">null</SourceRef>\n <Data>200</Data>\n </Status>\n <Final></Final>\n </SyncBody>\n</SyncML>\n\n", LAST); return 0; }
temp、param_last、param_s_get_time变量都通过以下方式添加:
12、此时一个可进行并发测试的脚本创建OK,可以使用Loadrunner对这个脚本进行各种性能指标的测试。