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,22 @@ 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 );
70+ 
6371 connectionText  =
6472 ((java .sql .Driver ) Class .forName (className ).getDeclaredConstructor ().newInstance ())
65-  .connect ("jdbc:"  +  driver  +  "://"  +  jdbcUrlText , new  Properties ());
73+  .connect (jdbcUrlText , new  Properties ());
6674 connectionBinary  =
6775 ((java .sql .Driver ) Class .forName (className ).getDeclaredConstructor ().newInstance ())
68-  .connect ("jdbc:"  +  driver  +  "://"  +  jdbcUrlBinary , new  Properties ());
76+  .connect (jdbcUrlBinary , new  Properties ());
6977 } catch  (SQLException  e ) {
7078 e .printStackTrace ();
7179 throw  new  RuntimeException (e );
@@ -78,4 +86,45 @@ public void doTearDown() throws SQLException {
7886 connectionBinary .close ();
7987 }
8088 }
89+ 
90+  public  static  class  SetupData  {
91+  static  {
92+  try  {
93+  try  (Connection  conn  =
94+  DriverManager .getConnection (
95+  String .format (
96+  "jdbc:mariadb://%s:%s/%s?user=%s&password=%s" ,
97+  host , port , database , username , password ))) {
98+  Statement  stmt  = conn .createStatement ();
99+  try  {
100+  stmt .executeQuery ("INSTALL SONAME 'ha_blackhole'" );
101+  } catch  (SQLException  e ) {
102+  // eat 
103+  }
104+  stmt .executeUpdate ("DROP TABLE IF EXISTS testBlackHole" );
105+  stmt .executeUpdate ("DROP TABLE IF EXISTS test100" );
106+ 
107+  try  {
108+  stmt .executeUpdate ("CREATE TABLE testBlackHole (id INT, t VARCHAR(256)) ENGINE = BLACKHOLE" );
109+  } catch  (SQLException  e ) {
110+  stmt .executeUpdate ("CREATE TABLE testBlackHole (id INT, t VARCHAR(256))" );
111+  }
112+ 
113+  StringBuilder  sb  = new  StringBuilder ("CREATE TABLE test100 (i1 int" );
114+  StringBuilder  sb2  = new  StringBuilder ("INSERT INTO test100 value (1" );
115+  for  (int  i  = 2 ; i  <= 100 ; i ++) {
116+  sb .append (",i" ).append (i ).append (" int" );
117+  sb2 .append ("," ).append (i );
118+  }
119+  sb .append (")" );
120+  sb2 .append (")" );
121+  stmt .executeUpdate (sb .toString ());
122+  stmt .executeUpdate (sb2 .toString ());
123+  }
124+  } catch  (SQLException  e ) {
125+  e .printStackTrace ();
126+  }
127+  }
128+  }
129+ 
81130}
0 commit comments