Ngrinder Testrunnerinsertmysqlmore2.groovy

Source: Internet
Author: User
Tags stmt stringbuffer

S

C:\Users\Lindows\IdeaProjects\TestGroovy\src\com\iteye\lindows\TestRunnerInsert.groovy

Package Com.iteye.lindows;import Junit.framework.Assertimport Net.grinder.script.GTestimport Net.grinder.scriptengine.groovy.junit.GrinderRunnerimport Net.grinder.scriptengine.groovy.junit.annotation.AfterThreadimport Net.grinder.scriptengine.groovy.junit.annotation.BeforeProcessimport Net.grinder.scriptengine.groovy.junit.annotation.BeforeThreadimport Org.junit.Testimport Org.junit.runner.RunWithimport Java.sql.Connectionimport Java.sql.DriverManagerimport Java.sql.Statementimport static Net.grinder.script.Grinder.grinderimport Static org.junit.assert.asserttrue/** * Java code example, connection database for query * * @author Lindows */@RunWith (Grinderrunner) class Testrunnerinsert {public static gtest inserttable public static Connection C    Onn; public static Statement stmt; Create statement object public static list<string> dblinelist;    Prepare parameterized Data Objects public static filerownnumber; @BeforeProcess public static void Beforeprocess () {inserttable = new Gtest (1, "Insert table data") Dblinelist = new File ("C:/users/lindows/ideaprojects/testgroovy/src/resources/database.txt"). ReadLines ("UTF-8") System.out.println ("Tangxje:" + dblinelist.size ()) Filerownnumber = new Random (). Nextint (Dblinelist.size ()-1) +1/        /file Database.txt, including Titile line 0, total 10 rows. Method Two, get directly (the number of lines of file, such as: 10 lines-1) =9 fill in the following, Nextint from 0~8 value//filerownnumber = new Random (). Nextint (9) Grinder.logger.info ( "Tangxje::" + filerownnumber) try {//Call Class.forName () method to load driver Class.forName ("Com.mysql.jd Bc.            Driver "); Grinder.logger.info ("Load MySQL driver successfully!")            ");    /* String url= "jdbc:mysql://10.244.73.65:3306/performance_test";             The URL of the JDBC String username = "Fabu";            String passwd = "[email protected]";            */String URL = dblinelist.get (Filerownnumber). Split (",") [0];            String username = dblinelist.get (filerownnumber). Split (",") [1];      String passwd = Dblinelist.get (Filerownnumber). Split (",") [2];      Grinder.logger.debug (URL) conn = drivermanager.getconnection (URL, username, passwd); stmt = Conn.createstatement (); Create the Statement object Grinder.logger.info ("successfully created stmt!        ");        } catch (Exception e) {e.printstacktrace ()}} @BeforeThread public void Beforethread () { Inserttable.record (This, "inserttable") grinder.statistics.delayreports=true} @Test public void insert Table () {try{Grinder.logger.info ("Successfully connected to the database!            "); StringBuffer sql = new StringBuffer () sql.append ("INSERT INTO tab_001 (column_int,column_double,column_decimal,c Olumn_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 Ran Dom (). Nextint (99999999)). Append ("', ' work on 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))//Can be set here            Think Time 10ms asserttrue (!stmt.execute (sql.tostring ())//Execute SQL Insert,!stmt.execute (SQL) This notation is only true when the insert is confirmed            Asserttrue (Stmt.execute (SQL));//Execute SQL query,!stmt.execute (SQL) This notation only applies to query true to confirm}catch (Exception e) {        E.printstacktrace ();        }} @AfterThread public void Afterthread () {stmt.close ();    Conn.close (); }}

  

C:\Users\Lindows\IdeaProjects\TestGroovy\src\resources\database.txt

Url,username,passwordjdbc:mysql://10.244.73.65:3306/performance_test,root,[email protected]jdbc:mysql:// 10.244.73.65:3306/performance_test,root,[email protected]jdbc:mysql://10.244.73.65:3306/performance_test,root,[ Email protected]

C:\Users\Lindows\Desktop\dev\ptsp_lib\

1 Antlr-2.7.7.jar2 Asm-3.3.1.jar3 Commons-collections-3.2.1.jar4 Commons-compress-1.4.1.jar5 Commons-io-2.0.1.jar6 Commons-lang-2.6.jar7 Commons-math3-3.6.1.jar8 Dnsjava-2.1.1.jar9 Dom4j-1.6.1.jarTen Grinder-core-3.9.1.jar One Grinder-dcr-agent-3.9.1.jar A Grinder-http-3.9.1.jar - Grinder-http-patch-3.9.1-patch.jar - Grinder-httpclient-3.9.1.jar the Grinder-httpclient-patch-3.9.1-patch.jar - Grinder-patch-3.9.1-patch.jar - Groovy-all-2.2.1.jar - Gson-2.2.jar + Hamcrest-all-1.1.jar - Hibernate-commons-annotations-4.0.2.final.jar + Hibernate-core-4.2.2.final.jar A Java-semver-0.9.0.jar at Javassist-3.15.0-ga.jar - Jboss-transaction-api_1.1_spec-1.0.1.final.jar - Jcl-over-slf4j-1.6.4.jar - Jcommander-1.32.jar - Jna-3.4.0.jar - Json-20090211.jar in Junit-dep-4.11.jar - Jython-standalone-2.5.3.jar to Log4j-1.2.15.jar + Logback-classic-1.0.0.jar - Logback-core-1.0.0.jar the Ls.txt * Mysql-connector-java-5.1.36.jar $ Ngrinder-core-3.4.jarPanax Notoginseng Ngrinder-groovy-3.4.jar - Ngrinder-runtime-3.4.jar the Pf4j-0.12.0.jar + Picocontainer-2.13.6.jar A Sigar-1.6.4.jar the Sigar-native-1.0.jar + Slf4j-api-1.6.4.jar -Xz-1.0.jar

End

Ngrinder Testrunnerinsertmysqlmore2.groovy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.