11package net .bytebuddy .benchmark ;
22
33import net .bytebuddy .benchmark .specimen .ExampleClass ;
4+ import net .bytebuddy .test .utility .JavaVersionRule ;
5+ import net .bytebuddy .test .utility .UnsafeAccessRule ;
46import org .hamcrest .CoreMatchers ;
57import org .junit .Before ;
8+ import org .junit .Rule ;
69import org .junit .Test ;
10+ import org .junit .rules .MethodRule ;
711
812import static org .hamcrest .CoreMatchers .is ;
913import static org .hamcrest .CoreMatchers .not ;
1014import static org .hamcrest .MatcherAssert .assertThat ;
1115
1216public class ClassByExtensionBenchmarkTest {
1317
18+ @ Rule
19+ public MethodRule javaVersionRule = new JavaVersionRule ();
20+
21+ @ Rule
22+ public MethodRule unsafeAccessRule = new UnsafeAccessRule ();
23+
1424 private static final boolean BOOLEAN_VALUE = true ;
1525
1626 private static final byte BYTE_VALUE = 42 ;
@@ -75,6 +85,7 @@ public void testBaseline() throws Exception {
7585 }
7686
7787 @ Test
88+ @ UnsafeAccessRule .Enforce
7889 public void testByteBuddyWithProxiesClassCreation () throws Exception {
7990 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithProxy ();
8091 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -84,6 +95,7 @@ public void testByteBuddyWithProxiesClassCreation() throws Exception {
8495 }
8596
8697 @ Test
98+ @ UnsafeAccessRule .Enforce
8799 public void testByteBuddyWithProxiesClassCreationCached () throws Exception {
88100 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithProxyAndReusedDelegator ();
89101 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -93,6 +105,7 @@ public void testByteBuddyWithProxiesClassCreationCached() throws Exception {
93105 }
94106
95107 @ Test
108+ @ UnsafeAccessRule .Enforce
96109 public void testByteBuddyWithProxiesClassCreationWithTypePool () throws Exception {
97110 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithProxyWithTypePool ();
98111 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -102,6 +115,7 @@ public void testByteBuddyWithProxiesClassCreationWithTypePool() throws Exception
102115 }
103116
104117 @ Test
118+ @ UnsafeAccessRule .Enforce
105119 public void testByteBuddyWithProxiesClassCreationCachedWithTypePool () throws Exception {
106120 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithProxyAndReusedDelegatorWithTypePool ();
107121 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -111,6 +125,7 @@ public void testByteBuddyWithProxiesClassCreationCachedWithTypePool() throws Exc
111125 }
112126
113127 @ Test
128+ @ UnsafeAccessRule .Enforce
114129 public void testByteBuddyWithAccessorClassCreation () throws Exception {
115130 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithAccessor ();
116131 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -120,6 +135,7 @@ public void testByteBuddyWithAccessorClassCreation() throws Exception {
120135 }
121136
122137 @ Test
138+ @ UnsafeAccessRule .Enforce
123139 public void testByteBuddyWithAccessorClassCreationCached () throws Exception {
124140 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithAccessorAndReusedDelegator ();
125141 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -129,6 +145,7 @@ public void testByteBuddyWithAccessorClassCreationCached() throws Exception {
129145 }
130146
131147 @ Test
148+ @ UnsafeAccessRule .Enforce
132149 public void testByteBuddyWithAccessorClassCreationWithTypePool () throws Exception {
133150 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithAccessorWithTypePool ();
134151 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -138,6 +155,7 @@ public void testByteBuddyWithAccessorClassCreationWithTypePool() throws Exceptio
138155 }
139156
140157 @ Test
158+ @ UnsafeAccessRule .Enforce
141159 public void testByteBuddyWithAccessorClassCreationCachedWithTypePool () throws Exception {
142160 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithAccessorAndReusedDelegatorWithTypePool ();
143161 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -147,6 +165,7 @@ public void testByteBuddyWithAccessorClassCreationCachedWithTypePool() throws Ex
147165 }
148166
149167 @ Test
168+ @ UnsafeAccessRule .Enforce
150169 public void testByteBuddyWithPrefixClassCreation () throws Exception {
151170 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithPrefix ();
152171 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -156,6 +175,7 @@ public void testByteBuddyWithPrefixClassCreation() throws Exception {
156175 }
157176
158177 @ Test
178+ @ UnsafeAccessRule .Enforce
159179 public void testByteBuddyWithPrefixClassCreationCached () throws Exception {
160180 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithPrefixAndReusedDelegator ();
161181 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -165,6 +185,7 @@ public void testByteBuddyWithPrefixClassCreationCached() throws Exception {
165185 }
166186
167187 @ Test
188+ @ UnsafeAccessRule .Enforce
168189 public void testByteBuddyWithPrefixClassCreationWithTypePool () throws Exception {
169190 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithPrefixWithTypePool ();
170191 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -174,6 +195,7 @@ public void testByteBuddyWithPrefixClassCreationWithTypePool() throws Exception
174195 }
175196
176197 @ Test
198+ @ UnsafeAccessRule .Enforce
177199 public void testByteBuddyWithPrefixClassCreationCachedWithTypePool () throws Exception {
178200 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddyWithPrefixAndReusedDelegatorWithTypePool ();
179201 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -183,6 +205,7 @@ public void testByteBuddyWithPrefixClassCreationCachedWithTypePool() throws Exce
183205 }
184206
185207 @ Test
208+ @ UnsafeAccessRule .Enforce
186209 public void testByteBuddySpecializedClassCreation () throws Exception {
187210 ExampleClass instance = classByExtensionBenchmark .benchmarkByteBuddySpecialized ();
188211 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -192,6 +215,8 @@ public void testByteBuddySpecializedClassCreation() throws Exception {
192215 }
193216
194217 @ Test
218+ @ JavaVersionRule .Enforce (atMost = 10 )
219+ @ UnsafeAccessRule .Enforce
195220 public void testCglibClassCreation () throws Exception {
196221 ExampleClass instance = classByExtensionBenchmark .benchmarkCglib ();
197222 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
@@ -201,6 +226,8 @@ public void testCglibClassCreation() throws Exception {
201226 }
202227
203228 @ Test
229+ @ JavaVersionRule .Enforce (atMost = 10 )
230+ @ UnsafeAccessRule .Enforce
204231 public void testJavassistClassCreation () throws Exception {
205232 ExampleClass instance = classByExtensionBenchmark .benchmarkJavassist ();
206233 assertThat (instance .getClass (), not (CoreMatchers .<Class <?>>is (ClassByExtensionBenchmark .BASE_CLASS )));
0 commit comments