nGrinder TestRunnerInsertMysqlMore.groovy
s
C:\Users\Lindows\workspace\GroovyTest\src\com\iteye\lindows\mysql\TestRunnerInsertMysqlMore.groovy
package com.iteye.lindows.mysql import junit.framework.Assert
import net.grinder.script.GTest
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.AfterThread
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
import org.junit.Test
import org.junit.runner.RunWith import java.sql.Connection
import java.sql.DriverManager
import java.sql.ResultSet
import java.sql.Statement import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.assertTrue /**
* java代码示例,连接数据库进行插入
*
* @author 15071743(zhangl)
*/
@RunWith(GrinderRunner)
class TestRunnerInsertMysqlMore {
public static GTest insertTable
public static Connection conn;
public static Statement stmt; //创建Statement对象
public static List<String> databaseIP; //参数化文件多数据库IP
public static fileRowNumber;
@BeforeProcess
� //LoggerFactory.getLogger("worker").setLevel(Level.ERROR); //可以关闭该类打印的日志
public static void beforeProcess() {
insertTable = new GTest(1, "插入表数据")
//参数化文件读取--随机数据库IP
databaseIP = new File("C:\\Users\\Lindows\\workspace\\GroovyTest\\src\\resources\\databaseIP.txt").readLines()
fileRowNumber = new Random().nextInt(databaseIP.size()-1)
} @BeforeThread
public void beforeThread() {
insertTable.record(this, "insertTable")
grinder.statistics.delayReports=true
} @Test
public void insertTable() {
try{
//调用Class.forName()方法加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
grinder.logger.info("成功加载MySQL驱动!");
StringBuffer url = new StringBuffer()
url.append("jdbc:mysql://")
.append(databaseIP.get(fileRowNumber).split(",")[0]) // 随机获取第一列数据库ip地址
.append(":3306/performance_test")
grinder.logger.info("tangxje_url: " + url.toString());
String username = "performance_user";
String passwd = "performance!QAZ";
conn = DriverManager.getConnection(url.toString(), username, passwd);
stmt = conn.createStatement();
grinder.logger.info("成功创建stmt!");
grinder.logger.info("成功连接到数据库!");
StringBuffer sql = new StringBuffer()
grinder.logger.info("tangxje_tab:" + databaseIP.get(fileRowNumber).split(",")[1]);
sql.append("insert into ")
.append(databaseIP.get(fileRowNumber).split(",")[1]) // 随机获取第二列数据库表名,同行取值列1
.append(" (column_int,column_double,column_decimal,column_varchar_name,column_varchar_address,column_text,column_timestamp_create_time,column_timestamp_update_time) values (1000,300.25,600.98,'jack','")
.append("China BeiJing")
.append(new Random().nextInt(99999999))
.append("', 'work in lindows for 3 years','2017-06-12 18:00:00','2017-06-13 15:00:00')")
grinder.logger.info("tangxje_sql:" + sql.toString())
assertTrue(!stmt.execute(sql.toString()))//执行sql insert,!stmt.execute(sql)该写法只于insert true确认
//assertTrue(stmt.execute(sql));//执行sql query , !stmt.execute(sql)该写法只适用于query true确认
}catch(Exception e) {
e.printStackTrace();
}
} @AfterThread
public void afterThread() {
stmt.close();
conn.close();
}
}
文件:C:\Users\Lindows\workspace\GroovyTest\src\resources\databaseIP.txt
内容:
10.37.153.1,tab_102
10.37.136.165,tab_002
10.37.136.162,tab_002
10.37.136.163,tab_102
C:\Users\Lindows\Desktop\lab\groovy\libs

1 asm-3.3.1.jar
2 commons-lang-2.6.jar
3 commons-lang3-3.3.2.jar
4 commons-logging-1.0.4.jar
5 grinder-core-3.9.1.jar
6 grinder-dcr-agent-3.9.1.jar
7 grinder-http-3.9.1.jar
8 grinder-http-patch-3.9.1-patch.jar
9 grinder-httpclient-3.9.1.jar
10 grinder-httpclient-patch-3.9.1-patch.jar
11 grinder-patch-3.9.1-patch.jar
12 hamcrest-all-1.1.jar
13 json-20090211.jar
14 junit-dep-4.11.jar
15 log4j-1.2.15.jar
16 logback-classic-1.0.0.jar
17 logback-core-1.0.0.jar
18 mysql-connector-java-5.1.36 (1).jar
19 ngrinder-core-3.4.jar
20 ngrinder-groovy-3.4.jar
21 ngrinder-runtime-3.4.jar
22 ngrinder-sh-3.4.jar
23 slf4j-api-1.6.4.jar

end
nGrinder TestRunnerInsertMysqlMore.groovy的更多相关文章
- nGrinder TestRunnerBarrier.groovy / jihedian
s import net.grinder.script.Barrier import net.grinder.script.GTest import net.grinder.scriptengine. ...
- nGrinder TestRunnerInsertMysqlSingle.groovy
s C:\Users\Lindows\workspace\GroovyTest\src\com\iteye\lindows\mysql\TestRunnerInsertMysqlSingle.groo ...
- nGrinder TestGroovy.groovy
s /** * */ package com.iteye.lindows.mysql /** * @author Lindows * */ class TestGroovy { static main ...
- 基于Groovy搭建Ngrinder脚本调试环境
介绍 最近公司搭建了一套压力测试平台,引用的是开源的项目 Ngrinder,做了二次开发,在脚本管理方面,去掉官方的SVN,引用的是Git,其他就是做了熔断处理等. 对技术一向充满热情的我,必须先来拥 ...
- 基于Groovy编写Ngrinder脚本常用方法
1.生成随机字符串(import org.apache.commons.lang.RandomStringUtils) 数字:RandomStringUtils.randomNumeric(lengt ...
- Ngrinder脚本开发各细节锦集(groovy)
Ngrinder脚本开发各细节锦集(groovy) 1.生成随机字符串(import org.apache.commons.lang.RandomStringUtils) 数字:RandomStrin ...
- nGrinder 简易使用教程
背景 性能压测工具之前使用的是jmeter,这次说的是nGrinder,先直接搬运两者之间的比较 比较点 JMeter nGrinder 结果 实现语言 Java Java = License Apa ...
- nGrinder Loadrunner vs nGrinder
s d 功能 参数类型 取值方式 迭代方式 Loadrunner实现方式 nGrinder实现方式 参数化 文件 sequential (顺序取值) Each Iteration (每次迭代) 在参 ...
- nGrinder TestRunner http post json
s nGrinder学习笔记 — post请求 https://blog.csdn.net/meyoung01/article/details/50435881 import HTTPClient.H ...
随机推荐
- CI框架2.x的验证码中所遇问题解决
用php版本是5.6,CI框架版本是2.x,在使用验证码(captcha)时,遇到一些问题. 首先,我查看框架手册,说必需的两个参数是"img_url",“img_path”,其他 ...
- Trouble shooting(问题解决):centos 7 gnome show someting has gone wrong.
centos 7 升级 内核 3.10,startx启动不了了.进界面也是oh,no!someting has gone wrong . 参见帖子:http://bbs.csdn.net/topics ...
- ASP.NET MVC缓存使用
局部缓存(Partial Page) 1.新建局部缓存控制器: public class PartialCacheController : Controller { // GET: /PartialC ...
- Python表达式与运算符
表达式与运算符 Python语言支持以下类型的运算符: 算术运算符 比较(关系)运算符 赋值运算符 逻辑运算符 位运算符 成员运算符 身份运算符 运算符优先级 算术运算符 运算符 描述 + 加 - 两 ...
- Jquery 组 tbale表格筛选
<!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...
- spring学习总结(一)_Ioc基础(上)
最近经历了许许多多的事情,学习荒废了很久.自己的目标成了摆设.现在要奋起直追了.最近发现了张果的博客.应该是一个教师.看了他写的spring系列的博客,写的不错.于是本文的内容参考自他的博客,当然都是 ...
- Oracle中rownum和rowid的理解
rownum,rowid都叫伪列. 但是,rownum是逻辑上的编号,且其值总是从1开始,每行的rounum不是固定的.而rowid是“物理”编号.若数据库文件没有移动,则每行的 rowid一般是固定 ...
- jmeter创建基本的FTP测试计划
这个测试计划中创建4个用户从FTP站点请求2个文件,也可以让用户重复发送2次请求,这样总请求次数=4*2*2=16 使用以下元素:thread group / FTP Request /FTP Req ...
- 国产首款5G手机抢先亮相:如此给力的说!
5G网络是接下来移动互联网发展的主旋律,各家都在努力跟进,目前最积极的当属手机厂商,而2019年我们就能看到多款5G手机降临了. 在11月27日的未来信息通信技术国际研讨会上,vivo展示了他们正在研 ...
- BZOJ2793[Poi2012]Vouchers——枚举
题目描述 考虑正整数集合,现在有n组人依次来取数,假设第i组来了x人,他们每个取的数一定是x的倍数,并且是还剩下的最小的x个.正整数中有m个数被标成了幸运数,问有哪些人取到了幸运数. 输入 第一行一个 ...