Skip to content

Commit

Permalink
fixed v2 cloud tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chernser committed Dec 20, 2024
1 parent a5f33d3 commit 84cec6e
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ public static void afterSuite() {
clickhouseContainer.stop();
}

if (isCloud) {
if (!runQuery("DROP DATABASE IF EXISTS " + database)) {
LOGGER.warn("Failed to drop database for testing.");
}
}
// if (isCloud) {
// if (!runQuery("DROP DATABASE IF EXISTS " + database)) {
// LOGGER.warn("Failed to drop database for testing.");
// }
// }
}

public static String getDatabase() {
Expand Down
31 changes: 17 additions & 14 deletions client-v2/src/test/java/com/clickhouse/client/ClientTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class ClientTests extends BaseIntegrationTest {

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

@Test
public void testRawSettings() {
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
Client client = new Client.Builder()
.addEndpoint(node.toUri().toString())
.setUsername("default")
.setPassword("")
Client client = newClient()
.setOption("custom_setting_1", "value_1")
.build();

client.execute("SELECT 1");

QuerySettings querySettings = new QuerySettings();
querySettings.setOption("session_timezone", "Europe/Zurich");
querySettings.serverSetting("session_timezone", "Europe/Zurich");

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

@Test
public void testPing() {
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
try (Client client = new Client.Builder()
.addEndpoint(node.toUri().toString())
.setUsername("default")
.setPassword("")
.useNewImplementation(System.getProperty("client.tests.useNewImplementation", "false").equals("true"))
.build()) {
try (Client client = newClient().build()) {
Assert.assertTrue(client.ping());
}
}
Expand All @@ -122,4 +114,15 @@ public void testPingFailure() {
Assert.assertFalse(client.ping(TimeUnit.SECONDS.toMillis(20)));
}
}

protected Client.Builder newClient() {
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
boolean isSecure = isCloud();
return new Client.Builder()
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isSecure)
.setUsername("default")
.setPassword(ClickHouseServerForTest.getPassword())
.setDefaultDatabase(ClickHouseServerForTest.getDatabase())
.useNewImplementation(System.getProperty("client.tests.useNewImplementation", "true").equals("true"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ public void closed(Socket socket) {

@Test(groups = {"integration"})
public void testConnectionRequestTimeout() {
if (isCloud()) {
return; // mocked server
}

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

@Test
public void testConnectionReuseStrategy() {
if (isCloud()) {
return; // mocked server
}

ClickHouseNode server = getServer(ClickHouseProtocol.HTTP);

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

@Test(groups = { "integration" })
public void testSecureConnection() {
if (isCloud()) {
return; // will fail in other tests
}

ClickHouseNode secureServer = getSecureServer(ClickHouseProtocol.HTTP);

try (Client client = new Client.Builder()
Expand All @@ -240,6 +251,10 @@ public void testSecureConnection() {
@Test(groups = { "integration" }, dataProvider = "NoResponseFailureProvider")
public void testInsertAndNoHttpResponseFailure(String body, int maxRetries, ThrowingFunction<Client, Void> function,
boolean shouldFail) {
if (isCloud()) {
return; // mocked server
}

WireMockServer faultyServer = new WireMockServer( WireMockConfiguration
.options().port(9090).notifier(new ConsoleNotifier(false)));
faultyServer.start();
Expand Down Expand Up @@ -318,6 +333,10 @@ public static Object[][] noResponseFailureProvider() {

@Test(groups = { "integration" }, dataProvider = "testServerErrorHandlingDataProvider")
public void testServerErrorHandling(ClickHouseFormat format, boolean serverCompression, boolean useHttpCompression) {
if (isCloud()) {
return; // mocked server
}

ClickHouseNode server = getServer(ClickHouseProtocol.HTTP);
try (Client client = new Client.Builder()
.addEndpoint(server.getBaseUri())
Expand Down Expand Up @@ -442,6 +461,10 @@ public void testErrorWithSuccessfulResponse() {

@Test(groups = { "integration" }, dataProvider = "testServerErrorsUncompressedDataProvider")
public void testServerErrorsUncompressed(int code, String message, String expectedMessage) {
if (isCloud()) {
return; // mocked server
}

WireMockServer mockServer = new WireMockServer( WireMockConfiguration
.options().port(9090).notifier(new ConsoleNotifier(false)));
mockServer.start();
Expand Down Expand Up @@ -497,6 +520,10 @@ public static Object[][] testServerErrorsUncompressedDataProvider() {

@Test(groups = { "integration" })
public void testAdditionalHeaders() {
if (isCloud()) {
return; // mocked server
}

WireMockServer mockServer = new WireMockServer( WireMockConfiguration
.options().port(9090).notifier(new ConsoleNotifier(false)));
mockServer.start();
Expand Down Expand Up @@ -538,6 +565,10 @@ public void testAdditionalHeaders() {

@Test(groups = { "integration" })
public void testServerSettings() {
if (isCloud()) {
return; // mocked server
}

WireMockServer mockServer = new WireMockServer( WireMockConfiguration
.options().port(9090).notifier(new ConsoleNotifier(false)));
mockServer.start();
Expand Down Expand Up @@ -733,6 +764,10 @@ public void testSSLAuthentication_invalidConfig() throws Exception {

@Test(groups = { "integration" })
public void testErrorWithSendProgressHeaders() throws Exception {
if (isCloud()) {
return; // mocked server
}

ClickHouseNode server = getServer(ClickHouseProtocol.HTTP);
try (Client client = new Client.Builder().addEndpoint(Protocol.HTTP, "localhost",server.getPort(), false)
.setUsername("default")
Expand Down Expand Up @@ -760,6 +795,9 @@ public void testErrorWithSendProgressHeaders() throws Exception {

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

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

@Test(groups = { "integration" })
public void testBearerTokenAuth() throws Exception {
if (isCloud()) {
return; // mocked server
}

WireMockServer mockServer = new WireMockServer( WireMockConfiguration
.options().port(9090).notifier(new ConsoleNotifier(false)));
mockServer.start();
Expand Down
27 changes: 27 additions & 0 deletions client-v2/src/test/java/com/clickhouse/client/ProxyTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ public void setUp() throws IOException {

@AfterMethod(groups = { "integration" })
public void teardown() {
if (isCloud()) {
return; // nothing to stop
}

proxy.get().stop();
client.get().close();
}

@Test(groups = { "integration" })
public void testSimpleQuery() throws Exception {
if (isCloud()) {
return; // to specific setup for cloud, may be later
}

client.set(clientBuilder(initProxy(), false).build());
addProxyStub();

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

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

@Test(groups = { "integration" })
public void testPrivateProxyWithoutAuth() {
if (isCloud()) {
return; // to specific setup for cloud, may be later
}

client.set(clientBuilder(initProxy(), true).build());
addPrivateProxyStub();

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

@Test(groups = { "integration" })
public void testPrivateProxyWithCredentials() {
if (isCloud()) {
return; // to specific setup for cloud, may be later
}

client.set(clientBuilder(initProxy(), true)
.setProxyCredentials("user", "pass").build());
addPrivateProxyStub();
Expand All @@ -112,6 +131,10 @@ public void testPrivateProxyWithCredentials() {

@Test(groups = { "integration" })
public void testProxyWithCookies() {
if (isCloud()) {
return; // to specific setup for cloud, may be later
}

client.set(clientBuilder(initProxy(), true).build());
final int targetPort = getServer(ClickHouseProtocol.HTTP).getPort();

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

@Test(groups = { "integration" })
public void testProxyWithDisabledCookies() {
if (isCloud()) {
return; // to specific setup for cloud, may be later
}

client.set(clientBuilder(initProxy(), true).setHttpCookiesEnabled(false).build());
final int targetPort = getServer(ClickHouseProtocol.HTTP).getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.clickhouse.client.BaseIntegrationTest;
import com.clickhouse.client.ClickHouseNode;
import com.clickhouse.client.ClickHouseProtocol;
import com.clickhouse.client.ClickHouseServerForTest;
import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.ClientException;
import com.clickhouse.client.api.command.CommandResponse;
Expand Down Expand Up @@ -67,12 +68,7 @@ public InsertTests(boolean useClientCompression, boolean useHttpCompression) {
public void setUp() throws IOException {
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
int bufferSize = (7 * 65500);
client = new Client.Builder()
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), false)
.setUsername("default")
.setPassword("")
.compressClientRequest(useClientCompression)
.useHttpCompression(useHttpCompression)
client = newClient()
.setSocketSndbuf(bufferSize)
.setSocketRcvbuf(bufferSize)
.setClientNetworkBufferSize(bufferSize)
Expand All @@ -83,6 +79,19 @@ public void setUp() throws IOException {
.setQueryId(String.valueOf(UUID.randomUUID()));
}

protected Client.Builder newClient() {
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
boolean isSecure = isCloud();
return new Client.Builder()
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isSecure)
.setUsername("default")
.setPassword(ClickHouseServerForTest.getPassword())
.compressClientRequest(useClientCompression)
.useHttpCompression(useHttpCompression)
.setDefaultDatabase(ClickHouseServerForTest.getDatabase())
.useNewImplementation(System.getProperty("client.tests.useNewImplementation", "true").equals("true"));
}

@AfterMethod(groups = { "integration" })
public void tearDown() {
client.close();
Expand Down
Loading

0 comments on commit 84cec6e

Please sign in to comment.