BentsiLeviav commented on code in PR #37611:
URL: https://github.com/apache/beam/pull/37611#discussion_r2812752148
##########
sdks/java/io/clickhouse/src/test/java/org/apache/beam/sdk/io/clickhouse/BaseClickHouseTest.java:
##########
@@ -72,45 +77,130 @@ public static void setup() throws IOException,
InterruptedException {
;
clickHouse.start();
LOG.info("Start Clickhouse");
+ clickHouseUrl = "http://" + clickHouse.getHost() + ":" +
clickHouse.getMappedPort(HTTP_PORT);
+ database = "default";
}
@AfterClass
public static void tearDown() {
- clickHouse.close();
- zookeeper.close();
+ if (clickHouse != null) {
+ clickHouse.close();
+ }
+ if (zookeeper != null) {
+ zookeeper.close();
+ }
}
@Before
- public void setUp() throws SQLException {
- connection = clickHouse.createConnection("");
+ public void setUp() throws Exception {
+ // Create ClickHouse Java Client
+ Client.Builder clientBuilder =
+ new Client.Builder()
+ .addEndpoint(clickHouseUrl)
+ .setUsername(clickHouse.getUsername())
+ .setPassword(clickHouse.getPassword())
+ .setDefaultDatabase(database);
+
+ client = clientBuilder.build();
}
@After
public void after() {
- if (connection != null) {
+ if (client != null) {
try {
- connection.close();
- } catch (SQLException e) {
- // failed to close connection, ignore
+ client.close();
+ } catch (Exception e) {
+ LOG.warn("Failed to close ClickHouse client", e);
} finally {
- connection = null;
+ client = null;
}
}
}
- boolean executeSql(String sql) throws SQLException {
- Statement statement = connection.createStatement();
- return statement.execute(sql);
+ /**
+ * Executes a SQL statement (DDL, DML, etc.).
+ *
+ * @param sql SQL statement to execute
+ * @return true if execution was successful
+ * @throws Exception if execution fails
+ */
+ boolean executeSql(String sql) throws Exception {
+ try {
+ client.query(sql).get(30, TimeUnit.SECONDS);
Review Comment:
Done
##########
sdks/java/io/clickhouse/src/test/java/org/apache/beam/sdk/io/clickhouse/AtomicInsertTest.java:
##########
@@ -55,7 +54,7 @@ private static boolean shouldAttempt(int i, long count) {
/** With sufficient block size, ClickHouse will atomically insert all or
nothing. */
@Test
- public void testAtomicInsert() throws SQLException {
+ public void testAtomicInsert() throws Exception {
int size = 100000;
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]