File tree Expand file tree Collapse file tree
src/test/java/fybug/nulll/pdcache Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import java .io .StringWriter ;
99
1010import fybug .nulll .pdcache .memory .memoryTest ;
11+ import fybug .nulll .pdcache .supplier .suppilerTest ;
1112
1213@ RunWith ( Suite .class )
13- @ Suite .SuiteClasses ( {memoryTest .class } )
14+ @ Suite .SuiteClasses ( {memoryTest .class , suppilerTest . class } )
1415public
1516class RunTest {
1617 public static PrintWriter from ;
Original file line number Diff line number Diff line change @@ -36,29 +36,6 @@ void tearDown() throws IOException {
3636 @ Test
3737 public
3838 void cache () throws Exception {
39- var o = new Object ();
40-
41- from .println (o );
42- cache .set (o );
43- cache .get (to ::println );
44-
45- o = null ;
46- System .gc ();
47- from .println ("null" );
48- cache .get (to ::println );
49-
50- o = new Object ();
51-
52- from .println (o );
53- cache .set (o );
54- cache .get (to ::println );
55-
56- check ();
57- }
58-
59- @ Test
60- public
61- void cache1 () throws Exception {
6239 CanClean o = new CanClean () {
6340 public @ NotNull
6441 Runnable getclean () { return () -> to .println ("des:" ); }
Original file line number Diff line number Diff line change 1414import static fybug .nulll .pdcache .RunTest .from ;
1515import static fybug .nulll .pdcache .RunTest .init ;
1616import static fybug .nulll .pdcache .RunTest .to ;
17+
1718public
1819class MapCacheTest {
1920 private MapCache <String , Object > cache ;
@@ -35,30 +36,6 @@ void tearDown() throws IOException {
3536 @ Test
3637 public
3738 void cache () throws Exception {
38- var o = new Object ();
39-
40- from .println (o );
41- cache .put ("asd" , o );
42- cache .get ("asd" , (k , v ) -> to .println (v ));
43-
44- // 模拟回收
45- o = null ;
46- System .gc ();
47- from .println ("null" );
48- cache .get ("asd" , (k , v ) -> to .println (v ));
49-
50- o = new Object ();
51-
52- from .println (o );
53- cache .put ("asd" , o );
54- cache .get ("asd" , (k , v ) -> to .println (v ));
55-
56- check ();
57- }
58-
59- @ Test
60- public
61- void cache1 () throws Exception {
6239 CanClean o = new CanClean () {
6340 public @ NotNull
6441 Runnable getclean () {
Original file line number Diff line number Diff line change 1+ package fybug .nulll .pdcache .supplier .memory ;
2+ import org .junit .After ;
3+ import org .junit .Before ;
4+ import org .junit .Test ;
5+
6+ import java .io .IOException ;
7+ import java .lang .ref .WeakReference ;
8+
9+ import fybug .nulll .pdcache .supplier .suppilerTest ;
10+
11+ import static fybug .nulll .pdcache .RunTest .check ;
12+ import static fybug .nulll .pdcache .RunTest .destruction ;
13+ import static fybug .nulll .pdcache .RunTest .from ;
14+ import static fybug .nulll .pdcache .RunTest .init ;
15+ import static fybug .nulll .pdcache .RunTest .to ;
16+ import static fybug .nulll .pdcache .supplier .suppilerTest .nextClean ;
17+
18+ public
19+ class SCacheTest {
20+ private SCache <Object > cache ;
21+
22+ @ Before
23+ public
24+ void setUp () {
25+ init ();
26+ cache = SCache .build (Object .class )
27+ .createdata (suppilerTest ::getNowClean )
28+ .refernce (WeakReference .class )
29+ .build ();
30+ }
31+
32+ @ After
33+ public
34+ void tearDown () throws IOException {
35+ cache .clear ();
36+ destruction ();
37+ }
38+
39+ @ Test
40+ public
41+ void cache () throws Exception {
42+ from .println (nextClean ());
43+ cache .get (to ::println );
44+
45+ from .println ("des:" );
46+ from .println (nextClean ());
47+ System .gc ();
48+ cache .get (to ::println );
49+
50+ check ();
51+ }
52+ }
Original file line number Diff line number Diff line change 1+ package fybug .nulll .pdcache .supplier .memory ;
2+ import org .junit .After ;
3+ import org .junit .Before ;
4+ import org .junit .Test ;
5+
6+ import java .io .IOException ;
7+ import java .lang .ref .WeakReference ;
8+
9+ import static fybug .nulll .pdcache .RunTest .check ;
10+ import static fybug .nulll .pdcache .RunTest .destruction ;
11+ import static fybug .nulll .pdcache .RunTest .from ;
12+ import static fybug .nulll .pdcache .RunTest .init ;
13+ import static fybug .nulll .pdcache .RunTest .to ;
14+ import static fybug .nulll .pdcache .supplier .suppilerTest .getNowClean ;
15+ import static fybug .nulll .pdcache .supplier .suppilerTest .nextClean ;
16+
17+ public
18+ class SMapCacheTest {
19+ private SMapCache <String , Object > cache ;
20+
21+ @ Before
22+ public
23+ void setUp () {
24+ init ();
25+ cache = SMapCache .build (String .class , Object .class )
26+ .createdata ((k ) -> getNowClean ())
27+ .refernce (WeakReference .class )
28+ .build ();
29+ }
30+
31+ @ After
32+ public
33+ void tearDown () throws IOException {
34+ cache .clear ();
35+ destruction ();
36+ }
37+
38+ @ Test
39+ public
40+ void cache () throws Exception {
41+
42+ from .println (nextClean ());
43+ cache .get ("asd" , (k , v ) -> to .println (v ));
44+
45+ // 模拟回收
46+ from .println ("des:" );
47+ from .println (nextClean ());
48+ System .gc ();
49+ cache .get ("asd" , (k , v ) -> to .println (v ));
50+
51+ check ();
52+ }
53+ }
Original file line number Diff line number Diff line change 1+ package fybug .nulll .pdcache .supplier .memory ;
2+ import org .junit .runner .RunWith ;
3+ import org .junit .runners .Suite ;
4+
5+ import fybug .nulll .pdcache .memory .CacheTest ;
6+ import fybug .nulll .pdcache .memory .MapCacheTest ;
7+
8+ @ RunWith ( Suite .class )
9+ @ Suite .SuiteClasses ( {SCacheTest .class , SMapCacheTest .class } )
10+ public
11+ class memoryTest {}
Original file line number Diff line number Diff line change 1+ package fybug .nulll .pdcache .supplier ;
2+ import org .jetbrains .annotations .NotNull ;
3+ import org .junit .runner .RunWith ;
4+ import org .junit .runners .Suite ;
5+
6+ import fybug .nulll .pdcache .CanClean ;
7+ import fybug .nulll .pdcache .supplier .memory .memoryTest ;
8+
9+ import static fybug .nulll .pdcache .RunTest .to ;
10+
11+ @ RunWith ( Suite .class )
12+ @ Suite .SuiteClasses ( {memoryTest .class } )
13+ public
14+ class suppilerTest {
15+ private static CanClean canClean = new a ();
16+
17+ public static
18+ CanClean getNowClean () { return canClean ; }
19+
20+ public static
21+ CanClean nextClean () { return canClean = new a (); }
22+
23+ private static
24+ class a implements CanClean {
25+ public @ NotNull
26+ Runnable getclean () { return () -> to .println ("des:" ); }
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments