1 package org.apache.commons.jcs3;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.LinkedList;
24 import java.util.Random;
25
26 import org.apache.commons.jcs3.access.CacheAccess;
27
28 import junit.framework.TestCase;
29
30
31
32
33 public class JCSUnitTest
34 extends TestCase
35 {
36
37 Random random = new Random();
38
39
40
41
42 public void testJCS()
43 throws Exception
44 {
45 final CacheAccess<String, LinkedList<HashMap<String, String>>> jcs = JCS.getInstance( "testCache1" );
46
47 final LinkedList<HashMap<String, String>> list = buildList();
48
49 jcs.put( "some:key", list );
50
51 assertEquals( list, jcs.get( "some:key" ) );
52 }
53
54
55
56
57 private LinkedList<HashMap<String, String>> buildList()
58 {
59 final LinkedList<HashMap<String, String>> list = new LinkedList<>();
60
61 for ( int i = 0; i < 100; i++ )
62 {
63 list.add( buildMap() );
64 }
65
66 return list;
67 }
68
69
70
71
72 private HashMap<String, String> buildMap()
73 {
74 final HashMap<String, String> map = new HashMap<>();
75
76 final byte[] keyBytes = new byte[32];
77 final byte[] valBytes = new byte[128];
78
79 for ( int i = 0; i < 10; i++ )
80 {
81 random.nextBytes( keyBytes );
82 random.nextBytes( valBytes );
83
84 map.put( new String( keyBytes ), new String( valBytes ) );
85 }
86
87 return map;
88 }
89 }