ngrinder 入库mysql_script nGrinder_TestRunnerInsertMysqlSingle.groovy
s
阿里巴巴Java開發(fā)規(guī)范手冊(cè).zip
http://dl.iteye.com/topics/download/ffc4ddcf-8b65-3b3c-b146-96468e2baf40
/**
關(guān)于日志打印
System.out.println(result); 這個(gè)應(yīng)該只是在當(dāng)前驗(yàn)證頁(yè)面打印;
grinder.logger.info(result);這個(gè)可以打印到日志中
*/
nGrinder 平臺(tái)調(diào)試groovy壓測(cè)腳本,成功!
C:\Users\Lindows\workspace\GroovyTest\src\com\iteye\lindows\mysql\TestRunnerInsertMysqlSingle.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代碼示例,連接數(shù)據(jù)庫(kù)進(jìn)行查詢
*
* @author Lindows
*/
@RunWith(GrinderRunner)
class TestRunnerInsertMysqlSingle {
public static GTest insertTable
public static Connection conn;
public static Statement stmt; //創(chuàng)建Statement對(duì)象
@BeforeProcess
public static void beforeProcess() {
insertTable = new GTest(1, "插入表數(shù)據(jù)")
try {
Class.forName("com.mysql.jdbc.Driver");
grinder.logger.info("成功加載MySQL驅(qū)動(dòng)!");
String url="jdbc:mysql://10.37.136.162:3306/performance_test"; //JDBC的URL
String username = "performance_user";
String passwd = "performance!QAZ";
conn = DriverManager.getConnection(url, username, passwd);
stmt = conn.createStatement(); //創(chuàng)建Statement對(duì)象
grinder.logger.info("成功創(chuàng)建stmt!");
} catch (Exception e) {
e.printStackTrace()
}
}
@BeforeThread
public void beforeThread() {
insertTable.record(this, "insertTable")
grinder.statistics.delayReports=true
}
@Test
public void insertTable() {
try{
grinder.logger.info("成功連接到數(shù)據(jù)庫(kù)!");
StringBuffer sql = new StringBuffer()
sql.append("insert into tab_002(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 passat for 3 years','2017-06-12 18:00:00','2017-06-13 15:00:00')")
grinder.logger.info(sql.toString())
Thread.sleep(new Random().nextInt(10)) //這里可以設(shè)置思考時(shí)間10ms
assertTrue(!stmt.execute(sql.toString()))//執(zhí)行sql insert,!stmt.execute(sql)該寫法只于insert true確認(rèn)
//assertTrue(stmt.execute(sql));//執(zhí)行sql query , !stmt.execute(sql)該寫法只適用于query true確認(rèn)
}catch(Exception e) {
e.printStackTrace();
}
}
@AfterThread
public void afterThread() {
stmt.close();
conn.close();
}
}
C:\Users\Lindows\Desktop\lab\groovy\libs
asm-3.3.1.jar
commons-lang-2.6.jar
commons-lang3-3.3.2.jar
commons-logging-1.0.4.jar
grinder-core-3.9.1.jar
grinder-dcr-agent-3.9.1.jar
grinder-http-3.9.1.jar
grinder-http-patch-3.9.1-patch.jar
grinder-httpclient-3.9.1.jar
grinder-httpclient-patch-3.9.1-patch.jar
grinder-patch-3.9.1-patch.jar
hamcrest-all-1.1.jar
json-20090211.jar
junit-dep-4.11.jar
log4j-1.2.15.jar
logback-classic-1.0.0.jar
logback-core-1.0.0.jar
mysql-connector-java-5.1.36 (1).jar
ngrinder-core-3.4.jar
ngrinder-groovy-3.4.jar
ngrinder-runtime-3.4.jar
ngrinder-sh-3.4.jar
slf4j-api-1.6.4.jar
junit ?test運(yùn)行異常:
java.lang.RuntimeException: Please add?-javaagent:C:\Users\Lindows\Desktop\lab\groovy\libs\grinder-dcr-agent-3.9.1.jarin 'Run As JUnit' vm argument.at net.grinder.engine.process.JUnitThreadContextInitializer.initialize(JUnitThreadContextInitializer.java:72)at net.grinder.scriptengine.groovy.junit.GrinderRunner.initializeGrinderContext(GrinderRunner.java:142)at net.grinder.scriptengine.groovy.junit.GrinderRunner.(GrinderRunner.java:112)at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:423)at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.(JUnit4TestReference.java:33)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.(JUnit4TestClassReference.java:25)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
解決一: -javaagent:C:\Users\Lindows\Desktop\lab\groovy\libs\grinder-dcr-agent-3.9.1.jar
Debug As JUnit Test ,,,ok!
end
總結(jié)
以上是生活随笔為你收集整理的ngrinder 入库mysql_script nGrinder_TestRunnerInsertMysqlSingle.groovy的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 同步磁阻电机SynRM滑模控制 基于FO
- 下一篇: 学习JavaScript第一弹(上)——