Groovy   发布时间:2022-04-12  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了script Ngrinder_TestRunnerInsertMysqlSingle.groovy大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

s

阿里巴巴Java开发规范手册.zip

http://dl.iteye.com/topics/download/ffc4ddcf-8b65-3b3c-b146-96468e2baf40

 

nGrinder 平台调试groovy压测脚本,成功!@H_696_15@

 

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代码示例,连接数据库进行查询
 *
 * @author Lindows
 */
@RunWith(GrinderRunner)
class TestRunnerInsertMysqLSingle {
    public static GTest insertTable
    public static Connection conn;
    public static Statement stmt; //创建Statement对象

    @BeforeProcess
    public static void beforeProcess() {
        insertTable = new GTest(1,"插入表数据")
        try {
            Class.forName("com.MysqL.jdbc.Driver");
            grinder.logger.info("成功加载MysqL驱动!");
            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(); //创建Statement对象
            grinder.logger.info("成功创建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("成功连接到数据库!");
            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 SuNing 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)) //这里可以设置思时间10ms
            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\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
@L_197_24@or-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运行异常:

java.lang.RuntimeException: Please add 
-javaagent:C:\Users\Lindows\Desktop\lab\groovy\libs\grinder-dcr-agent-3.9.1.jar
in '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.<init>(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.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TESTClassReference.<init>(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

script Ngrinder_TestRunnerInsertMysqlSingle.groovy

Debug As JUnit Test ,,,ok!

 

end

大佬总结

以上是大佬教程为你收集整理的script Ngrinder_TestRunnerInsertMysqlSingle.groovy全部内容,希望文章能够帮你解决script Ngrinder_TestRunnerInsertMysqlSingle.groovy所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。