TTworkbench应用客户案例

您当前所在位置: 

 网站首页 >  TTworkbench应用客户案例
TTCN-3/TTworkbench分布式测试例子工程解析

TTCN-3标准6部分“TTCN-3 Control Interface”定义了TTCN-3的分布式测试标准,将测试部署在异构硬件,工作在不同的应用场景和部署模式。TTCN-3的分布测试使TTCN-3适合负载/压力测试,扩展性测试,功能测试等 

1.TTCN-3分布式测试平台TTmex

TTmex是符合TTCN-3分布式测试标准要求的TTCN-3分布式测试平台,应用TTmex,客户可以只进行一次测试开发,把测试分布到不同的应用场景和部署模式下执行。是目前为止最佳的TTCN-3分布式测试实现。

 

                                 Figure 1. Ttmex Structure 

TTmex 架构设计目标如下:

l  解决计算测试组件部署最佳策略,获得最佳的测试执行效率。

l  提供高性能,并为整个测试执行常见操作进行了优化。  

l  可以部署在异构硬件,工作在不同的应用场景和部署模式。

l  可扩展满足预期的需求,用最小的资源代价支持大量的活动和用户(supports a large number of activities and users with minimal use of resources.

l  Ttmex是可管理的,允许操作者在适当的场景下部署、监控和troubleshoot应用。 

2.分布式测试例子工程TTCN-3代码解析

下边我们介绍一个TTworkbench内置的分布式测试的例子工程。在这个例子工程里边,我们创建两个平行组件PTC同时执行访问同一个网页下载文件,通过这个例子来展示分布式测试例的开发特点。 

module DinoListTest {

    modulepar integer NUMBER_OF_PTCS := 2 

//模块和模块参数定义。在这里模块参数代表2PTCs(平行组件) 

type record urlType {

        charstring protocol,

        charstring host,

        charstring file

    }

//类型定义,定义发送消息类型。发出去的是url消息,也就是网页浏览的消息。

    type set of dinosaurType dinolistType; 

    type record dinosaurType {

        charstring name,

        charstring len,

        charstring mass,

        charstring time,

        charstring place

}

//类型定义,定义接收消息类型。这里首先定义名称为dinosaurTyperecord类型接收回来的消息应该是由dinosaurType组合的set of 类型消息。 

template urlType urlTemplate := {

        protocol := "http://",

        host     := "www.testingtech.de",

        file     := "/TTCN-3_Example/dinolist.xml"

    }

//定义发送消息模版。发送的是名称为urlTemplate网页访问消息。

    template dinosaurType BrachiosaurusTemplate := {

        name  := "Brachiosaurus",

        len   := ?,

        mass  := ?,

        time  := ?,

        place := ?

    }

//定义消息模版,在这里只给第一个区赋值name :=Brachiosaurus,其它的的区是什么都不关注。

    template dinolistType DinoListTemplate := {BrachiosaurusTemplate, *};

//定义接收消息模版。我们接收回来的消息应该是DinoListTemplate消息,这是一个set of 类型消息。在这个接收回来的消息中我们只关心表里是否包含BranchiosaurrusTemplate消息,其它的有没有或者是什么都不关注。 

type port httpPortType message {

        out urlType;

        in  dinolistType;

    }

//端口类型定义,定义发送的消息为urlType类型,接收的消息为dinolistType类型

    type component ptcType {

        //the port for the communication between the PTC and the SYSTEM

        port httpPortType httpPort;

        timer localTimer := 3.0;

    }

//定义ptc组件类型,ptc组件包含了端口以及内部计时器,端口类型就是我们上边定义的端口类型,ptc端口用于和系统端口建立映射,是消息发送和接收的通道。 

    type component mtcType {}

//定义mtc,mtc在这里不负责通信,只是用来承载测试,所以没有给mtc定义端口。

    type component systemType {

        port httpPortType httpPortArray[NUMBER_OF_PTCS];

}

//定义系统组件,系统组件是待测系统在ttcn-3代码中的映射。系统组件包含了http类型端口,httpPortArray代表了端口的数量,这里我们定义的数量是2个。系统的这些端口平行的和ptc端口进行通信。 

function ptcBehaviour() runs on ptcType {

        httpPort.send(urlTemplate);

        localTimer.start;

        alt {

            [] httpPort.receive(DinoListTemplate) {

                localTimer.stop;

                setverdict(pass);

            }

            [] httpPort.receive {

                localTimer.stop;

                setverdict(fail);

            }

            [] localTimer.timeout {

                setverdict(fail);

            }

        }

}

//定义运行在ptc上的行为函数。http端口发出网页访问消息,启动计时器,如果收到了DinolistType消息(包含了名字为BrachiosaurusBrachiosaurusTemplate,定义测试通过,如果收到错误消息,定义为fail,如果计时器超时,定义测试结果为fail. 

testcase DinoListTest_1() runs on mtcType system systemType { 

        var ptcType ptcArray[NUMBER_OF_PTCS];

        var integer i := 0;

        for (i:=0; i<NUMBER_OF_PTCS; i:=i+1) {

            //create the PTCs

            ptcArray[i] := ptcType.create;

        }

        for (i:=0; i<NUMBER_OF_PTCS; i:=i+1) {

            //map the PTCs to the system port

            map (ptcArray[i]:httpPort, system:httpPortArray[i]);

        }

        for (i:=0; i<NUMBER_OF_PTCS; i:=i+1) {

            //start the PTC's behaviour

            ptcArray[i].start(ptcBehaviour());

        }

         all component.done;

    }

}

//定义测试例,第一for循环创建ptc,在这里创建了两个ptc.第二个for循环分别建立

ptc端口和系统端口影射关系。第三个for循环同时启动ptc行为,调用行为函数开始测试。

3.分布式测试例子工程总结

我们在真实世界里经常有成千上万个用户同时反问一个网站的网页情况。在这里我们用创建多个(成千上万个)ptc来仿真这种对网站网页的访问行为,每个ptc代表一个真实的用户的访问行为,我们在执行测试时,利用分布式平台Ttmex把这些ptc放到不同的机器上来同时执行测试(同时访问同一网站的网页),这样实现应用TTCN-3来进行负载测试。 

4.应用分布式测试平台进行分布式测试部署执行测试

4.1例子工程的结构

ttcn3       The source code of TTCN-3 definition.                                

 Build       The Java .class files

Javasrc     The Java source code, here the codec example     implementation

Lib         additional Jar libraries

build.xml     antbuild file for jar packaging

*.ccf, *.tcdl   Part of TTmex configuration, belong to .mex

*.clf         Test campaign loader file for standalone test execution

*.tlz          Test logging file

README     The configuration and usage instruction

*.mex        The configuration and execution script file  taconfig.xml   The test adaptation configuration   

.mex ist       the key configuration and execution file to distributed testing.

   

5.应用TTmex部署、实施分布式测试

采用Ttmex分布式测试平台,把2ptc分布到2台机器上运行。请参考TTmex first step guide,有详细的文档,这里不再赘述。请参考/Item/Show.asp?m=1&d=1027

 

6.了解更多信息或者获得TTworkbench&TTmex试用license,请联系我们.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

北京泰斯汀通信技术有限公司
TEL:010-56497908 FAX:010-56497908
Copyright 2014.Testing 天润顺腾提供技术支持