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 BOSSES = 2;
39      private static final int WORKERS = 3;
40      private static final EventLoopGroup nioBossGroup =
41              new NioEventLoopGroup(BOSSES, new DefaultThreadFactory("testsuite-sctp-nio-boss", true));
42      private static final EventLoopGroup nioWorkerGroup =
43              new NioEventLoopGroup(WORKERS, new DefaultThreadFactory("testsuite-sctp-nio-worker", true));
44      private static final EventLoopGroup oioBossGroup =
45              new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-sctp-oio-boss", true));
46      private static final EventLoopGroup oioWorkerGroup =
47              new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-sctp-oio-worker", true));
48  
49      static List<BootstrapFactory<ServerBootstrap>> sctpServerChannel() {
50          if (!TestUtils.isSctpSupported()) {
51              return Collections.emptyList();
52          }
53  
54          List<BootstrapFactory<ServerBootstrap>> list = new ArrayList<BootstrapFactory<ServerBootstrap>>();
55          // Make the list of ServerBootstrap factories.
56          list.add(new BootstrapFactory<ServerBootstrap>() {
57              @Override
58              public ServerBootstrap newInstance() {
59                  return new ServerBootstrap().
60                          group(nioBossGroup, nioWorkerGroup).
61                          channel(NioSctpServerChannel.class);
62              }
63          });
64          list.add(new BootstrapFactory<ServerBootstrap>() {
65              @Override
66              public ServerBootstrap newInstance() {
67                  return new ServerBootstrap().
68                          group(oioBossGroup, oioWorkerGroup).
69                          channel(OioSctpServerChannel.class);
70              }
71          });
72  
73          return list;
74      }
75  
76      static List<BootstrapFactory<Bootstrap>> sctpClientChannel() {
77          if (!TestUtils.isSctpSupported()) {
78              return Collections.emptyList();
79          }
80  
81          List<BootstrapFactory<Bootstrap>> list = new ArrayList<BootstrapFactory<Bootstrap>>();
82          list.add(new BootstrapFactory<Bootstrap>() {
83              @Override
84              public Bootstrap newInstance() {
85                  return new Bootstrap().group(nioWorkerGroup).channel(NioSctpChannel.class);
86              }
87          });
88          list.add(new BootstrapFactory<Bootstrap>() {
89              @Override
90              public Bootstrap newInstance() {
91                  return new Bootstrap().group(oioWorkerGroup).channel(OioSctpChannel.class);
92              }
93          });
94          return list;
95      }
96  
97      static List<BootstrapComboFactory<ServerBootstrap, Bootstrap>> sctpChannel() {
98          List<BootstrapComboFactory<ServerBootstrap, Bootstrap>> list =
99                  new ArrayList<BootstrapComboFactory<ServerBootstrap, Bootstrap>>();
100 
101         // Make the list of SCTP ServerBootstrap factories.
102         List<BootstrapFactory<ServerBootstrap>> sbfs = sctpServerChannel();
103 
104         // Make the list of SCTP Bootstrap factories.
105         List<BootstrapFactory<Bootstrap>> cbfs = sctpClientChannel();
106 
107         // Populate the combinations
108         for (BootstrapFactory<ServerBootstrap> sbf: sbfs) {
109             for (BootstrapFactory<Bootstrap> cbf: cbfs) {
110                 final BootstrapFactory<ServerBootstrap> sbf0 = sbf;
111                 final BootstrapFactory<Bootstrap> cbf0 = cbf;
112                 list.add(new BootstrapComboFactory<ServerBootstrap, Bootstrap>() {
113                     @Override
114                     public ServerBootstrap newServerInstance() {
115                         return sbf0.newInstance();
116                     }
117 
118                     @Override
119                     public Bootstrap newClientInstance() {
120                         return cbf0.newInstance();
121                     }
122                 });
123             }
124         }
125 
126         return list;
127     }
128 
129     private SctpTestPermutation() { }
130 }