1 package org.apache.jcs.utils.access;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 /***
25 * Test cases for the JCS worker.
26 *
27 * @author Aaron Smuts
28 *
29 */
30 public class JCSWorkerUnitTest
31 extends TestCase
32 {
33
34 /***
35 * Test basic worker funtionality. This is a serial not a concurrent test.
36 * <p>
37 * Just verify that the worker will go to the cache before asking the helper.
38 *
39 * @throws Exception
40 *
41 */
42 public void testSimpleGet()
43 throws Exception
44 {
45 JCSWorker cachingWorker = new JCSWorker( "example region" );
46
47
48 JCSWorkerHelper helper = new AbstractJCSWorkerHelper()
49 {
50 int timesCalled = 0;
51
52 public Object doWork()
53 {
54 Object results = new Long( ++timesCalled );
55 return results;
56 }
57 };
58
59 String key = "abc";
60
61 Long result = (Long) cachingWorker.getResult( key, helper );
62 assertEquals( "Called the wrong number of times", new Long( 1 ), result );
63
64
65 Long result2 = (Long) cachingWorker.getResult( key, helper );
66 assertEquals( "Called the wrong number of times", new Long( 1 ), result2 );
67
68 }
69
70 }