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