Skip to content

Commit 6344de4

Browse files
committed
[pinpoint-apm#9794] Add tests, Change minimum version to 0.3.2
1 parent ed97e0f commit 6344de4

File tree

18 files changed

+632
-146
lines changed

18 files changed

+632
-146
lines changed

plugins-it/clickhouse-jdbc-it/pom.xml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2018 NAVER Corp.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>com.navercorp.pinpoint</groupId>
23+
<artifactId>pinpoint-plugins-it</artifactId>
24+
<version>2.6.0-SNAPSHOT</version>
25+
</parent>
26+
27+
<artifactId>pinpoint-clickhouse-jdbc-plugin-it</artifactId>
28+
29+
<packaging>jar</packaging>
30+
31+
<properties>
32+
<jdk.version>11</jdk.version>
33+
<jdk.home>${env.JAVA_11_HOME}</jdk.home>
34+
</properties>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>com.navercorp.pinpoint</groupId>
39+
<artifactId>pinpoint-plugin-it-utils</artifactId>
40+
<version>${project.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.navercorp.pinpoint</groupId>
44+
<artifactId>pinpoint-plugin-it-utils-jdbc</artifactId>
45+
<version>${project.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.navercorp.pinpoint</groupId>
49+
<artifactId>pinpoint-clickhouse-jdbc-driver-plugin</artifactId>
50+
<version>${project.version}</version>
51+
</dependency>
52+
<!-- testcontainers -->
53+
<dependency>
54+
<groupId>org.testcontainers</groupId>
55+
<artifactId>testcontainers</artifactId>
56+
<version>${testcontainers.version}</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.testcontainers</groupId>
60+
<artifactId>clickhouse</artifactId>
61+
<version>1.19.0</version>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>com.clickhouse</groupId>
66+
<artifactId>clickhouse-jdbc</artifactId>
67+
<version>0.3.2-patch11</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>com.zaxxer</groupId>
71+
<artifactId>HikariCP</artifactId>
72+
<scope>compile</scope>
73+
</dependency>
74+
</dependencies>
75+
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-surefire-plugin</artifactId>
81+
<configuration>
82+
<skip>true</skip>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-failsafe-plugin</artifactId>
88+
<configuration>
89+
<jvm>${env.JAVA_8_HOME}/bin/java</jvm>
90+
</configuration>
91+
</plugin>
92+
</plugins>
93+
</build>
94+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright 2023 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.it.plugin.jdbc.clickhouse;
17+
18+
import com.clickhouse.jdbc.ClickHouseConnection;
19+
import com.clickhouse.jdbc.ClickHouseStatement;
20+
import org.apache.logging.log4j.LogManager;
21+
import org.apache.logging.log4j.Logger;
22+
23+
import java.sql.PreparedStatement;
24+
import java.sql.ResultSet;
25+
import java.sql.SQLException;
26+
import java.util.Collections;
27+
28+
/**
29+
* @author intr3p1d
30+
*/
31+
public class ClickHouseITBase {
32+
private final Logger logger = LogManager.getLogger(getClass());
33+
static final String TABLE_NAME = "jdbc_example_basic";
34+
35+
public ClickHouseITBase() {
36+
}
37+
38+
public int dropAndCreateTable(ClickHouseConnection conn) throws SQLException {
39+
try (ClickHouseStatement stmt = conn.createStatement()) {
40+
// multi-statement query is supported by default
41+
// session will be created automatically during execution
42+
stmt.execute(String.format(
43+
"drop table if exists %1$s; create table %1$s(a String, b Nullable(String)) engine=Memory",
44+
TABLE_NAME));
45+
return stmt.getUpdateCount();
46+
}
47+
}
48+
49+
public int query(ClickHouseConnection conn) throws SQLException {
50+
String sql = "select * from " + TABLE_NAME;
51+
try (ClickHouseStatement stmt = conn.createStatement()) {
52+
// set max_result_rows = 3, result_overflow_mode = 'break'
53+
// or simply discard rows after the first 3 in read-only mode
54+
stmt.setMaxRows(3);
55+
int count = 0;
56+
try (ResultSet rs = stmt.executeQuery(sql)) {
57+
while (rs.next()) {
58+
count++;
59+
}
60+
}
61+
return count;
62+
}
63+
}
64+
65+
public void insertByteArray(ClickHouseConnection conn) throws SQLException {
66+
try (ClickHouseStatement s = conn.createStatement()) {
67+
s.execute("drop table if exists t_map;"
68+
+ "CREATE TABLE t_map"
69+
+ "("
70+
+ " `audit_seq` Int64 CODEC(Delta(8), LZ4),"
71+
+ "`timestamp` Int64 CODEC(Delta(8), LZ4),"
72+
+ "`event_type` LowCardinality(String),"
73+
+ "`event_subtype` LowCardinality(String),"
74+
+ "`actor_type` LowCardinality(String),"
75+
+ "`actor_id` String,"
76+
+ "`actor_tenant_id` LowCardinality(String),"
77+
+ "`actor_tenant_name` String,"
78+
+ "`actor_firstname` String,"
79+
+ "`actor_lastname` String,"
80+
+ "`resource_type` LowCardinality(String),"
81+
+ "`resource_id` String,"
82+
+ "`resource_container` LowCardinality(String),"
83+
+ "`resource_path` String,"
84+
+ "`origin_ip` String,"
85+
+ "`origin_app_name` LowCardinality(String),"
86+
+ "`origin_app_instance` String,"
87+
+ "`description` String,"
88+
+ "`attributes` Map(String, String)"
89+
+ ")"
90+
+ "ENGINE = MergeTree "
91+
+ "ORDER BY (resource_container, event_type, event_subtype) "
92+
+ "SETTINGS index_granularity = 8192");
93+
try (PreparedStatement stmt = conn.prepareStatement(
94+
"INSERT INTO t_map SETTINGS async_insert=1,wait_for_async_insert=1 VALUES (8481365034795008,1673349039830,'operation-9','a','service', 'bc3e47b8-2b34-4c1a-9004-123656fa0000','b', 'c', 'service-56','d', 'object','e', 'my-value-62', 'mypath', 'some.hostname.address.com', 'app-9', 'instance-6','x', ?)")) {
95+
stmt.setObject(1, Collections.singletonMap("key1", "value1"));
96+
stmt.execute();
97+
98+
try (ResultSet rs = s.executeQuery("select attributes from t_map")) {
99+
logger.info(rs.next());
100+
logger.info(rs.getObject(1));
101+
}
102+
}
103+
}
104+
}
105+
106+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2023 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.it.plugin.jdbc.clickhouse;
17+
18+
import com.clickhouse.jdbc.ClickHouseConnection;
19+
import com.clickhouse.jdbc.ClickHouseDriver;
20+
import com.clickhouse.config.ClickHouseOption;
21+
import com.navercorp.pinpoint.it.plugin.utils.jdbc.DriverProperties;
22+
23+
import java.sql.Connection;
24+
import java.sql.SQLException;
25+
import java.util.Objects;
26+
import java.util.Properties;
27+
28+
/**
29+
* @author intr3p1d
30+
*/
31+
public class ClickHouseITHelper {
32+
33+
private final String jdbcUrl;
34+
private final String userName;
35+
private final String password;
36+
37+
38+
public ClickHouseITHelper(DriverProperties driverProperties) {
39+
Objects.requireNonNull(driverProperties, "driverProperties");
40+
41+
this.jdbcUrl = driverProperties.getUrl();
42+
this.userName = driverProperties.getUser();
43+
this.password = driverProperties.getPassword();
44+
45+
}
46+
47+
public ClickHouseConnection getConnection() throws SQLException {
48+
ClickHouseDriver driver = new ClickHouseDriver();
49+
Properties properties = new Properties();
50+
properties.put("user", userName);
51+
properties.put("password", password);
52+
53+
// final Connection conn = DriverManager.getConnection(jdbcUrl, userName, password);
54+
final ClickHouseConnection conn = driver.connect(jdbcUrl, properties);
55+
56+
System.out.println("Connected to: " + conn.getMetaData().getURL());
57+
return conn;
58+
}
59+
60+
}
61+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.it.plugin.jdbc.clickhouse;
17+
18+
import com.navercorp.pinpoint.it.plugin.utils.jdbc.testcontainers.DatabaseContainers;
19+
import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle;
20+
import org.junit.jupiter.api.Assumptions;
21+
import org.testcontainers.DockerClientFactory;
22+
import org.testcontainers.clickhouse.ClickHouseContainer;
23+
import org.testcontainers.utility.DockerImageName;
24+
25+
import java.util.Properties;
26+
27+
/**
28+
* @author intr3p1d
29+
*/
30+
public class ClickHouseServer implements SharedTestLifeCycle {
31+
private static final String CLICKHOUSE_IMAGE = "clickhouse/clickhouse-server:23.9.1.1854";
32+
private ClickHouseContainer container;
33+
34+
@Override
35+
public Properties beforeAll() {
36+
Assumptions.assumeTrue(DockerClientFactory.instance().isDockerAvailable(), "Docker not enabled");
37+
container = new ClickHouseContainer(DockerImageName.parse(CLICKHOUSE_IMAGE));
38+
container.withDatabaseName("default");
39+
container.withUsername("default");
40+
container.withPassword("");
41+
container.start();
42+
43+
return DatabaseContainers.toProperties(container);
44+
}
45+
46+
@Override
47+
public void afterAll() {
48+
if (container != null) {
49+
container.stop();
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)