1 package org.apache.jcs;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25
26 import org.apache.jcs.JCS;
27
28 import java.util.LinkedList;
29 import java.util.HashMap;
30 import java.util.Random;
31
32 /***
33 * Simple test for the JCS class.
34 *
35 * @version $Id: JCSUniTest.java 536904 2007-05-10 16:03:42Z tv $
36 */
37 public class JCSUniTest
38 extends TestCase
39 {
40 Random random = new Random();
41
42 /***
43 * @param testName
44 */
45 public JCSUniTest( String testName )
46 {
47 super( testName );
48 }
49
50 /***
51 * @return Test
52 */
53 public static Test suite()
54 {
55 return new TestSuite( JCSUniTest.class );
56 }
57
58 /***
59 * @param args
60 */
61 public static void main( String args[] )
62 {
63 String[] testCaseName = { JCSUniTest.class.getName() };
64 junit.textui.TestRunner.main( testCaseName );
65 }
66
67 /***
68 * @throws Exception
69 */
70 public void testJCS()
71 throws Exception
72 {
73 JCS jcs = JCS.getInstance( "testCache1" );
74
75 LinkedList list = buildList();
76
77 jcs.put( "some:key", list );
78
79 assertEquals( list, jcs.get( "some:key" ) );
80 }
81
82 private LinkedList buildList()
83 {
84 LinkedList list = new LinkedList();
85
86 for ( int i = 0; i < 100; i++ )
87 {
88 list.add( buildMap() );
89 }
90
91 return list;
92 }
93
94 private HashMap buildMap()
95 {
96 HashMap map = new HashMap();
97
98 byte[] keyBytes = new byte[32];
99 byte[] valBytes = new byte[128];
100
101 for ( int i = 0; i < 10; i++ )
102 {
103 random.nextBytes( keyBytes );
104 random.nextBytes( valBytes );
105
106 map.put( new String( keyBytes ), new String( valBytes ) );
107 }
108
109 return map;
110 }
111
112 }