77import  org .openjdk .jmh .annotations .*;
88
99import  java .sql .Connection ;
10+ import  java .sql .DriverManager ;
1011import  java .sql .SQLException ;
12+ import  java .sql .Statement ;
1113import  java .util .Properties ;
1214import  java .util .concurrent .TimeUnit ;
1315
2022@ OutputTimeUnit (TimeUnit .SECONDS )
2123public  class  Common  {
2224
25+  // conf 
26+  public  final  static  String  host  = System .getProperty ("TEST_HOST" , "localhost" );
27+  public  final  static  int  port  = Integer .parseInt (System .getProperty ("TEST_PORT" , "3306" ));
28+  public  final  static  String  username  = System .getProperty ("TEST_USERNAME" , "root" );
29+  public  final  static  String  password  = System .getProperty ("TEST_PASSWORD" , "" );
30+  public  final  static  String  database  = System .getProperty ("TEST_DATABASE" , "testj" );
31+  public  final  static  String  other  = System .getProperty ("TEST_OTHER" , "" );
32+  static  {
33+  new  SetupData ();
34+  }
35+ 
2336 @ State (Scope .Thread )
2437 public  static  class  MyState  {
2538
26-  // conf 
27-  public  final  String  host  = System .getProperty ("TEST_HOST" , "localhost" );
28-  public  final  int  port  = Integer .parseInt (System .getProperty ("TEST_PORT" , "3306" ));
29-  public  final  String  username  = System .getProperty ("TEST_USERNAME" , "root" );
30-  public  final  String  password  = System .getProperty ("TEST_PASSWORD" , "" );
31-  public  final  String  database  = System .getProperty ("TEST_DATABASE" , "testj" );
3239 // connections 
3340 protected  Connection  connectionText ;
3441 protected  Connection  connectionBinary ;
@@ -37,7 +44,7 @@ public static class MyState {
3744 String  driver ;
3845
3946 @ Setup (Level .Trial )
40-  public  void  doSetup () throws  Exception  {
47+  public  void  createConnections () throws  Exception  {
4148
4249 String  className ;
4350 switch  (driver ) {
@@ -51,21 +58,21 @@ public void doSetup() throws Exception {
5158 throw  new  RuntimeException ("wrong param" );
5259 }
5360 try  {
54-  String  jdbcBase  = "%s:%s /%s?user=%s&password=%s&sslMode=DISABLED&useServerPrepStmts=%s&cachePrepStmts=%s&serverTimezone=UTC" ;
61+  String  jdbcBase  = "jdbc: %s://%s:%s /%s?user=%s&password=%s&sslMode=DISABLED&useServerPrepStmts=%s&cachePrepStmts=%s&serverTimezone=UTC&%s " ;
5562 String  jdbcUrlText  =
5663 String .format (
5764 jdbcBase ,
58-  host , port , database , username , password , false , false );
65+  driver ,  host , port , database , username , password , false , false ,  other );
5966 String  jdbcUrlBinary  =
6067 String .format (
6168 jdbcBase ,
62-  host , port , database , username , password , true , true );
69+  driver ,  host , port , database , username , password , true , true ,  other );
6370 connectionText  =
6471 ((java .sql .Driver ) Class .forName (className ).getDeclaredConstructor ().newInstance ())
65-  .connect ("jdbc:"  +  driver  +  "://"  +  jdbcUrlText , new  Properties ());
72+  .connect (jdbcUrlText , new  Properties ());
6673 connectionBinary  =
6774 ((java .sql .Driver ) Class .forName (className ).getDeclaredConstructor ().newInstance ())
68-  .connect ("jdbc:"  +  driver  +  "://"  +  jdbcUrlBinary , new  Properties ());
75+  .connect (jdbcUrlBinary , new  Properties ());
6976 } catch  (SQLException  e ) {
7077 e .printStackTrace ();
7178 throw  new  RuntimeException (e );
@@ -78,4 +85,32 @@ public void doTearDown() throws SQLException {
7885 connectionBinary .close ();
7986 }
8087 }
88+ 
89+  public  static  class  SetupData  {
90+  static  {
91+  try  {
92+  try  (Connection  conn  =
93+  DriverManager .getConnection (
94+  String .format (
95+  "jdbc:mariadb://%s:%s/%s?user=%s&password=%s" ,
96+  host , port , database , username , password ))) {
97+  Statement  stmt  = conn .createStatement ();
98+  stmt .executeUpdate ("DROP TABLE IF EXISTS test100" );
99+  StringBuilder  sb  = new  StringBuilder ("CREATE TABLE test100 (i1 int" );
100+  StringBuilder  sb2  = new  StringBuilder ("INSERT INTO test100 value (1" );
101+  for  (int  i  = 2 ; i  <= 100 ; i ++) {
102+  sb .append (",i" ).append (i ).append (" int" );
103+  sb2 .append ("," ).append (i );
104+  }
105+  sb .append (")" );
106+  sb2 .append (")" );
107+  stmt .executeUpdate (sb .toString ());
108+  stmt .executeUpdate (sb2 .toString ());
109+  }
110+  } catch  (SQLException  e ) {
111+  e .printStackTrace ();
112+  }
113+  }
114+  }
115+ 
81116}
0 commit comments