2222import com .clickhouse .data .ClickHouseOutputStream ;
2323import com .clickhouse .data .ClickHouseRecord ;
2424import com .clickhouse .data .format .ClickHouseRowBinaryProcessor ;
25+ import com .clickhouse .jdbc .ClickHouseDriver ;
2526import org .openjdk .jmh .annotations .Level ;
2627import org .openjdk .jmh .annotations .Param ;
2728import org .openjdk .jmh .annotations .Scope ;
3536import java .io .InputStream ;
3637import java .math .BigInteger ;
3738import java .nio .ByteBuffer ;
39+ import java .sql .Connection ;
40+ import java .sql .SQLException ;
3841import java .util .ArrayList ;
3942import java .util .Collections ;
4043import java .util .List ;
44+ import java .util .Properties ;
4145
4246import static com .clickhouse .benchmark .BenchmarkRunner .getSelectCountQuery ;
4347import static com .clickhouse .benchmark .BenchmarkRunner .getSyncQuery ;
@@ -55,15 +59,20 @@ public class BenchmarkBase {
5559
5660 protected ClickHouseClient clientV1 ;
5761 protected Client clientV2 ;
62+ protected static Connection jdbcV1 = null ;
63+ protected static Connection jdbcV2 = null ;
64+
5865 @ Setup (Level .Iteration )
59- public void setUpIteration () {
66+ public void setUpIteration () throws SQLException {
6067 LOGGER .info ("BenchmarkBase::setUpIteration" );
6168 clientV1 = getClientV1 ();
6269 clientV2 = getClientV2 ();
70+ jdbcV1 = getJdbcV1 ();
71+ jdbcV2 = getJdbcV2 ();
6372 }
6473
6574 @ TearDown (Level .Iteration )
66- public void tearDownIteration () {
75+ public void tearDownIteration () throws SQLException {
6776 LOGGER .info ("BenchmarkBase::tearDownIteration" );
6877 if (clientV1 != null ) {
6978 clientV1 .close ();
@@ -73,6 +82,14 @@ public void tearDownIteration() {
7382 clientV2 .close ();
7483 clientV2 = null ;
7584 }
85+ if (jdbcV1 != null ) {
86+ jdbcV1 .close ();
87+ jdbcV1 = null ;
88+ }
89+ if (jdbcV2 != null ) {
90+ jdbcV2 .close ();
91+ jdbcV2 = null ;
92+ }
7693 }
7794
7895 @ State (Scope .Benchmark )
@@ -241,6 +258,29 @@ protected static Client getClientV2(boolean includeDb) {
241258 .build ();
242259 }
243260
261+ protected static Connection getJdbcV1 () throws SQLException {
262+ Properties properties = new Properties ();
263+ properties .put ("user" , getUsername ());
264+ properties .put ("password" , getPassword ());
265+
266+ ClickHouseNode node = getServer ();
267+ LOGGER .info (String .format ("clickhouse endpoint [%s:%s]" , node .getHost (), node .getPort ()));
268+ Connection jdbcV1 = new ClickHouseDriver ().connect (String .format ("jdbc:clickhouse://%s:%s?clickhouse.jdbc.v1=true" , node .getHost (), node .getPort ()), properties );
269+ return jdbcV1 ;
270+ }
271+
272+ protected static Connection getJdbcV2 () throws SQLException {
273+ Properties properties = new Properties ();
274+ properties .put ("user" , getUsername ());
275+ properties .put ("password" , getPassword ());
276+
277+ ClickHouseNode node = getServer ();
278+ LOGGER .info (String .format ("clickhouse endpoint [%s:%s]" , node .getHost (), node .getPort ()));
279+
280+ Connection jdbcV2 = new ClickHouseDriver ().connect (String .format ("jdbc:clickhouse://%s:%s" , node .getHost (), node .getPort ()), properties );
281+ return jdbcV2 ;
282+ }
283+
244284 public static void loadClickHouseRecords (DataState dataState ) {
245285 syncQuery (dataState .tableNameFilled );
246286
0 commit comments