1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.testsuite.transport;
17
18 import io.netty.bootstrap.AbstractBootstrap;
19 import io.netty.buffer.AdaptiveByteBufAllocator;
20 import io.netty.buffer.ByteBuf;
21 import io.netty.buffer.ByteBufAllocator;
22 import io.netty.buffer.PooledByteBufAllocator;
23 import io.netty.buffer.Unpooled;
24 import io.netty.buffer.UnpooledByteBufAllocator;
25
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.concurrent.ThreadLocalRandom;
29
30 public final class TestsuitePermutation {
31 private static final AdaptiveByteBufAllocator DEFAULT_ADAPTIVE_ALLOCATOR = new AdaptiveByteBufAllocator();
32
33 public static List<ByteBufAllocator> allocator() {
34 List<ByteBufAllocator> allocators = new ArrayList<ByteBufAllocator>();
35 allocators.add(UnpooledByteBufAllocator.DEFAULT);
36 allocators.add(PooledByteBufAllocator.DEFAULT);
37 allocators.add(DEFAULT_ADAPTIVE_ALLOCATOR);
38 return allocators;
39 }
40
41 private TestsuitePermutation() { }
42
43 public interface BootstrapFactory<CB extends AbstractBootstrap<?, ?>> {
44 CB newInstance();
45 }
46
47 public interface BootstrapComboFactory<SB extends AbstractBootstrap<?, ?>, CB extends AbstractBootstrap<?, ?>> {
48 SB newServerInstance();
49 CB newClientInstance();
50 }
51
52 public static ByteBuf randomBufferType(ByteBufAllocator allocator, byte[] data, int offset, int length) {
53 if (ThreadLocalRandom.current().nextBoolean()) {
54 return allocator.directBuffer().writeBytes(data, offset, length);
55 }
56 return Unpooled.wrappedBuffer(data, offset, length);
57 }
58 }