Skip to content

Commit 51bcf80

Browse files
committed
[CALCITE-6854] ConnectionPropertiesHATest fails when running in eclipse-temurin:8 docker container on Windows
1 parent c8e57f2 commit 51bcf80

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

server/src/test/java/org/apache/calcite/avatica/ha/ConnectionPropertiesHATest.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import org.junit.BeforeClass;
3737
import org.junit.Test;
3838

39+
import java.io.PrintWriter;
40+
import java.io.StringWriter;
3941
import java.lang.reflect.Field;
4042
import java.lang.reflect.InvocationTargetException;
4143
import java.net.URI;
@@ -61,6 +63,7 @@
6163
import static org.junit.Assert.assertNotNull;
6264
import static org.junit.Assert.assertTrue;
6365
import static org.junit.Assert.fail;
66+
import static org.junit.Assume.assumeFalse;
6467

6568
public class ConnectionPropertiesHATest {
6669
private static final AvaticaServersForTest SERVERS = new AvaticaServersForTest();
@@ -250,24 +253,38 @@ public void testConnectionPropertiesHALBFailover() throws Exception {
250253
@Test
251254
public void testConnectionPropertiesHAHttpConnectionTimeout5Sec() throws Exception {
252255
// Skip the test for Windows.
253-
Assume.assumeFalse(OS_NAME_LOWERCASE.startsWith(WINDOWS_OS_PREFIX));
256+
Assume.assumeFalse("Skipping on Windows.", OS_NAME_LOWERCASE.startsWith(WINDOWS_OS_PREFIX));
254257
Properties properties = new Properties();
255258

256259
properties.put(BuiltInConnectionProperty.USE_CLIENT_SIDE_LB.name(), "true");
257260
properties.put(BuiltInConnectionProperty.HTTP_CONNECTION_TIMEOUT.name(), "5000");
258261
properties.put(BuiltInConnectionProperty.LB_CONNECTION_FAILOVER_RETRIES.name(), "0");
259262
// 240.0.0.1 is special URL which should result in connection timeout.
263+
// (Except on Windows)
260264
properties.put(BuiltInConnectionProperty.LB_URLS.name(), "http://240.0.0.1:" + 9000);
261265
String url = SERVERS.getJdbcUrl(START_PORT, Driver.Serialization.PROTOBUF);
262266
long startTime = System.currentTimeMillis();
263267
try {
264268
DriverManager.getConnection(url, properties);
265269
} catch (RuntimeException re) {
270+
assumeFalse(
271+
"Got HttpHostConnectException, probably running in WSL / Docker Desktop on Windows.",
272+
re.getCause() instanceof HttpHostConnectException);
266273
long endTime = System.currentTimeMillis();
267274
long elapsedTime = endTime - startTime;
268-
Assert.assertTrue(elapsedTime < Timeout.ofMinutes(3).toMilliseconds());
269-
Assert.assertTrue(elapsedTime >= 5000);
270-
Assert.assertTrue(re.getCause() instanceof ConnectTimeoutException);
275+
String stackTrace = "";
276+
try (StringWriter sw = new StringWriter();
277+
PrintWriter pw = new PrintWriter(sw)) {
278+
re.printStackTrace(pw);
279+
stackTrace = sw.toString();
280+
}
281+
Assert.assertTrue(
282+
"Expected RuntimeException with ConnectTimeoutException cause, got:\n" + stackTrace,
283+
re.getCause() instanceof ConnectTimeoutException);
284+
Assert.assertTrue("Elapsed time: " + elapsedTime + " ms, expected less than 3 minutes",
285+
elapsedTime < Timeout.ofMinutes(3).toMilliseconds());
286+
Assert.assertTrue("Elapsed time: " + elapsedTime + " ms, expected at least 5000 ms",
287+
elapsedTime >= 5000);
271288
}
272289
}
273290

0 commit comments

Comments
 (0)