参照样例程序编写了使用jdbc连接sybase数据库的测试脚本,脚本调试通过,已验证可以连到数据库中查询。
但,问题是统计结果中没有定义test的结果数据,不知道原因出在哪里? 例外,本人又使用mysql jdbc连接mysql进行测试,问题依旧? 以下是测试脚本: from net.grinder.script.Grinder import grinder from net.grinder.script import Test from java.sql import DriverManager from com.sybase.jdbc3.jdbc import SybDriver debug = True test1 = Test(1, "testASE") # Load the Sybase JDBC driver. DriverManager.registerDriver(SybDriver()) def getConnection(): return DriverManager.getConnection("jdbc:sybase:Tds:192.168.1.100:5000/user", "sa", "password") def ensureClosed(object): try: object.close() except: pass class TestRunner: def __call__(self): connection = None statement = None try: connection = getConnection() statement = connection.createStatement() test1.record(statement) sql = "select * from user..test" if debug: print sql rs = statement.executeQuery(sql) if debug: print type(rs) while rs.next(): print rs.getString("network_address") if debug: print "Database OK" finally: ensureClosed(statement) ensureClosed(connection) 以下是日志中结果显示: Tests Errors Mean Test Test Time TPS Time (ms) Standard Deviation (ms) Totals 0 0 - 0.00 0.00 |
从最终结果来看,就是测试方法没有绑定到test上,也就是: test1.record(statement) 这个语句会将之后对statement的所有操作都作为测试的一个方法,就像代理一样。
你看看脚本在验证的时候有没有什么错误,把验证时候的日志发过来看看。
-----Original Message----- If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/jdbc-record-tp871.html
To start a new topic under ngrinder-user-cn, email [hidden email]
To unsubscribe from ngrinder-user-cn, click here. NAML |
2013-09-04 15:40:24,156 INFO myagent-0 : The Grinder version 3.11
2013-09-04 15:40:24,171 INFO myagent-0 : Java(TM) SE Runtime Environment 1.6.0_37-b06: Java HotSpot(TM) Client VM (20.12-b01, mixed mode) on Windows XP x86 5.1 2013-09-04 15:40:24,171 INFO myagent-0 : time zone is CST (+0800) 2013-09-04 15:40:24,250 INFO myagent-0 : worker process 0 2013-09-04 15:40:24,312 INFO myagent-0 : instrumentation agents: byte code transforming instrumenter for Jython 2.5; byte code transforming instrumenter for Java 2013-09-04 15:40:26,453 INFO myagent-0 : running "testDatabase.py" using Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:48:36) [Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] 2013-09-04 15:40:26,484 INFO myagent-0 thread-0: starting, will do 1 run 2013-09-04 15:40:26,484 INFO myagent-0 : start time is 1378280426478 ms since Epoch 2013-09-04 15:40:26,765 INFO myagent-0 thread-0: finished 1 run 2013-09-04 15:40:26,765 INFO myagent-0 : elapsed time is 276 ms 2013-09-04 15:40:26,765 INFO myagent-0 : Final statistics for this process: 2013-09-04 15:40:26,781 INFO myagent-0 : Tests Errors Mean Test Test Time TPS Time (ms) Standard Deviation (ms) Totals 0 0 - 0.00 0.00 Tests resulting in error only contribute to the Errors column. Statistics for individual tests can be found in the data file, including (possibly incomplete) statistics for erroneous tests. Composite tests are marked with () and not included in the totals. 以上是验证脚本的日志,sql语句已经执行成功,脚本也没有报错 |
看你用的Grinder的版本是3.11,我们使用的是3.9.1. 我看了一下Grinder的change log,没有看到有什么特别的会影响的地方,但是,因为我们对Grinder改写了很多,所以,无法保证在其他版本的Grinder上运行没有问题。 我用你的脚本,在我们的测试平台测了一下,这个脚本连我的数据库,运行是没有问题的。
所以,最好还是用我们发布包中所指定的版本,最好不要修改。
-----Original Message----- If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/jdbc-record-tp871p873.html
To start a new topic under ngrinder-user-cn, email [hidden email]
To unsubscribe from ngrinder-user-cn, click here. NAML |
Administrator
|
In reply to this post by ypspace
If you're using groovy... you can use the following code. it's much easier.
package org.ngrinder; import static net.grinder.script.Grinder.grinder import static org.junit.Assert.* import static org.hamcrest.Matchers.* import net.grinder.script.GTest import net.grinder.script.Grinder import net.grinder.scriptengine.groovy.junit.GrinderRunner import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread import org.junit.Before import org.junit.BeforeClass import org.junit.Test import org.junit.runner.RunWith import groovy.sql.Sql /** * A simple example using the Groovy SQL that shows the retrieval of a * Simple query. * * This script is automatically generated by ngrinder. * * @author 김성규 */ @RunWith(GrinderRunner) class TestRunner { public static GTest test public static sql @BeforeProcess public static void beforeProcess() { test = new GTest(1, "Test1") sql = Sql.newInstance( 'jdbc:cubrid:<DB Host>:<DB Port>:demodb:::', 'public', '', 'cubrid.jdbc.driver.CUBRIDDriver' ) test.record(sql); grinder.logger.info("before process."); } @BeforeThread public void beforeThread() { grinder.statistics.delayReports=true; grinder.logger.info("before thread."); } @Test public void test(){ sql.eachRow( 'select * from code' ) { println "$it.s_name -- ${it.f_name} --" } } } |
In reply to this post by Mavlarn
我使用ngrinder平台验证此脚本,得到的结果也是没有test1的数据,不知道问题出在哪里了。
|
这是用Juno 提供的Groovy 脚本 运行的效果图,只改了驱动程序和查询的表,其他没有改动。
|
In reply to this post by Mavlarn
使用这个脚本:
import static net.grinder.script.Grinder.grinder import static org.junit.Assert.* import static org.hamcrest.Matchers.* import net.grinder.plugin.http.HTTPRequest import net.grinder.plugin.http.HTTPPluginControl import net.grinder.script.GTest import net.grinder.script.Grinder import net.grinder.scriptengine.groovy.junit.GrinderRunner import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread import static net.grinder.util.GrinderUtils.* // You can use this if you're using nGrinder after 3.2.3 import org.junit.Before import org.junit.BeforeClass import org.junit.Test import org.junit.runner.RunWith import java.util.Date import java.util.List import java.util.ArrayList import HTTPClient.Cookie import HTTPClient.CookieModule import HTTPClient.HTTPResponse import HTTPClient.NVPair import java.sql.DriverManager import java.sql.SQLException import java.sql.Statement import java.sql.ResultSet import com.mysql.jdbc.Connection import com.didi.utils.GCounter import com.didi.utils.JavaStackTrace /** * A simple example using the HTTP plugin that shows the retrieval of a * single page via HTTP. * * This script is automatically generated by ngrinder. * * @author admin */ @RunWith(GrinderRunner) class TestRunner { public static String msg public static GTest test public static HTTPRequest request public static NVPair[] headers = [] public static NVPair[] params = [] public static Cookie[] cookies = [] //增加数据 public static Boolean addUser(){ Connection con = null Statement stmt = null ResultSet rs = null boolean status=true String msg="" //def GCounter de=new GCounter(); int agentNumber = grinder.agentNumber int processNumber = grinder.processNumber int threadNumber = grinder.threadNumber //long threadId = GrinderUtils.threadUniqId String counter=GCounter.getIstance(processNumber); try{ Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://10.94.66.30:3309/zblog", "root", "123456"); stmt = con.createStatement(); //stmt = con.createStatement(); String name="A_"+counter+"|"+agentNumber+"_"+processNumber+"_"+threadNumber; String pass="PW_"+counter; String sql="insert into user(`username`,`password`) values ('"+name+"','"+pass+"')"; stmt.executeUpdate(sql); }catch(SQLException e){ status=false; msg=JavaStackTrace.errorStack2String(e); grinder.logger.info("错误:"+msg); }catch(ClassNotFoundException e){ status=false; msg=JavaStackTrace.errorStack2String(e); grinder.logger.info("错误:"+msg); }finally{ try{stmt.close();}catch(Exception e){} try{con.close();}catch(Exception e){} } return status } public static void jdbcTest() { Connection con = null; Statement stmt = null; ResultSet rs = null; try{ Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://10.94.66.30:3309/zblog", "root", "123456"); stmt = con.createStatement(); rs = stmt.executeQuery("select * from user"); while (rs.next()) { System.out.println("user id: " + rs.getLong(1) + " username: " + rs.getString(2) + " pass: " + rs.getString(3)); } }catch(SQLException e){ e.printStackTrace(); }catch(ClassNotFoundException e){ e.printStackTrace(); }finally{ try{rs.close();}catch(Exception e){} try{stmt.close();}catch(Exception e){} try{con.close();}catch(Exception e){} } } @BeforeProcess public static void beforeProcess() { HTTPPluginControl.getConnectionDefaults().timeout = 6000 test = new GTest(1, "Test1") request = new HTTPRequest() grinder.logger.info("before process."); } @BeforeThread public void beforeThread() { test.record(this, "test") grinder.statistics.delayReports=true; grinder.logger.info("before thread."); } @Before public void before() { request.setHeaders(headers) cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) } grinder.logger.info("before thread. init headers and cookies"); } @Test public void test(){ //HTTPResponse result = request.GET("http://10.94.120.205:8866/ci/login?from=%2Fci%2F", params) //jdbcTest(); def status=addUser(); if(status==false){ grinder.logger.info("添加用户失败。。。"); assertThat(100, is(200)); }else{ assertThat(200, is(200)); } //if (result.statusCode == 301 || result.statusCode == 302 || result.statusCode == 403 || status==false) { // grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode); //} else { // //} } } |
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>ngrinder</groupId> <artifactId>Test1</artifactId> <version>0.0.1</version> <properties> <ngrinder.version>3.4</ngrinder.version> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <repositories> <repository> <id>ngrinder.maven.repo</id> <url>https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.ngrinder</groupId> <artifactId>ngrinder-groovy</artifactId> <version>${ngrinder.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.9</version> <configuration> <additionalProjectnatures> <projectnature> org.eclipse.jdt.groovy.core.groovyNature </projectnature> <projectnature> org.eclipse.m2e.core.maven2Nature </projectnature> </additionalProjectnatures> </configuration> </plugin> </plugins> </build> </project> |
Free forum by Nabble | Edit this page |