Skip to content

Commit

Permalink
Test: Add clickhouse-core-it moudule (ClickHouse#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
pan3793 authored Jul 20, 2023
1 parent e8dab70 commit 2f05c39
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ project(':clickhouse-core') {
}
}

project(":clickhouse-core-it") {
dependencies {
implementation "org.scala-lang:scala-library:$scala_version" // for scala plugin detect scala binary version

testImplementation(testFixtures(project(":clickhouse-core")))

testImplementation("com.clickhouse:clickhouse-jdbc:$clickhouse_jdbc_version:all") { transitive = false }
testImplementation "org.slf4j:slf4j-log4j12:$slf4j_version"
}

test {
classpath += files("${project(':clickhouse-core').projectDir}/src/testFixtures/conf")
}

slowTest {
classpath += files("${project(':clickhouse-core').projectDir}/src/testFixtures/conf")
}
}

boolean isVersionFileExists() {
return file("version.txt").exists()
}
Expand Down
24 changes: 24 additions & 0 deletions clickhouse-core-it/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. See accompanying LICENSE file.
#

log4j.rootLogger=INFO, console

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss.SSS} %p %c: %m%n

log4j.logger.org.apache.hadoop.util.Shell=ERROR
log4j.logger.org.apache.hadoop.util.NativeCodeLoader=ERROR
log4j.logger.xenon.clickhouse=DEBUG
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package xenon.clickhouse

import xenon.clickhouse.base.ClickHouseSingleMixIn

import java.time.{LocalDateTime, ZoneId}

class UtilsClickHouseSuite extends ClickHouseSingleMixIn with Logging {

test("parse date with nano seconds") {
withNodeClient() { client =>
val tz = ZoneId.systemDefault()
val sql = s"SELECT toDateTime64('2023-03-29 15:25:25.977654', 3, '$tz')"
val output = client.syncQueryAndCheckOutputJSONCompactEachRowWithNamesAndTypes(sql)
assert(output.rows === 1L)
val row = output.records.head
assert(row.length === 1L)
val actual = LocalDateTime.parse(row.head.asText, Utils.dateTimeFmt)
val expected = LocalDateTime.of(2023, 3, 29, 15, 25, 25, 977000000)
assert(actual === expected)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

package xenon.clickhouse.base

import com.clickhouse.client.ClickHouseProtocol
import com.clickhouse.client.ClickHouseProtocol._
import com.clickhouse.data.ClickHouseVersion
import com.dimafeng.testcontainers.{ForAllTestContainer, JdbcDatabaseContainer, SingleContainer}
import org.scalatest.funsuite.AnyFunSuite
import org.testcontainers.containers.ClickHouseContainer
import org.testcontainers.utility.{DockerImageName, MountableFile}
import xenon.clickhouse.Utils
import xenon.clickhouse.client.NodeClient
import xenon.clickhouse.spec.NodeSpec

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

Expand Down Expand Up @@ -73,4 +77,11 @@ trait ClickHouseSingleMixIn extends AnyFunSuite with ForAllTestContainer {
def clickhouseHttpPort: Int = container.mappedPort(CLICKHOUSE_HTTP_PORT)
def clickhouseTcpPort: Int = container.mappedPort(CLICKHOUSE_TPC_PORT)
// format: on

def withNodeClient(protocol: ClickHouseProtocol = HTTP)(block: NodeClient => Unit): Unit =
Utils.tryWithResource {
NodeClient(NodeSpec(clickhouseHost, Some(clickhouseHttpPort), Some(clickhouseTcpPort), protocol))
} {
client => block(client)
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
rootProject.name = 'spark-clickhouse-connector'

include ":clickhouse-core"
include ":clickhouse-core-it"

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

0 comments on commit 2f05c39

Please sign in to comment.