Skip to content

Commit 9e543e8

Browse files
authored
Merge pull request #764 from zhicwu/fix-build
Fix build failure on JDK 8
2 parents de411cc + 05e89d8 commit 9e543e8

6 files changed

Lines changed: 96 additions & 74 deletions

File tree

.github/toolchains.xml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
mvn --batch-mode --update-snapshots -q -DskipTests install
6363
cd clickhouse-benchmark
6464
java -DclickhouseVersion="21.8" -jar target/benchmarks.jar -rf text \
65-
-p client=clickhouse-http-jdbc -p type=default Basic
65+
-p client=clickhouse-http-jdbc -p client=clickhouse-grpc-jdbc -p type=default Basic
6666
echo "BENCHMARK_REPORT<<EOF" >> $GITHUB_ENV
6767
cat jmh-result.text >> $GITHUB_ENV
6868
echo "EOF" >> $GITHUB_ENV

.github/workflows/build.yml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ jobs:
3232
runs-on: ubuntu-latest
3333
strategy:
3434
matrix:
35-
java: [8, 11, 17]
3635
# most recent LTS releases as well as latest stable builds
3736
clickhouse: ["21.3", "21.8", "latest"]
3837
fail-fast: false
39-
name: Build using JDK ${{ matrix.java }} against ClickHouse ${{ matrix.clickhouse }}
38+
name: Build against ClickHouse ${{ matrix.clickhouse }}
4039
steps:
4140
- name: Check out Git repository
4241
uses: actions/checkout@v2
@@ -45,10 +44,34 @@ jobs:
4544
git fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 \
4645
origin pull/${{ github.event.inputs.pr }}/merge:merged-pr && git checkout merged-pr
4746
if: github.event.inputs.pr != ''
48-
- name: Set up JDK ${{ matrix.java }}
49-
uses: actions/setup-java@v1
47+
- name: Install JDK 11
48+
uses: AdoptOpenJDK/install-jdk@v1
5049
with:
51-
java-version: ${{ matrix.java }}
50+
version: '11'
51+
targets: 'JDK11_HOME'
52+
- name: Setup Toolchain
53+
shell: bash
54+
run: |
55+
mkdir -p $HOME/.m2 \
56+
&& cat << EOF > $HOME/.m2/toolchains.xml
57+
<?xml version="1.0" encoding="UTF8"?>
58+
<toolchains>
59+
<toolchain>
60+
<type>jdk</type>
61+
<provides>
62+
<version>11</version>
63+
</provides>
64+
<configuration>
65+
<jdkHome>${{ env.JDK11_HOME }}</jdkHome>
66+
</configuration>
67+
</toolchain>
68+
</toolchains>
69+
EOF
70+
- name: Install JDK 8 and Maven
71+
uses: actions/setup-java@v2
72+
with:
73+
distribution: 'temurin'
74+
java-version: 8
5275
# Step that does that actual cache save and restore
5376
- name: Cache maven dependencies
5477
uses: actions/cache@v2
@@ -59,10 +82,4 @@ jobs:
5982
${{ runner.os }}-build-
6083
- name: Build
6184
run: |
62-
mvn --batch-mode --update-snapshots -DclickhouseVersion=${{ matrix.clickhouse }} verify
63-
if: matrix.java == '8'
64-
- name: Build in release mode
65-
run: |
66-
mvn --batch-mode --update-snapshots --global-toolchains .github/toolchains.xml \
67-
-Drelease -DclickhouseVersion=${{ matrix.clickhouse }} verify
68-
if: matrix.java != '8'
85+
mvn --batch-mode --update-snapshots -Drelease -DclickhouseVersion=${{ matrix.clickhouse }} verify

clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/DriverState.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public void doSetup(ServerState serverState) throws Exception {
5656
s.execute(
5757
"create table if not exists system.test_insert(i Nullable(UInt64), s Nullable(String), t Nullable(DateTime))engine=Memory");
5858
}
59+
60+
if (!Constants.REUSE_CONNECTION.equalsIgnoreCase(connection)) {
61+
conn.close();
62+
conn = null;
63+
}
5964
} catch (SQLException e) {
6065
e.printStackTrace();
6166
throw new RuntimeException(e);
@@ -68,6 +73,7 @@ public void doTearDown(ServerState serverState) throws SQLException {
6873

6974
if (conn != null) {
7075
conn.close();
76+
conn = null;
7177
}
7278
}
7379

clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHousePipedStreamTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.InputStream;
55
import java.io.OutputStream;
66
import java.nio.ByteBuffer;
7+
import java.nio.Buffer;
78
import java.util.concurrent.CountDownLatch;
89
import java.util.concurrent.ExecutorService;
910
import java.util.concurrent.Executors;
@@ -23,7 +24,7 @@ public void testRead() throws Exception {
2324
}
2425

2526
ByteBuffer buf = ByteBuffer.allocate(1).put(new byte[] { (byte) 3 });
26-
stream.queue.put((ByteBuffer) buf.rewind());
27+
stream.queue.put((ByteBuffer) ((Buffer) buf).rewind());
2728
Assert.assertEquals(stream.queue.size(), 1);
2829
try (InputStream in = stream.getInput()) {
2930
Assert.assertEquals(in.read(), 3);
@@ -34,7 +35,7 @@ public void testRead() throws Exception {
3435
}
3536

3637
buf = ByteBuffer.allocate(2).put(new byte[] { (byte) 3, (byte) 4 });
37-
stream.queue.put((ByteBuffer) buf.rewind());
38+
stream.queue.put((ByteBuffer) ((Buffer) buf).rewind());
3839
Assert.assertEquals(stream.queue.size(), 1);
3940
try (InputStream in = stream.getInput()) {
4041
Assert.assertEquals(in.read(), 3);
@@ -52,7 +53,7 @@ public void testRead() throws Exception {
5253
Assert.assertEquals(in.read(), -1);
5354
}
5455

55-
stream.queue.put((ByteBuffer) buf.rewind());
56+
stream.queue.put((ByteBuffer) ((Buffer) buf).rewind());
5657
stream.queue.put(buf);
5758
stream.queue.put(ClickHousePipedStream.EMPTY);
5859
Assert.assertEquals(stream.queue.size(), 3);
@@ -90,15 +91,15 @@ public void testReadBytes() throws Exception {
9091
}
9192

9293
ByteBuffer buf = ByteBuffer.allocate(2).put(new byte[] { (byte) 3, (byte) 4 });
93-
stream.queue.put((ByteBuffer) buf.rewind());
94+
stream.queue.put((ByteBuffer) ((Buffer) buf).rewind());
9495
Assert.assertEquals(stream.queue.size(), 1);
9596
try (InputStream in = stream.getInput()) {
9697
in.read(bytes);
9798
Assert.fail("Read should be timed out");
9899
} catch (IOException e) {
99100
Assert.assertTrue(e.getMessage().indexOf("Read timed out") == 0);
100101
}
101-
stream.queue.put((ByteBuffer) buf.rewind());
102+
stream.queue.put((ByteBuffer) ((Buffer) buf).rewind());
102103
Assert.assertEquals(stream.queue.size(), 1);
103104
try (InputStream in = stream.getInput()) {
104105
Assert.assertEquals(in.read(bytes, 0, 2), 2);
@@ -107,7 +108,7 @@ public void testReadBytes() throws Exception {
107108
} catch (IOException e) {
108109
Assert.assertTrue(e.getMessage().indexOf("Read timed out") == 0);
109110
}
110-
stream.queue.put((ByteBuffer) buf.rewind());
111+
stream.queue.put((ByteBuffer) ((Buffer) buf).rewind());
111112
Assert.assertEquals(stream.queue.size(), 1);
112113
try (InputStream in = stream.getInput()) {
113114
in.read(bytes, 0, 3);
@@ -117,7 +118,7 @@ public void testReadBytes() throws Exception {
117118
}
118119

119120
buf = ByteBuffer.allocate(2).put(new byte[] { (byte) 3, (byte) 4 });
120-
stream.queue.put((ByteBuffer) buf.rewind());
121+
stream.queue.put((ByteBuffer) ((Buffer) buf).rewind());
121122
stream.queue.put(ClickHousePipedStream.EMPTY);
122123
Assert.assertEquals(stream.queue.size(), 2);
123124
try (InputStream in = stream.getInput()) {

clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/util/ClickHouseBlockChecksumTest.java

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,80 @@
44
import org.testng.annotations.Test;
55
import ru.yandex.clickhouse.response.ClickHouseLZ4Stream;
66

7-
import javax.xml.bind.DatatypeConverter;
8-
97
/**
108
* @author Anton Sukhonosenko <a href="mailto:algebraic@yandex-team.ru"></a>
119
* @date 08.06.18
1210
*/
1311
public class ClickHouseBlockChecksumTest {
1412
private static final int HEADER_SIZE_BYTES = 9;
1513

14+
private static int hexToBin(char ch) {
15+
if ('0' <= ch && ch <= '9') {
16+
return ch - '0';
17+
}
18+
if ('A' <= ch && ch <= 'F') {
19+
return ch - 'A' + 10;
20+
}
21+
if ('a' <= ch && ch <= 'f') {
22+
return ch - 'a' + 10;
23+
}
24+
return -1;
25+
}
26+
27+
private static byte[] parseHexBinary(String s) {
28+
final int len = s.length();
29+
30+
// "111" is not a valid hex encoding.
31+
if (len % 2 != 0) {
32+
throw new IllegalArgumentException("hexBinary needs to be even-length: " + s);
33+
}
34+
35+
byte[] out = new byte[len / 2];
36+
37+
for (int i = 0; i < len; i += 2) {
38+
int h = hexToBin(s.charAt(i));
39+
int l = hexToBin(s.charAt(i + 1));
40+
if (h == -1 || l == -1) {
41+
throw new IllegalArgumentException("contains illegal character for hexBinary: " + s);
42+
}
43+
44+
out[i / 2] = (byte) (h * 16 + l);
45+
}
46+
47+
return out;
48+
}
49+
1650
@Test(groups = "unit")
1751
public void trickyBlock() {
18-
byte[] compressedData = DatatypeConverter.parseHexBinary("1F000100078078000000B4000000");
52+
byte[] compressedData = parseHexBinary("1F000100078078000000B4000000");
1953
int uncompressedSizeBytes = 35;
2054

2155
ClickHouseBlockChecksum checksum = ClickHouseBlockChecksum.calculateForBlock(
22-
(byte) ClickHouseLZ4Stream.MAGIC,
23-
compressedData.length + HEADER_SIZE_BYTES,
24-
uncompressedSizeBytes,
25-
compressedData,
26-
compressedData.length
27-
);
56+
(byte) ClickHouseLZ4Stream.MAGIC,
57+
compressedData.length + HEADER_SIZE_BYTES,
58+
uncompressedSizeBytes,
59+
compressedData,
60+
compressedData.length);
2861

2962
Assert.assertEquals(
30-
new ClickHouseBlockChecksum(-493639813825217902L, -6253550521065361778L),
31-
checksum
32-
);
63+
new ClickHouseBlockChecksum(-493639813825217902L, -6253550521065361778L),
64+
checksum);
3365
}
3466

3567
@Test(groups = "unit")
3668
public void anotherTrickyBlock() {
37-
byte[] compressedData = DatatypeConverter.parseHexBinary("80D9CEF753E3A59B3F");
69+
byte[] compressedData = parseHexBinary("80D9CEF753E3A59B3F");
3870
int uncompressedSizeBytes = 8;
3971

4072
ClickHouseBlockChecksum checksum = ClickHouseBlockChecksum.calculateForBlock(
41-
(byte) ClickHouseLZ4Stream.MAGIC,
42-
compressedData.length + HEADER_SIZE_BYTES,
43-
uncompressedSizeBytes,
44-
compressedData,
45-
compressedData.length
46-
);
73+
(byte) ClickHouseLZ4Stream.MAGIC,
74+
compressedData.length + HEADER_SIZE_BYTES,
75+
uncompressedSizeBytes,
76+
compressedData,
77+
compressedData.length);
4778

4879
Assert.assertEquals(
49-
new ClickHouseBlockChecksum(-7135037831041210418L, -8214889029657590490L),
50-
checksum
51-
);
80+
new ClickHouseBlockChecksum(-7135037831041210418L, -8214889029657590490L),
81+
checksum);
5282
}
5383
}

0 commit comments

Comments
 (0)