View Javadoc
1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
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 BOSSES = 2;
40      private static final int WORKERS = 3;
41      private static final EventLoopGroup nioBossGroup = new MultiThreadIoEventLoopGroup(
42              BOSSES, new DefaultThreadFactory("testsuite-sctp-nio-boss", true), NioIoHandler.newFactory());
43      private static final EventLoopGroup nioWorkerGroup = new MultiThreadIoEventLoopGroup(
44              WORKERS, new DefaultThreadFactory("testsuite-sctp-nio-worker", true), NioIoHandler.newFactory());
45      private static final EventLoopGroup oioBossGroup =
46              new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-sctp-oio-boss", true));
47      private static final EventLoopGroup oioWorkerGroup =
48              new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-sctp-oio-worker", true));
49  
50      static List<BootstrapFactory<ServerBootstrap>> sctpServerChannel() {
51          if (!TestUtils.isSctpSupported()) {
52              return Collections.emptyList();
53          }
54  
55          List<BootstrapFactory<ServerBootstrap>> list = new ArrayList<BootstrapFactory<ServerBootstrap>>();
56          // Make the list of ServerBootstrap factories.
57          list.add(new BootstrapFactory<ServerBootstrap>() {
58              @Override
59              public ServerBootstrap newInstance() {
60                  return new ServerBootstrap().
61                          group(nioBossGroup, nioWorkerGroup).
62                          channel(NioSctpServerChannel.class);
63              }
64          });
65          list.add(new BootstrapFactory<ServerBootstrap>() {
66              @Override
67              public ServerBootstrap newInstance() {
68                  return new ServerBootstrap().
69                          group(oioBossGroup, oioWorkerGroup).
70                          channel(OioSctpServerChannel.class);
71              }
72          });
73  
74          return list;
75      }
76  
77      static List<BootstrapFactory<Bootstrap>> sctpClientChannel() {
78          if (!TestUtils.isSctpSupported()) {
79              return Collections.emptyList();
80          }
81  
82          List<BootstrapFactory<Bootstrap>> list = new ArrayList<BootstrapFactory<Bootstrap>>();
83          list.add(new BootstrapFactory<Bootstrap>() {
84              @Override
85              public Bootstrap newInstance() {
86                  return new Bootstrap().group(nioWorkerGroup).channel(NioSctpChannel.class);
87              }
88          });
89          list.add(new BootstrapFactory<Bootstrap>() {
90              @Override
91              public Bootstrap newInstance() {
92                  return new Bootstrap().group(oioWorkerGroup).channel(OioSctpChannel.class);
93              }
94          });
95          return list;
96      }
97  
98      static List<BootstrapComboFactory<ServerBootstrap, Bootstrap>> sctpChannel() {
99          List<BootstrapComboFactory<ServerBootstrap, Bootstrap>> list =
100                 new ArrayList<BootstrapComboFactory<ServerBootstrap, Bootstrap>>();
101 
102         // Make the list of SCTP ServerBootstrap factories.
103         List<BootstrapFactory<ServerBootstrap>> sbfs = sctpServerChannel();
104 
105         // Make the list of SCTP Bootstrap factories.
106         List<BootstrapFactory<Bootstrap>> cbfs = sctpClientChannel();
107 
108         // Populate the combinations
109         for (BootstrapFactory<ServerBootstrap> sbf: sbfs) {
110             for (BootstrapFactory<Bootstrap> cbf: cbfs) {
111                 final BootstrapFactory<ServerBootstrap> sbf0 = sbf;
112                 final BootstrapFactory<Bootstrap> cbf0 = cbf;
113                 list.add(new BootstrapComboFactory<ServerBootstrap, Bootstrap>() {
114                     @Override
115                     public ServerBootstrap newServerInstance() {
116                         return sbf0.newInstance();
117                     }
118 
119                     @Override
120                     public Bootstrap newClientInstance() {
121                         return cbf0.newInstance();
122                     }
123                 });
124             }
125         }
126 
127         return list;
128     }
129 
130     private SctpTestPermutation() { }
131 }