99import com .clickhouse .client .ClickHouseNode ;
1010import com .clickhouse .client .ClickHouseProtocol ;
1111import com .clickhouse .client .ClickHouseResponse ;
12+ import com .clickhouse .client .ClickHouseServerForTest ;
1213import com .clickhouse .client .api .Client ;
1314import com .clickhouse .client .api .enums .Protocol ;
1415import com .clickhouse .client .api .insert .InsertResponse ;
1819import com .clickhouse .data .ClickHouseOutputStream ;
1920import com .clickhouse .data .ClickHouseRecord ;
2021import com .clickhouse .data .format .ClickHouseRowBinaryProcessor ;
22+ import com .clickhouse .jdbc .ClickHouseDriver ;
2123import org .openjdk .jmh .annotations .Level ;
2224import org .openjdk .jmh .annotations .Param ;
2325import org .openjdk .jmh .annotations .Scope ;
3133import java .io .InputStream ;
3234import java .math .BigInteger ;
3335import java .nio .ByteBuffer ;
36+ import java .sql .Connection ;
37+ import java .sql .SQLException ;
3438import java .util .ArrayList ;
3539import java .util .Collections ;
3640import java .util .List ;
41+ import java .util .Properties ;
3742
3843import static com .clickhouse .benchmark .BenchmarkRunner .getSelectCountQuery ;
3944import static com .clickhouse .benchmark .BenchmarkRunner .getSyncQuery ;
4853@ State (Scope .Benchmark )
4954public class BenchmarkBase {
5055 private static final Logger LOGGER = LoggerFactory .getLogger (BenchmarkBase .class );
51-
5256 protected ClickHouseClient clientV1 ;
5357 protected Client clientV2 ;
58+ protected static Connection jdbcV1 = null ;
59+ protected static Connection jdbcV2 = null ;
60+
5461 @ Setup (Level .Iteration )
55- public void setUpIteration () {
62+ public void setUpIteration () throws SQLException {
5663 clientV1 = getClientV1 ();
5764 clientV2 = getClientV2 ();
58-
65+ jdbcV1 = getJdbcV1 ();
66+ jdbcV2 = getJdbcV2 ();
5967 }
6068
6169 @ TearDown (Level .Iteration )
62- public void tearDownIteration () {
70+ public void tearDownIteration () throws SQLException {
6371 if (clientV1 != null ) {
6472 clientV1 .close ();
6573 clientV1 = null ;
@@ -68,6 +76,14 @@ public void tearDownIteration() {
6876 clientV2 .close ();
6977 clientV2 = null ;
7078 }
79+ if (jdbcV1 != null ) {
80+ jdbcV1 .close ();
81+ jdbcV1 = null ;
82+ }
83+ if (jdbcV2 != null ) {
84+ jdbcV2 .close ();
85+ jdbcV2 = null ;
86+ }
7187 }
7288
7389 @ State (Scope .Benchmark )
@@ -224,6 +240,28 @@ protected static Client getClientV2(boolean includeDb) {
224240 .build ();
225241 }
226242
243+ protected static Connection getJdbcV1 () throws SQLException {
244+ Properties properties = new Properties ();
245+ properties .put ("user" , getUsername ());
246+ properties .put ("password" , getPassword ());
247+
248+ ClickHouseNode node = ClickHouseServerForTest .getClickHouseNode (ClickHouseProtocol .HTTP , ClickHouseServerForTest .isCloud (), ClickHouseNode .builder ().build ());
249+ LOGGER .info (String .format ("clickhouse endpoint [%s:%s]" , node .getHost (), node .getPort ()));
250+ Connection jdbcV1 = new ClickHouseDriver ().connect (String .format ("jdbc:clickhouse://%s:%s?clickhouse.jdbc.v1=true" , node .getHost (), node .getPort ()), properties );
251+ return jdbcV1 ;
252+ }
253+ protected static Connection getJdbcV2 () throws SQLException {
254+ Properties properties = new Properties ();
255+ properties .put ("user" , getUsername ());
256+ properties .put ("password" , getPassword ());
257+
258+ ClickHouseNode node = ClickHouseServerForTest .getClickHouseNode (ClickHouseProtocol .HTTP , ClickHouseServerForTest .isCloud (), ClickHouseNode .builder ().build ());
259+ LOGGER .info (String .format ("clickhouse endpoint [%s:%s]" , node .getHost (), node .getPort ()));
260+
261+ Connection jdbcV2 = new ClickHouseDriver ().connect (String .format ("jdbc:clickhouse://%s:%s" , node .getHost (), node .getPort ()), properties );
262+ return jdbcV2 ;
263+ }
264+
227265 public static void loadClickHouseRecords (DataState dataState ) {
228266 syncQuery (dataState .tableNameFilled );
229267
0 commit comments