|
31 | 31 | import org.junit.Before;
|
32 | 32 | import org.junit.Test;
|
33 | 33 |
|
34 |
| -import static org.junit.Assert.assertFalse; |
35 |
| -import static org.junit.Assert.assertNotSame; |
36 |
| -import static org.junit.Assert.assertTrue; |
37 |
| - |
38 | 34 | import org.apache.spark.network.TestUtils;
|
39 | 35 | import org.apache.spark.network.TransportContext;
|
40 | 36 | import org.apache.spark.network.server.NoOpRpcHandler;
|
|
45 | 41 | import org.apache.spark.network.util.JavaUtils;
|
46 | 42 | import org.apache.spark.network.util.TransportConf;
|
47 | 43 |
|
| 44 | +import static org.junit.Assert.*; |
| 45 | + |
48 | 46 | public class TransportClientFactorySuite {
|
49 | 47 | private TransportConf conf;
|
50 | 48 | private TransportContext context;
|
@@ -237,4 +235,31 @@ public void fastFailConnectionInTimeWindow() {
|
237 | 235 | Assert.assertThrows("fail this connection directly", IOException.class,
|
238 | 236 | () -> factory.createClient(TestUtils.getLocalHost(), unreachablePort, true));
|
239 | 237 | }
|
| 238 | + |
| 239 | + @Test |
| 240 | + public void unlimitedConnectionAndCreationTimeouts() throws IOException, InterruptedException { |
| 241 | + Map<String, String> configMap = new HashMap<>(); |
| 242 | + configMap.put("spark.shuffle.io.connectionTimeout", "-1"); |
| 243 | + configMap.put("spark.shuffle.io.connectionCreationTimeout", "-1"); |
| 244 | + TransportConf conf = new TransportConf("shuffle", new MapConfigProvider(configMap)); |
| 245 | + RpcHandler rpcHandler = new NoOpRpcHandler(); |
| 246 | + try (TransportContext ctx = new TransportContext(conf, rpcHandler, true); |
| 247 | + TransportClientFactory factory = ctx.createClientFactory()){ |
| 248 | + TransportClient c1 = factory.createClient(TestUtils.getLocalHost(), server1.getPort()); |
| 249 | + assertTrue(c1.isActive()); |
| 250 | + long expiredTime = System.currentTimeMillis() + 5000; |
| 251 | + while (c1.isActive() && System.currentTimeMillis() < expiredTime) { |
| 252 | + Thread.sleep(10); |
| 253 | + } |
| 254 | + assertTrue(c1.isActive()); |
| 255 | + // When connectionCreationTimeout is unlimited, the connection shall be able to |
| 256 | + // fail when the server is not reachable. |
| 257 | + TransportServer server = ctx.createServer(); |
| 258 | + int unreachablePort = server.getPort(); |
| 259 | + JavaUtils.closeQuietly(server); |
| 260 | + IOException exception = Assert.assertThrows(IOException.class, |
| 261 | + () -> factory.createClient(TestUtils.getLocalHost(), unreachablePort, true)); |
| 262 | + assertNotEquals(exception.getCause(), null); |
| 263 | + } |
| 264 | + } |
240 | 265 | }
|
0 commit comments