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 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          // Make the list of ServerBootstrap factories.
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          // Make the list of SCTP ServerBootstrap factories.
98          List<BootstrapFactory<ServerBootstrap>> sbfs = sctpServerChannel();
99  
100         // Make the list of SCTP Bootstrap factories.
101         List<BootstrapFactory<Bootstrap>> cbfs = sctpClientChannel();
102 
103         // Populate the combinations
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 }