|
2 | 2 |
|
3 | 3 | import com.clickhouse.client.api.Client;
|
4 | 4 | import com.clickhouse.client.api.ConnectionInitiationException;
|
| 5 | +import com.clickhouse.client.api.ConnectionReuseStrategy; |
5 | 6 | import com.clickhouse.client.api.enums.ProxyType;
|
6 | 7 | import com.clickhouse.client.api.query.GenericRecord;
|
7 | 8 | import com.clickhouse.client.api.query.QueryResponse;
|
@@ -150,17 +151,39 @@ public void testConnectionRequestTimeout() {
|
150 | 151 |
|
151 | 152 | try (Client client = clientBuilder.build()) {
|
152 | 153 | CompletableFuture<QueryResponse> f1 = client.query("select 1");
|
| 154 | + Thread.sleep(500L); |
153 | 155 | CompletableFuture<QueryResponse> f2 = client.query("select 1");
|
154 | 156 | f2.get();
|
155 | 157 | } catch (ExecutionException e) {
|
156 | 158 | e.printStackTrace();
|
157 |
| - Assert.assertTrue(e.getCause() instanceof ConnectionInitiationException); |
158 |
| - Assert.assertTrue(e.getCause().getCause() instanceof ConnectionRequestTimeoutException); |
| 159 | + Assert.assertEquals(e.getCause().getClass(), ConnectionInitiationException.class); |
| 160 | + Assert.assertEquals(e.getCause().getCause().getClass(), ConnectionRequestTimeoutException.class); |
159 | 161 | } catch (Exception e) {
|
160 | 162 | e.printStackTrace();
|
161 | 163 | Assert.fail("Unexpected exception", e);
|
162 | 164 | } finally {
|
163 | 165 | proxy.stop();
|
164 | 166 | }
|
165 | 167 | }
|
| 168 | + |
| 169 | + @Test |
| 170 | + public void testConnectionReuseStrategy() { |
| 171 | + ClickHouseNode server = getServer(ClickHouseProtocol.HTTP); |
| 172 | + |
| 173 | + try (Client client = new Client.Builder() |
| 174 | + .addEndpoint(server.getBaseUri()) |
| 175 | + .setUsername("default") |
| 176 | + .setPassword(getPassword()) |
| 177 | + .useNewImplementation(true) |
| 178 | + .setConnectionReuseStrategy(ConnectionReuseStrategy.LIFO) |
| 179 | + .build()) { |
| 180 | + |
| 181 | + List<GenericRecord> records = client.queryAll("SELECT timezone()"); |
| 182 | + Assert.assertTrue(records.size() > 0); |
| 183 | + Assert.assertEquals(records.get(0).getString(1), "UTC"); |
| 184 | + } catch (Exception e) { |
| 185 | + e.printStackTrace(); |
| 186 | + Assert.fail(e.getMessage()); |
| 187 | + } |
| 188 | + } |
166 | 189 | }
|
0 commit comments