@@ -34,52 +34,52 @@ public class SWDescriptionStrategyCacheTest {
3434
3535 @ Test
3636 public void testWeakHashMapCacheCleanup () throws Exception {
37- // 获取静态缓存字段
37+ // Get static cache field
3838 Field cacheField = SWDescriptionStrategy .SWTypeDescriptionWrapper .class
3939 .getDeclaredField ("CLASS_LOADER_TYPE_CACHE" );
4040 cacheField .setAccessible (true );
4141 @ SuppressWarnings ("unchecked" )
4242 Map <ClassLoader , Map <String , SWDescriptionStrategy .TypeCache >> cache =
4343 (Map <ClassLoader , Map <String , SWDescriptionStrategy .TypeCache >>) cacheField .get (null );
4444
45- // 记录初始缓存大小
45+ // Record initial cache size
4646 int initialCacheSize = cache .size ();
4747
48- // 创建测试用的ClassLoader
48+ // Create test ClassLoader
4949 URLClassLoader testClassLoader = new URLClassLoader (new URL [0 ], null );
5050 String testTypeName = "com.test.DynamicClass" ;
5151
52- // 创建SWTypeDescriptionWrapper实例
52+ // Create SWTypeDescriptionWrapper instance
5353 SWDescriptionStrategy .SWTypeDescriptionWrapper wrapper =
5454 new SWDescriptionStrategy .SWTypeDescriptionWrapper (
5555 null , "test" , testClassLoader , testTypeName );
5656
57- // 通过反射调用getTypeCache方法触发缓存
57+ // Call getTypeCache method via reflection to trigger caching
5858 Method getTypeCacheMethod = wrapper .getClass ()
5959 .getDeclaredMethod ("getTypeCache" );
6060 getTypeCacheMethod .setAccessible (true );
6161 SWDescriptionStrategy .TypeCache typeCache =
6262 (SWDescriptionStrategy .TypeCache ) getTypeCacheMethod .invoke (wrapper );
6363
64- // 验证缓存中存在该ClassLoader
64+ // Verify that the ClassLoader exists in cache
6565 Assert .assertTrue ("Cache should contain the test ClassLoader" ,
6666 cache .containsKey (testClassLoader ));
6767 Assert .assertNotNull ("TypeCache should be created" , typeCache );
6868 Assert .assertEquals ("Cache size should increase by 1" ,
6969 initialCacheSize + 1 , cache .size ());
7070
71- // 清除ClassLoader引用,准备GC测试
71+ // Clear ClassLoader references, prepare for GC test
7272 testClassLoader = null ;
7373 wrapper = null ;
7474 typeCache = null ;
7575
76- // 强制垃圾回收
76+ // Force garbage collection
7777 System .gc ();
7878 Thread .sleep (100 );
7979 System .gc ();
8080 Thread .sleep (100 );
8181
82- // WeakHashMap应该自动清理被回收的ClassLoader条目
82+ // WeakHashMap should automatically clean up garbage collected ClassLoader entries
8383 int attempts = 0 ;
8484 int currentCacheSize = cache .size ();
8585 while (currentCacheSize > initialCacheSize && attempts < 20 ) {
@@ -92,14 +92,14 @@ public void testWeakHashMapCacheCleanup() throws Exception {
9292 System .out .println ("Cache size after GC: " + currentCacheSize +
9393 " (initial: " + initialCacheSize + ", attempts: " + attempts + ")" );
9494
95- // 验证WeakHashMap的清理机制工作正常
95+ // Verify that WeakHashMap cleanup mechanism works properly
9696 Assert .assertTrue ("WeakHashMap should clean up entries or attempts should be reasonable" ,
9797 currentCacheSize <= initialCacheSize + 1 && attempts < 20 );
9898 }
9999
100100 @ Test
101101 public void testBootstrapClassLoaderHandling () throws Exception {
102- // 获取Bootstrap ClassLoader缓存字段
102+ // Get Bootstrap ClassLoader cache field
103103 Field bootstrapCacheField = SWDescriptionStrategy .SWTypeDescriptionWrapper .class
104104 .getDeclaredField ("BOOTSTRAP_TYPE_CACHE" );
105105 bootstrapCacheField .setAccessible (true );
@@ -109,20 +109,20 @@ public void testBootstrapClassLoaderHandling() throws Exception {
109109
110110 int initialBootstrapCacheSize = bootstrapCache .size ();
111111
112- // 测试Bootstrap ClassLoader (null) 的处理
112+ // Test Bootstrap ClassLoader (null) handling
113113 String testTypeName = "test.BootstrapClass" ;
114114 SWDescriptionStrategy .SWTypeDescriptionWrapper wrapper =
115115 new SWDescriptionStrategy .SWTypeDescriptionWrapper (
116116 null , "test" , null , testTypeName );
117117
118- // 通过反射调用getTypeCache方法
118+ // Call getTypeCache method via reflection
119119 Method getTypeCacheMethod = wrapper .getClass ()
120120 .getDeclaredMethod ("getTypeCache" );
121121 getTypeCacheMethod .setAccessible (true );
122122 SWDescriptionStrategy .TypeCache typeCache =
123123 (SWDescriptionStrategy .TypeCache ) getTypeCacheMethod .invoke (wrapper );
124124
125- // 验证Bootstrap ClassLoader的缓存处理
125+ // Verify Bootstrap ClassLoader cache handling
126126 Assert .assertNotNull ("TypeCache should be created for bootstrap classloader" , typeCache );
127127 Assert .assertTrue ("Bootstrap cache should contain the type" ,
128128 bootstrapCache .containsKey (testTypeName ));
@@ -141,20 +141,20 @@ public void testMultipleClassLoadersIndependentCache() throws Exception {
141141
142142 int initialCacheSize = cache .size ();
143143
144- // 创建两个不同的ClassLoader
144+ // Create two different ClassLoaders
145145 URLClassLoader classLoader1 = new URLClassLoader (new URL [0 ], null );
146146 URLClassLoader classLoader2 = new URLClassLoader (new URL [0 ], null );
147147 String testTypeName = "com.test.SameClassName" ;
148148
149- // 为两个ClassLoader创建相同类名的TypeCache
149+ // Create TypeCache with same class name for both ClassLoaders
150150 SWDescriptionStrategy .SWTypeDescriptionWrapper wrapper1 =
151151 new SWDescriptionStrategy .SWTypeDescriptionWrapper (
152152 null , "test" , classLoader1 , testTypeName );
153153 SWDescriptionStrategy .SWTypeDescriptionWrapper wrapper2 =
154154 new SWDescriptionStrategy .SWTypeDescriptionWrapper (
155155 null , "test" , classLoader2 , testTypeName );
156156
157- // 通过反射调用getTypeCache方法
157+ // Call getTypeCache method via reflection
158158 Method getTypeCacheMethod =
159159 SWDescriptionStrategy .SWTypeDescriptionWrapper .class .getDeclaredMethod ("getTypeCache" );
160160 getTypeCacheMethod .setAccessible (true );
@@ -164,18 +164,18 @@ public void testMultipleClassLoadersIndependentCache() throws Exception {
164164 SWDescriptionStrategy .TypeCache typeCache2 =
165165 (SWDescriptionStrategy .TypeCache ) getTypeCacheMethod .invoke (wrapper2 );
166166
167- // 验证两个ClassLoader有独立的缓存项
167+ // Verify that the two ClassLoaders have independent cache entries
168168 Assert .assertNotNull ("TypeCache1 should be created" , typeCache1 );
169169 Assert .assertNotNull ("TypeCache2 should be created" , typeCache2 );
170170 Assert .assertNotSame ("TypeCaches should be different instances" , typeCache1 , typeCache2 );
171171
172- // 验证缓存结构
172+ // Verify cache structure
173173 Assert .assertEquals ("Cache should contain both classloaders" ,
174174 initialCacheSize + 2 , cache .size ());
175175 Assert .assertTrue ("Cache should contain classloader1" , cache .containsKey (classLoader1 ));
176176 Assert .assertTrue ("Cache should contain classloader2" , cache .containsKey (classLoader2 ));
177177
178- // 验证每个ClassLoader有独立的类型缓存
178+ // Verify each ClassLoader has independent type cache
179179 Map <String , SWDescriptionStrategy .TypeCache > typeCacheMap1 = cache .get (classLoader1 );
180180 Map <String , SWDescriptionStrategy .TypeCache > typeCacheMap2 = cache .get (classLoader2 );
181181
@@ -191,14 +191,14 @@ public void testMultipleClassLoadersIndependentCache() throws Exception {
191191
192192 @ Test
193193 public void testConcurrentAccess () throws Exception {
194- // 测试并发访问场景
194+ // Test concurrent access scenario
195195 final String testTypeName = "com.test.ConcurrentClass" ;
196196 final int threadCount = 10 ;
197197 final Thread [] threads = new Thread [threadCount ];
198198 final URLClassLoader [] classLoaders = new URLClassLoader [threadCount ];
199199 final SWDescriptionStrategy .TypeCache [] results = new SWDescriptionStrategy .TypeCache [threadCount ];
200200
201- // 创建多个线程同时访问缓存
201+ // Create multiple threads to access cache simultaneously
202202 for (int i = 0 ; i < threadCount ; i ++) {
203203 final int index = i ;
204204 classLoaders [i ] = new URLClassLoader (new URL [0 ], null );
@@ -219,17 +219,17 @@ public void testConcurrentAccess() throws Exception {
219219 });
220220 }
221221
222- // 启动所有线程
222+ // Start all threads
223223 for (Thread thread : threads ) {
224224 thread .start ();
225225 }
226226
227- // 等待所有线程完成
227+ // Wait for all threads to complete
228228 for (Thread thread : threads ) {
229- thread .join (1000 ); // 最多等待1秒
229+ thread .join (1000 ); // Wait at most 1 second
230230 }
231231
232- // 验证所有结果
232+ // Verify all results
233233 for (int i = 0 ; i < threadCount ; i ++) {
234234 Assert .assertNotNull ("Result " + i + " should not be null" , results [i ]);
235235 }
0 commit comments