1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.testsuite.transport.socket;
17
18 import io.netty5.bootstrap.Bootstrap;
19 import io.netty5.bootstrap.ServerBootstrap;
20 import io.netty5.channel.Channel;
21 import io.netty5.channel.ChannelHandler;
22 import io.netty5.testsuite.transport.TestsuitePermutation;
23 import io.netty5.util.NetUtil;
24 import org.junit.jupiter.api.Test;
25 import org.junit.jupiter.api.TestInfo;
26 import org.junit.jupiter.api.Timeout;
27
28 import java.nio.channels.AlreadyConnectedException;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.concurrent.TimeUnit;
32
33 import static org.assertj.core.api.Assertions.assertThat;
34
35 public class SocketMultipleConnectTest extends AbstractSocketTest {
36
37 @Test
38 @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
39 public void testMultipleConnect(TestInfo testInfo) throws Throwable {
40 run(testInfo, this::testMultipleConnect);
41 }
42
43 public void testMultipleConnect(ServerBootstrap sb, Bootstrap cb) throws Exception {
44 Channel sc = null;
45 Channel cc = null;
46 try {
47 sb.childHandler(new ChannelHandler() { });
48 sc = sb.bind(NetUtil.LOCALHOST, 0).asStage().get();
49
50 cb.handler(new ChannelHandler() { });
51 cc = cb.register().asStage().get();
52 cc.connect(sc.localAddress()).asStage().sync();
53 Throwable cause = cc.connect(sc.localAddress()).asStage().getCause();
54 assertThat(cause).isInstanceOf(AlreadyConnectedException.class);
55 } finally {
56 if (cc != null) {
57 cc.close();
58 }
59 if (sc != null) {
60 sc.close();
61 }
62 }
63 }
64
65 @Override
66 protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
67 return new ArrayList<>(SocketTestPermutation.INSTANCE.socketWithFastOpen());
68 }
69 }