Skip to content

Commit 2f05c39

Browse files
authored
Test: Add clickhouse-core-it moudule (#260)
1 parent e8dab70 commit 2f05c39

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,25 @@ project(':clickhouse-core') {
170170
}
171171
}
172172

173+
project(":clickhouse-core-it") {
174+
dependencies {
175+
implementation "org.scala-lang:scala-library:$scala_version" // for scala plugin detect scala binary version
176+
177+
testImplementation(testFixtures(project(":clickhouse-core")))
178+
179+
testImplementation("com.clickhouse:clickhouse-jdbc:$clickhouse_jdbc_version:all") { transitive = false }
180+
testImplementation "org.slf4j:slf4j-log4j12:$slf4j_version"
181+
}
182+
183+
test {
184+
classpath += files("${project(':clickhouse-core').projectDir}/src/testFixtures/conf")
185+
}
186+
187+
slowTest {
188+
classpath += files("${project(':clickhouse-core').projectDir}/src/testFixtures/conf")
189+
}
190+
}
191+
173192
boolean isVersionFileExists() {
174193
return file("version.txt").exists()
175194
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# https://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License. See accompanying LICENSE file.
13+
#
14+
15+
log4j.rootLogger=INFO, console
16+
17+
log4j.appender.console=org.apache.log4j.ConsoleAppender
18+
log4j.appender.console.target=System.out
19+
log4j.appender.console.layout=org.apache.log4j.PatternLayout
20+
log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss.SSS} %p %c: %m%n
21+
22+
log4j.logger.org.apache.hadoop.util.Shell=ERROR
23+
log4j.logger.org.apache.hadoop.util.NativeCodeLoader=ERROR
24+
log4j.logger.xenon.clickhouse=DEBUG
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* https://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package xenon.clickhouse
16+
17+
import xenon.clickhouse.base.ClickHouseSingleMixIn
18+
19+
import java.time.{LocalDateTime, ZoneId}
20+
21+
class UtilsClickHouseSuite extends ClickHouseSingleMixIn with Logging {
22+
23+
test("parse date with nano seconds") {
24+
withNodeClient() { client =>
25+
val tz = ZoneId.systemDefault()
26+
val sql = s"SELECT toDateTime64('2023-03-29 15:25:25.977654', 3, '$tz')"
27+
val output = client.syncQueryAndCheckOutputJSONCompactEachRowWithNamesAndTypes(sql)
28+
assert(output.rows === 1L)
29+
val row = output.records.head
30+
assert(row.length === 1L)
31+
val actual = LocalDateTime.parse(row.head.asText, Utils.dateTimeFmt)
32+
val expected = LocalDateTime.of(2023, 3, 29, 15, 25, 25, 977000000)
33+
assert(actual === expected)
34+
}
35+
}
36+
}

clickhouse-core/src/testFixtures/scala/xenon/clickhouse/base/ClickHouseSingleMixIn.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414

1515
package xenon.clickhouse.base
1616

17+
import com.clickhouse.client.ClickHouseProtocol
18+
import com.clickhouse.client.ClickHouseProtocol._
1719
import com.clickhouse.data.ClickHouseVersion
1820
import com.dimafeng.testcontainers.{ForAllTestContainer, JdbcDatabaseContainer, SingleContainer}
1921
import org.scalatest.funsuite.AnyFunSuite
2022
import org.testcontainers.containers.ClickHouseContainer
2123
import org.testcontainers.utility.{DockerImageName, MountableFile}
2224
import xenon.clickhouse.Utils
25+
import xenon.clickhouse.client.NodeClient
26+
import xenon.clickhouse.spec.NodeSpec
2327

2428
import java.nio.file.{Path, Paths}
2529

@@ -73,4 +77,11 @@ trait ClickHouseSingleMixIn extends AnyFunSuite with ForAllTestContainer {
7377
def clickhouseHttpPort: Int = container.mappedPort(CLICKHOUSE_HTTP_PORT)
7478
def clickhouseTcpPort: Int = container.mappedPort(CLICKHOUSE_TPC_PORT)
7579
// format: on
80+
81+
def withNodeClient(protocol: ClickHouseProtocol = HTTP)(block: NodeClient => Unit): Unit =
82+
Utils.tryWithResource {
83+
NodeClient(NodeSpec(clickhouseHost, Some(clickhouseHttpPort), Some(clickhouseTcpPort), protocol))
84+
} {
85+
client => block(client)
86+
}
7687
}

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
rootProject.name = 'spark-clickhouse-connector'
1616

1717
include ":clickhouse-core"
18+
include ":clickhouse-core-it"
1819

1920
List<String> knownScalaBinaryVersions = System.getProperty("known_scala_binary_versions").split(",")
2021
String scala_binary_version = System.getProperty("scala_binary_version")

0 commit comments

Comments
 (0)