@@ -1120,6 +1120,71 @@ public void testSNIWithCloud() throws Exception {
11201120 }
11211121 }
11221122
1123+ @ Test (groups = {"integration" })
1124+ public void testEndpointUrlPathIsPreserved () throws Exception {
1125+ if (isCloud ()) {
1126+ return ; // mocked server
1127+ }
1128+
1129+ int serverPort = new Random ().nextInt (1000 ) + 10000 ;
1130+ WireMockServer mockServer = new WireMockServer (WireMockConfiguration
1131+ .options ().port (serverPort )
1132+ .notifier (new Slf4jNotifier (true )));
1133+ mockServer .start ();
1134+
1135+ try {
1136+ // Setup stubs for two virtual ClickHouse instances behind a reverse proxy
1137+ mockServer .addStubMapping (WireMock .post (WireMock .urlPathEqualTo ("/sales/db" ))
1138+ .willReturn (WireMock .aResponse ()
1139+ .withStatus (HttpStatus .SC_OK )
1140+ .withHeader ("X-ClickHouse-Summary" ,
1141+ "{ \" read_bytes\" : \" 100\" , \" read_rows\" : \" 10\" }" )).build ());
1142+
1143+ mockServer .addStubMapping (WireMock .post (WireMock .urlPathEqualTo ("/billing/db" ))
1144+ .willReturn (WireMock .aResponse ()
1145+ .withStatus (HttpStatus .SC_OK )
1146+ .withHeader ("X-ClickHouse-Summary" ,
1147+ "{ \" read_bytes\" : \" 200\" , \" read_rows\" : \" 20\" }" )).build ());
1148+
1149+ // Test sales virtual instance
1150+ try (Client salesClient = new Client .Builder ()
1151+ .addEndpoint ("http://localhost:" + serverPort + "/sales/db" )
1152+ .setUsername ("default" )
1153+ .setPassword (ClickHouseServerForTest .getPassword ())
1154+ .compressServerResponse (false )
1155+ .build ()) {
1156+
1157+ try (QueryResponse response = salesClient .query ("SELECT 1" ).get (10 , TimeUnit .SECONDS )) {
1158+ Assert .assertEquals (response .getReadBytes (), 100 );
1159+ }
1160+ }
1161+
1162+ // Test billing virtual instance - also verify query parameters in URL are ignored
1163+ try (Client billingClient = new Client .Builder ()
1164+ .addEndpoint ("http://localhost:" + serverPort + "/billing/db?ignored_param=value" )
1165+ .setUsername ("default" )
1166+ .setPassword (ClickHouseServerForTest .getPassword ())
1167+ .compressServerResponse (false )
1168+ .build ()) {
1169+
1170+ try (QueryResponse response = billingClient .query ("SELECT 1" ).get (10 , TimeUnit .SECONDS )) {
1171+ Assert .assertEquals (response .getReadBytes (), 200 );
1172+ }
1173+
1174+ // Verify that ignored_param is not in the request URL
1175+ mockServer .verify (WireMock .postRequestedFor (WireMock .urlPathEqualTo ("/billing/db" ))
1176+ .withoutQueryParam ("ignored_param" ));
1177+ }
1178+
1179+ // Verify requests were made to the correct paths
1180+ mockServer .verify (WireMock .postRequestedFor (WireMock .urlPathEqualTo ("/sales/db" )));
1181+ mockServer .verify (WireMock .postRequestedFor (WireMock .urlPathEqualTo ("/billing/db" )));
1182+
1183+ } finally {
1184+ mockServer .stop ();
1185+ }
1186+ }
1187+
11231188 protected Client .Builder newClient () {
11241189 ClickHouseNode node = getServer (ClickHouseProtocol .HTTP );
11251190 boolean isSecure = isCloud ();
0 commit comments