|
59 | 59 | import static org.junit.jupiter.api.Assertions.fail; |
60 | 60 |
|
61 | 61 | public class BufferTest { |
62 | | - private static volatile Fixture[] fixtures; |
63 | 62 | private static ExecutorService executor; |
64 | 63 |
|
65 | | - static Fixture[] allocators() { |
66 | | - Fixture[] fxs = fixtures; |
67 | | - if (fxs != null) { |
68 | | - return fxs; |
69 | | - } |
70 | | - return fixtures = fixtureCombinations().toArray(Fixture[]::new); |
71 | | - } |
| 64 | + private static final Memoize<Fixture[]> ALL_COMBINATIONS = new Memoize<>( |
| 65 | + () -> fixtureCombinations().toArray(Fixture[]::new)); |
| 66 | + private static final Memoize<Fixture[]> NON_SLICED = new Memoize<>( |
| 67 | + () -> Arrays.stream(ALL_COMBINATIONS.get()).filter(f -> !f.isSlice()).toArray(Fixture[]::new)); |
| 68 | + private static final Memoize<Fixture[]> NON_COMPOSITE = new Memoize<>( |
| 69 | + () -> Arrays.stream(ALL_COMBINATIONS.get()).filter(f -> !f.isComposite()).toArray(Fixture[]::new)); |
| 70 | + private static final Memoize<Fixture[]> HEAP_ALLOCS = new Memoize<>( |
| 71 | + () -> Arrays.stream(ALL_COMBINATIONS.get()).filter(f -> f.isHeap()).toArray(Fixture[]::new)); |
| 72 | + private static final Memoize<Fixture[]> DIRECT_ALLOCS = new Memoize<>( |
| 73 | + () -> Arrays.stream(ALL_COMBINATIONS.get()).filter(f -> f.isDirect()).toArray(Fixture[]::new)); |
| 74 | + private static final Memoize<Fixture[]> POOLED_ALLOCS = new Memoize<>( |
| 75 | + () -> Arrays.stream(ALL_COMBINATIONS.get()).filter(f -> f.isPooled()).toArray(Fixture[]::new)); |
72 | 76 |
|
73 | | - static List<Fixture> initialAllocators() { |
74 | | - return List.of( |
75 | | - new Fixture("heap", BufferAllocator::heap, HEAP), |
76 | | - new Fixture("direct", BufferAllocator::direct, DIRECT, CLEANER), |
77 | | - new Fixture("pooledHeap", BufferAllocator::pooledHeap, POOLED, HEAP), |
78 | | - new Fixture("pooledDirect", BufferAllocator::pooledDirect, POOLED, DIRECT, CLEANER)); |
| 77 | + static Fixture[] allocators() { |
| 78 | + return ALL_COMBINATIONS.get(); |
79 | 79 | } |
80 | 80 |
|
81 | | - static Stream<Fixture> nonSliceAllocators() { |
82 | | - return fixtureCombinations().filter(f -> !f.isSlice()); |
| 81 | + static Fixture[] nonSliceAllocators() { |
| 82 | + return NON_SLICED.get(); |
83 | 83 | } |
84 | 84 |
|
85 | | - static Stream<Fixture> nonCompositeAllocators() { |
86 | | - return fixtureCombinations().filter(f -> !f.isComposite()); |
| 85 | + static Fixture[] nonCompositeAllocators() { |
| 86 | + return NON_COMPOSITE.get(); |
87 | 87 | } |
88 | 88 |
|
89 | | - static Stream<Fixture> heapAllocators() { |
90 | | - return fixtureCombinations().filter(Fixture::isHeap); |
| 89 | + static Fixture[] heapAllocators() { |
| 90 | + return HEAP_ALLOCS.get(); |
91 | 91 | } |
92 | 92 |
|
93 | | - static Stream<Fixture> directAllocators() { |
94 | | - return fixtureCombinations().filter(Fixture::isDirect); |
| 93 | + static Fixture[] directAllocators() { |
| 94 | + return DIRECT_ALLOCS.get(); |
95 | 95 | } |
96 | 96 |
|
97 | | - static Stream<Fixture> directPooledAllocators() { |
98 | | - return fixtureCombinations().filter(f -> f.isDirect() && f.isCleaner() && f.isPooled()); |
| 97 | + static Fixture[] pooledAllocators() { |
| 98 | + return POOLED_ALLOCS.get(); |
99 | 99 | } |
100 | 100 |
|
101 | | - static Stream<Fixture> pooledAllocators() { |
102 | | - return fixtureCombinations().filter(Fixture::isPooled); |
| 101 | + static List<Fixture> initialAllocators() { |
| 102 | + return List.of( |
| 103 | + new Fixture("heap", BufferAllocator::heap, HEAP), |
| 104 | + new Fixture("direct", BufferAllocator::direct, DIRECT, CLEANER), |
| 105 | + new Fixture("pooledHeap", BufferAllocator::pooledHeap, POOLED, HEAP), |
| 106 | + new Fixture("pooledDirect", BufferAllocator::pooledDirect, POOLED, DIRECT, CLEANER)); |
103 | 107 | } |
104 | 108 |
|
105 | 109 | private static Stream<Fixture> fixtureCombinations() { |
106 | | - Fixture[] fxs = fixtures; |
107 | | - if (fxs != null) { |
108 | | - return Arrays.stream(fxs); |
109 | | - } |
110 | 110 | List<Fixture> initFixtures = initialAllocators(); |
111 | 111 | Builder<Fixture> builder = Stream.builder(); |
112 | 112 | initFixtures.forEach(builder); |
|
0 commit comments