|
1 | 1 | package org.testcontainers.clickhouse;
|
2 | 2 |
|
| 3 | +import com.clickhouse.client.api.Client; |
| 4 | +import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader; |
| 5 | +import com.clickhouse.client.api.query.QueryResponse; |
3 | 6 | import org.junit.Test;
|
4 | 7 | import org.testcontainers.ClickhouseTestImages;
|
5 | 8 | import org.testcontainers.db.AbstractContainerDatabaseTest;
|
6 | 9 |
|
7 | 10 | import java.sql.ResultSet;
|
8 | 11 | import java.sql.SQLException;
|
| 12 | +import java.util.concurrent.ExecutionException; |
| 13 | +import java.util.concurrent.TimeUnit; |
| 14 | +import java.util.concurrent.TimeoutException; |
9 | 15 |
|
10 | 16 | import static org.assertj.core.api.Assertions.assertThat;
|
| 17 | +import static org.assertj.core.api.Assertions.fail; |
11 | 18 |
|
12 | 19 | public class ClickHouseContainerTest extends AbstractContainerDatabaseTest {
|
13 | 20 |
|
@@ -56,4 +63,27 @@ public void testNewAuth() throws SQLException {
|
56 | 63 | assertThat(resultSetInt).isEqualTo(1);
|
57 | 64 | }
|
58 | 65 | }
|
| 66 | + |
| 67 | + @Test |
| 68 | + public void testGetHttpMethodWithHttpClient() { |
| 69 | + ClickHouseContainer clickhouse = new ClickHouseContainer(ClickhouseTestImages.CLICKHOUSE_24_12_IMAGE); |
| 70 | + clickhouse.start(); |
| 71 | + Client client = new Client.Builder() |
| 72 | + .addEndpoint(clickhouse.getHttpUrl()) |
| 73 | + .setUsername(clickhouse.getUsername()) |
| 74 | + .setPassword(clickhouse.getPassword()) |
| 75 | + .build(); |
| 76 | + try { |
| 77 | + QueryResponse queryResponse = client.query("SELECT 1").get(1, TimeUnit.MINUTES); |
| 78 | + ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(queryResponse); |
| 79 | + reader.next(); |
| 80 | + int result = reader.getInteger(1); |
| 81 | + assertThat(result).isEqualTo(1); |
| 82 | + } catch (ExecutionException | InterruptedException | TimeoutException e) { |
| 83 | + fail("Cannot get sql result:" + e); |
| 84 | + } finally { |
| 85 | + clickhouse.close(); |
| 86 | + client.close(); |
| 87 | + } |
| 88 | + } |
59 | 89 | }
|
0 commit comments