1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.testsuite.transport.sctp;
17
18 import io.netty.bootstrap.Bootstrap;
19 import io.netty.bootstrap.ServerBootstrap;
20 import io.netty.channel.EventLoopGroup;
21 import io.netty.channel.MultiThreadIoEventLoopGroup;
22 import io.netty.channel.nio.NioIoHandler;
23 import io.netty.channel.oio.OioEventLoopGroup;
24 import io.netty.channel.sctp.nio.NioSctpChannel;
25 import io.netty.channel.sctp.nio.NioSctpServerChannel;
26 import io.netty.channel.sctp.oio.OioSctpChannel;
27 import io.netty.channel.sctp.oio.OioSctpServerChannel;
28 import io.netty.testsuite.util.TestUtils;
29 import io.netty.testsuite.transport.TestsuitePermutation.BootstrapComboFactory;
30 import io.netty.testsuite.transport.TestsuitePermutation.BootstrapFactory;
31 import io.netty.util.concurrent.DefaultThreadFactory;
32
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
36
37 public final class SctpTestPermutation {
38
39 private static final int NUM_THREADS = 4;
40 private static final EventLoopGroup NIO_GROUP = new MultiThreadIoEventLoopGroup(
41 NUM_THREADS, new DefaultThreadFactory("testsuite-sctp-nio", true), NioIoHandler.newFactory());
42 private static final EventLoopGroup OIO_GROUP =
43 new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-sctp-oio-worker", true));
44
45 static List<BootstrapFactory<ServerBootstrap>> sctpServerChannel() {
46 if (!TestUtils.isSctpSupported()) {
47 return Collections.emptyList();
48 }
49
50 List<BootstrapFactory<ServerBootstrap>> list = new ArrayList<BootstrapFactory<ServerBootstrap>>();
51
52 list.add(new BootstrapFactory<ServerBootstrap>() {
53 @Override
54 public ServerBootstrap newInstance() {
55 return new ServerBootstrap().
56 group(NIO_GROUP).
57 channel(NioSctpServerChannel.class);
58 }
59 });
60 list.add(new BootstrapFactory<ServerBootstrap>() {
61 @Override
62 public ServerBootstrap newInstance() {
63 return new ServerBootstrap().
64 group(OIO_GROUP).
65 channel(OioSctpServerChannel.class);
66 }
67 });
68
69 return list;
70 }
71
72 static List<BootstrapFactory<Bootstrap>> sctpClientChannel() {
73 if (!TestUtils.isSctpSupported()) {
74 return Collections.emptyList();
75 }
76
77 List<BootstrapFactory<Bootstrap>> list = new ArrayList<BootstrapFactory<Bootstrap>>();
78 list.add(new BootstrapFactory<Bootstrap>() {
79 @Override
80 public Bootstrap newInstance() {
81 return new Bootstrap().group(NIO_GROUP).channel(NioSctpChannel.class);
82 }
83 });
84 list.add(new BootstrapFactory<Bootstrap>() {
85 @Override
86 public Bootstrap newInstance() {
87 return new Bootstrap().group(OIO_GROUP).channel(OioSctpChannel.class);
88 }
89 });
90 return list;
91 }
92
93 static List<BootstrapComboFactory<ServerBootstrap, Bootstrap>> sctpChannel() {
94 List<BootstrapComboFactory<ServerBootstrap, Bootstrap>> list =
95 new ArrayList<BootstrapComboFactory<ServerBootstrap, Bootstrap>>();
96
97
98 List<BootstrapFactory<ServerBootstrap>> sbfs = sctpServerChannel();
99
100
101 List<BootstrapFactory<Bootstrap>> cbfs = sctpClientChannel();
102
103
104 for (BootstrapFactory<ServerBootstrap> sbf: sbfs) {
105 for (BootstrapFactory<Bootstrap> cbf: cbfs) {
106 final BootstrapFactory<ServerBootstrap> sbf0 = sbf;
107 final BootstrapFactory<Bootstrap> cbf0 = cbf;
108 list.add(new BootstrapComboFactory<ServerBootstrap, Bootstrap>() {
109 @Override
110 public ServerBootstrap newServerInstance() {
111 return sbf0.newInstance();
112 }
113
114 @Override
115 public Bootstrap newClientInstance() {
116 return cbf0.newInstance();
117 }
118 });
119 }
120 }
121
122 return list;
123 }
124
125 private SctpTestPermutation() { }
126 }