Skip to content

Commit 84cec6e

Browse files
committed
fixed v2 cloud tests
1 parent a5f33d3 commit 84cec6e

File tree

10 files changed

+162
-83
lines changed

10 files changed

+162
-83
lines changed

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,11 @@ public static void afterSuite() {
359359
clickhouseContainer.stop();
360360
}
361361

362-
if (isCloud) {
363-
if (!runQuery("DROP DATABASE IF EXISTS " + database)) {
364-
LOGGER.warn("Failed to drop database for testing.");
365-
}
366-
}
362+
// if (isCloud) {
363+
// if (!runQuery("DROP DATABASE IF EXISTS " + database)) {
364+
// LOGGER.warn("Failed to drop database for testing.");
365+
// }
366+
// }
367367
}
368368

369369
public static String getDatabase() {

client-v2/src/test/java/com/clickhouse/client/ClientTests.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class ClientTests extends BaseIntegrationTest {
2323

2424
@Test(dataProvider = "clientProvider")
2525
public void testAddSecureEndpoint(Client client) {
26+
if (isCloud()) {
27+
return; // will fail in other tests
28+
}
2629
try {
2730
Optional<GenericRecord> genericRecord = client
2831
.queryAll("SELECT hostname()").stream().findFirst();
@@ -69,18 +72,14 @@ private static Client[] secureClientProvider() throws Exception {
6972

7073
@Test
7174
public void testRawSettings() {
72-
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
73-
Client client = new Client.Builder()
74-
.addEndpoint(node.toUri().toString())
75-
.setUsername("default")
76-
.setPassword("")
75+
Client client = newClient()
7776
.setOption("custom_setting_1", "value_1")
7877
.build();
7978

8079
client.execute("SELECT 1");
8180

8281
QuerySettings querySettings = new QuerySettings();
83-
querySettings.setOption("session_timezone", "Europe/Zurich");
82+
querySettings.serverSetting("session_timezone", "Europe/Zurich");
8483

8584
try (Records response =
8685
client.queryRecords("SELECT timeZone(), serverTimeZone()", querySettings).get(10, TimeUnit.SECONDS)) {
@@ -91,7 +90,6 @@ public void testRawSettings() {
9190
Assert.assertEquals("UTC", record.getString(2));
9291
});
9392
} catch (Exception e) {
94-
e.printStackTrace();
9593
Assert.fail(e.getMessage());
9694
} finally {
9795
client.close();
@@ -100,13 +98,7 @@ public void testRawSettings() {
10098

10199
@Test
102100
public void testPing() {
103-
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
104-
try (Client client = new Client.Builder()
105-
.addEndpoint(node.toUri().toString())
106-
.setUsername("default")
107-
.setPassword("")
108-
.useNewImplementation(System.getProperty("client.tests.useNewImplementation", "false").equals("true"))
109-
.build()) {
101+
try (Client client = newClient().build()) {
110102
Assert.assertTrue(client.ping());
111103
}
112104
}
@@ -122,4 +114,15 @@ public void testPingFailure() {
122114
Assert.assertFalse(client.ping(TimeUnit.SECONDS.toMillis(20)));
123115
}
124116
}
117+
118+
protected Client.Builder newClient() {
119+
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
120+
boolean isSecure = isCloud();
121+
return new Client.Builder()
122+
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isSecure)
123+
.setUsername("default")
124+
.setPassword(ClickHouseServerForTest.getPassword())
125+
.setDefaultDatabase(ClickHouseServerForTest.getDatabase())
126+
.useNewImplementation(System.getProperty("client.tests.useNewImplementation", "true").equals("true"));
127+
}
125128
}

client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public void closed(Socket socket) {
155155

156156
@Test(groups = {"integration"})
157157
public void testConnectionRequestTimeout() {
158+
if (isCloud()) {
159+
return; // mocked server
160+
}
158161

159162
int serverPort = new Random().nextInt(1000) + 10000;
160163
ConnectionCounterListener connectionCounter = new ConnectionCounterListener();
@@ -197,6 +200,10 @@ public void testConnectionRequestTimeout() {
197200

198201
@Test
199202
public void testConnectionReuseStrategy() {
203+
if (isCloud()) {
204+
return; // mocked server
205+
}
206+
200207
ClickHouseNode server = getServer(ClickHouseProtocol.HTTP);
201208

202209
try (Client client = new Client.Builder()
@@ -218,6 +225,10 @@ public void testConnectionReuseStrategy() {
218225

219226
@Test(groups = { "integration" })
220227
public void testSecureConnection() {
228+
if (isCloud()) {
229+
return; // will fail in other tests
230+
}
231+
221232
ClickHouseNode secureServer = getSecureServer(ClickHouseProtocol.HTTP);
222233

223234
try (Client client = new Client.Builder()
@@ -240,6 +251,10 @@ public void testSecureConnection() {
240251
@Test(groups = { "integration" }, dataProvider = "NoResponseFailureProvider")
241252
public void testInsertAndNoHttpResponseFailure(String body, int maxRetries, ThrowingFunction<Client, Void> function,
242253
boolean shouldFail) {
254+
if (isCloud()) {
255+
return; // mocked server
256+
}
257+
243258
WireMockServer faultyServer = new WireMockServer( WireMockConfiguration
244259
.options().port(9090).notifier(new ConsoleNotifier(false)));
245260
faultyServer.start();
@@ -318,6 +333,10 @@ public static Object[][] noResponseFailureProvider() {
318333

319334
@Test(groups = { "integration" }, dataProvider = "testServerErrorHandlingDataProvider")
320335
public void testServerErrorHandling(ClickHouseFormat format, boolean serverCompression, boolean useHttpCompression) {
336+
if (isCloud()) {
337+
return; // mocked server
338+
}
339+
321340
ClickHouseNode server = getServer(ClickHouseProtocol.HTTP);
322341
try (Client client = new Client.Builder()
323342
.addEndpoint(server.getBaseUri())
@@ -442,6 +461,10 @@ public void testErrorWithSuccessfulResponse() {
442461

443462
@Test(groups = { "integration" }, dataProvider = "testServerErrorsUncompressedDataProvider")
444463
public void testServerErrorsUncompressed(int code, String message, String expectedMessage) {
464+
if (isCloud()) {
465+
return; // mocked server
466+
}
467+
445468
WireMockServer mockServer = new WireMockServer( WireMockConfiguration
446469
.options().port(9090).notifier(new ConsoleNotifier(false)));
447470
mockServer.start();
@@ -497,6 +520,10 @@ public static Object[][] testServerErrorsUncompressedDataProvider() {
497520

498521
@Test(groups = { "integration" })
499522
public void testAdditionalHeaders() {
523+
if (isCloud()) {
524+
return; // mocked server
525+
}
526+
500527
WireMockServer mockServer = new WireMockServer( WireMockConfiguration
501528
.options().port(9090).notifier(new ConsoleNotifier(false)));
502529
mockServer.start();
@@ -538,6 +565,10 @@ public void testAdditionalHeaders() {
538565

539566
@Test(groups = { "integration" })
540567
public void testServerSettings() {
568+
if (isCloud()) {
569+
return; // mocked server
570+
}
571+
541572
WireMockServer mockServer = new WireMockServer( WireMockConfiguration
542573
.options().port(9090).notifier(new ConsoleNotifier(false)));
543574
mockServer.start();
@@ -733,6 +764,10 @@ public void testSSLAuthentication_invalidConfig() throws Exception {
733764

734765
@Test(groups = { "integration" })
735766
public void testErrorWithSendProgressHeaders() throws Exception {
767+
if (isCloud()) {
768+
return; // mocked server
769+
}
770+
736771
ClickHouseNode server = getServer(ClickHouseProtocol.HTTP);
737772
try (Client client = new Client.Builder().addEndpoint(Protocol.HTTP, "localhost",server.getPort(), false)
738773
.setUsername("default")
@@ -760,6 +795,9 @@ public void testErrorWithSendProgressHeaders() throws Exception {
760795

761796
@Test(groups = { "integration" }, dataProvider = "testUserAgentHasCompleteProductName_dataProvider", dataProviderClass = HttpTransportTests.class)
762797
public void testUserAgentHasCompleteProductName(String clientName, Pattern userAgentPattern) throws Exception {
798+
if (isCloud()) {
799+
return; // mocked server
800+
}
763801

764802
ClickHouseNode server = getServer(ClickHouseProtocol.HTTP);
765803
try (Client client = new Client.Builder()
@@ -799,6 +837,10 @@ public static Object[][] testUserAgentHasCompleteProductName_dataProvider() {
799837

800838
@Test(groups = { "integration" })
801839
public void testBearerTokenAuth() throws Exception {
840+
if (isCloud()) {
841+
return; // mocked server
842+
}
843+
802844
WireMockServer mockServer = new WireMockServer( WireMockConfiguration
803845
.options().port(9090).notifier(new ConsoleNotifier(false)));
804846
mockServer.start();

client-v2/src/test/java/com/clickhouse/client/ProxyTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ public void setUp() throws IOException {
4343

4444
@AfterMethod(groups = { "integration" })
4545
public void teardown() {
46+
if (isCloud()) {
47+
return; // nothing to stop
48+
}
49+
4650
proxy.get().stop();
4751
client.get().close();
4852
}
4953

5054
@Test(groups = { "integration" })
5155
public void testSimpleQuery() throws Exception {
56+
if (isCloud()) {
57+
return; // to specific setup for cloud, may be later
58+
}
59+
5260
client.set(clientBuilder(initProxy(), false).build());
5361
addProxyStub();
5462

@@ -58,6 +66,9 @@ public void testSimpleQuery() throws Exception {
5866

5967
@Test(groups = { "integration" })
6068
public void testInsert() throws Exception {
69+
if (isCloud()) {
70+
return; // to specific setup for cloud, may be later
71+
}
6172
String tableName = "simple_pojo_disable_proxy_table";
6273
String createSQL = SamplePOJO.generateTableCreateSQL(tableName);
6374
client.set(clientBuilder(initProxy(), false).build());
@@ -81,6 +92,10 @@ public void testInsert() throws Exception {
8192

8293
@Test(groups = { "integration" })
8394
public void testPrivateProxyWithoutAuth() {
95+
if (isCloud()) {
96+
return; // to specific setup for cloud, may be later
97+
}
98+
8499
client.set(clientBuilder(initProxy(), true).build());
85100
addPrivateProxyStub();
86101

@@ -98,6 +113,10 @@ public void testPrivateProxyWithoutAuth() {
98113

99114
@Test(groups = { "integration" })
100115
public void testPrivateProxyWithCredentials() {
116+
if (isCloud()) {
117+
return; // to specific setup for cloud, may be later
118+
}
119+
101120
client.set(clientBuilder(initProxy(), true)
102121
.setProxyCredentials("user", "pass").build());
103122
addPrivateProxyStub();
@@ -112,6 +131,10 @@ public void testPrivateProxyWithCredentials() {
112131

113132
@Test(groups = { "integration" })
114133
public void testProxyWithCookies() {
134+
if (isCloud()) {
135+
return; // to specific setup for cloud, may be later
136+
}
137+
115138
client.set(clientBuilder(initProxy(), true).build());
116139
final int targetPort = getServer(ClickHouseProtocol.HTTP).getPort();
117140

@@ -137,6 +160,10 @@ public void testProxyWithCookies() {
137160

138161
@Test(groups = { "integration" })
139162
public void testProxyWithDisabledCookies() {
163+
if (isCloud()) {
164+
return; // to specific setup for cloud, may be later
165+
}
166+
140167
client.set(clientBuilder(initProxy(), true).setHttpCookiesEnabled(false).build());
141168
final int targetPort = getServer(ClickHouseProtocol.HTTP).getPort();
142169

client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.clickhouse.client.BaseIntegrationTest;
44
import com.clickhouse.client.ClickHouseNode;
55
import com.clickhouse.client.ClickHouseProtocol;
6+
import com.clickhouse.client.ClickHouseServerForTest;
67
import com.clickhouse.client.api.Client;
78
import com.clickhouse.client.api.ClientException;
89
import com.clickhouse.client.api.command.CommandResponse;
@@ -67,12 +68,7 @@ public InsertTests(boolean useClientCompression, boolean useHttpCompression) {
6768
public void setUp() throws IOException {
6869
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
6970
int bufferSize = (7 * 65500);
70-
client = new Client.Builder()
71-
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), false)
72-
.setUsername("default")
73-
.setPassword("")
74-
.compressClientRequest(useClientCompression)
75-
.useHttpCompression(useHttpCompression)
71+
client = newClient()
7672
.setSocketSndbuf(bufferSize)
7773
.setSocketRcvbuf(bufferSize)
7874
.setClientNetworkBufferSize(bufferSize)
@@ -83,6 +79,19 @@ public void setUp() throws IOException {
8379
.setQueryId(String.valueOf(UUID.randomUUID()));
8480
}
8581

82+
protected Client.Builder newClient() {
83+
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
84+
boolean isSecure = isCloud();
85+
return new Client.Builder()
86+
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isSecure)
87+
.setUsername("default")
88+
.setPassword(ClickHouseServerForTest.getPassword())
89+
.compressClientRequest(useClientCompression)
90+
.useHttpCompression(useHttpCompression)
91+
.setDefaultDatabase(ClickHouseServerForTest.getDatabase())
92+
.useNewImplementation(System.getProperty("client.tests.useNewImplementation", "true").equals("true"));
93+
}
94+
8695
@AfterMethod(groups = { "integration" })
8796
public void tearDown() {
8897
client.close();

0 commit comments

Comments
 (0)