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的更多相关文章

  1. nGrinder TestRunnerBarrier.groovy / jihedian

    s import net.grinder.script.Barrier import net.grinder.script.GTest import net.grinder.scriptengine. ...

  2. nGrinder TestRunnerInsertMysqlSingle.groovy

    s C:\Users\Lindows\workspace\GroovyTest\src\com\iteye\lindows\mysql\TestRunnerInsertMysqlSingle.groo ...

  3. nGrinder TestGroovy.groovy

    s /** * */ package com.iteye.lindows.mysql /** * @author Lindows * */ class TestGroovy { static main ...

  4. 基于Groovy搭建Ngrinder脚本调试环境

    介绍 最近公司搭建了一套压力测试平台,引用的是开源的项目 Ngrinder,做了二次开发,在脚本管理方面,去掉官方的SVN,引用的是Git,其他就是做了熔断处理等. 对技术一向充满热情的我,必须先来拥 ...

  5. 基于Groovy编写Ngrinder脚本常用方法

    1.生成随机字符串(import org.apache.commons.lang.RandomStringUtils) 数字:RandomStringUtils.randomNumeric(lengt ...

  6. Ngrinder脚本开发各细节锦集(groovy)

    Ngrinder脚本开发各细节锦集(groovy) 1.生成随机字符串(import org.apache.commons.lang.RandomStringUtils) 数字:RandomStrin ...

  7. nGrinder 简易使用教程

    背景 性能压测工具之前使用的是jmeter,这次说的是nGrinder,先直接搬运两者之间的比较 比较点 JMeter nGrinder 结果 实现语言 Java Java = License Apa ...

  8. nGrinder Loadrunner vs nGrinder

    s d 功能 参数类型 取值方式 迭代方式 Loadrunner实现方式 nGrinder实现方式 参数化 文件  sequential (顺序取值) Each Iteration (每次迭代) 在参 ...

  9. nGrinder TestRunner http post json

    s nGrinder学习笔记 — post请求 https://blog.csdn.net/meyoung01/article/details/50435881 import HTTPClient.H ...

随机推荐

  1. 基础-Math.floor与parseInt区别

    Math.floor只能对一个数向下取整,不能解析字符串 如: Math.floor(1.5) // 1 Math.floor(-2.1) // -3 Math.floor("3" ...

  2. Selenium的自我总结1

    搞了一段时间的Selenium Web的自动化,针对项目要搭建了一套适合项目的测试框架(Selenium[POM/DataDriver]+TestNG+Ant+Jenkins).在最开始看Seleni ...

  3. 使用node去爬虫

    let http = require('http'); let https = require('https');//引入node的https服务. let cheerio = require('ch ...

  4. [转帖]Nginx 的 TCP 负载均衡介绍

    Nginx 的 TCP 负载均衡介绍 https://www.cnblogs.com/felixzh/ 前几天同事问 nginx的代理 当时以为只有http的 现在看起来还有tcp的可以使用tcp 代 ...

  5. Axure8.0从入门到精通

    1. 新建工程 菜单->File->New 2. 添加组件并编辑组件 选中左侧Libary可选择Default/Flow/Icons,找到相应的组件并移动到工作区:并在右侧选中相应的组件属 ...

  6. MySQL-如何删除hash表分区

    一个大表,之前是以hash分区表的形式存在的, MySQL> show create table history_uint; | history_uint | CREATE TABLE `his ...

  7. docker--Dockerfile--java

    # AlpineLinux with a glibc-2.26-r0 and Oracle Java 7FROM alpine:3.6 MAINTAINER Anastas Dancha <an ...

  8. BZOJ1115[POI2009]石子游戏——阶梯Nim游戏

    题目描述 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏.问先手是否必 ...

  9. WordPress发送注册用户设置密码邮件提示:您的密码重设链接无效,请在下方请求新链接

    1.修改WP根目录下的 wp-login.php文件将 $message .= '<' . network_site_url("wp-login.php?action=rp&k ...

  10. day29 上周复习

    上周内容回顾 初始面向对象 class 类名(父类1,父类2): 静态属性 = "" # 静态属性,类方法 def __init__(self): # 初始化方法 def func ...