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 ...
随机推荐
- android计算器
一:引言 目前手机可以说是普及率非常高的电子设备了,由于其便于携带,使用方便,资费适中等等原因,现在手机已经在一定程度开始代替固定电话的通话功能,以及一些原来电脑软件上的功能了.手机上的软件也随 ...
- 小学生四则运算APP核心代码公布
Mainactivity类: package com.example.XXSCYS; import java.io.ByteArrayOutputStream; import java.io.File ...
- 关于hash冲突的解决
分离链接法:public class SeparateChainingHashTable<AnyType>{ private static final int DEFAULT_TABLE_ ...
- debug网页时小问题The source attachment does not contain the source for the file
第一次debug总是出现下图问题,提示我没加源码... The source attachment does not contain the source for the file ... 解决方法: ...
- php开启curl不成功原因
1. 在php.ini中找到 ;extension=php_curl.dll, 如果前面有分号, 去掉 2. php_curl.dll (ext目录下, 如果没有, 请下载) , libeay32.d ...
- 软件工程(GZSD2015) 第三次作业提交进度
第三次作业题目请查看这里:软件工程(GZSD2015)第三次作业 开始进入第三次作业提交进度记录中,童鞋们,虚位以待哈... 2015年4月19号 徐镇.尚清丽,C语言 2015年4月21号 毛涛.徐 ...
- 速读《构建之法》(Build to win)有感
通过这两天时间,我粗读了<构建之法>这本书.老实说,对于这样四百多页的一本书,刚开始把这样的任务当作是一种负担,然而当我开始真正接触它时却被它幽默有趣的风格所深深吸引,它不同于以往学习的教 ...
- Mybatis源码分析
MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以对配置和原生Map使用简 ...
- PSP(4.27——5.3)以及周记录
1.PSP 4.27 11:40 18:10 125 265 Cordova A Y min 4.28 10:00 16:50 200 210 Cordova A Y min 4.29 15:30 2 ...
- rabbitmq使用报错总结
最近公司重构服务器架构,需要用到rabbitmq,在公司搞了一个下午还是连接不上,后来细看了英文说明,测试连接成功,得出如下报错几点. 我用的安装包:otp_win64_21.3.exe(erlang ...