1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.testsuite.transport;
17
18 import io.netty5.bootstrap.AbstractBootstrap;
19 import io.netty5.buffer.api.BufferAllocator;
20 import io.netty5.testsuite.transport.TestsuitePermutation.AllocatorConfig;
21 import io.netty5.testsuite.util.TestUtils;
22 import io.netty5.util.internal.StringUtil;
23 import io.netty5.util.internal.logging.InternalLogger;
24 import io.netty5.util.internal.logging.InternalLoggerFactory;
25 import org.junit.jupiter.api.TestInfo;
26
27 import java.util.List;
28
29 public abstract class AbstractComboTestsuiteTest<SB extends AbstractBootstrap<?, ?, ?>,
30 CB extends AbstractBootstrap<?, ?, ?>> {
31 protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
32 protected volatile CB cb;
33 protected volatile SB sb;
34
35 protected abstract List<TestsuitePermutation.BootstrapComboFactory<SB, CB>> newFactories();
36
37 protected List<AllocatorConfig> newAllocators() {
38 return TestsuitePermutation.allocator();
39 }
40
41 protected void run(TestInfo testInfo, Runner<SB, CB> runner) throws Throwable {
42 List<TestsuitePermutation.BootstrapComboFactory<SB, CB>> combos = newFactories();
43 String methodName = TestUtils.testMethodName(testInfo);
44 for (AllocatorConfig config: newAllocators()) {
45 int i = 0;
46 for (TestsuitePermutation.BootstrapComboFactory<SB, CB> e : combos) {
47 sb = e.newServerInstance();
48 cb = e.newClientInstance();
49 configure(sb, cb, config.bufferAllocator);
50 logger.info(String.format(
51 "Running: %s %d of %d (%s + %s) with %s",
52 methodName, ++i, combos.size(), sb, cb,
53 StringUtil.simpleClassName(config.bufferAllocator)));
54 runner.run(sb, cb);
55 }
56 }
57 }
58
59 protected abstract void configure(SB sb, CB cb, BufferAllocator bufferAllocator);
60
61 public interface Runner<SB extends AbstractBootstrap<?, ?, ?>, CB extends AbstractBootstrap<?, ?, ?>> {
62 void run(SB sb, CB cb) throws Throwable;
63 }
64 }