01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package edu.iu.uis.eden.cache;
17:
18: import javax.xml.namespace.QName;
19:
20: import org.junit.Test;
21: import org.kuali.bus.test.KSBTestCase;
22:
23: public class RiceCacheAdministratorTest extends KSBTestCase {
24:
25: String key = "_key";
26: Object value = "_value";
27: String group = "_group";
28:
29: @Override
30: public boolean startClient1() {
31: return true;
32: }
33:
34: @Test
35: public void testCache() throws Exception {
36:
37: loadCaches();
38: assertCachesNotEmpty();
39:
40: //drive invalidation from this cache
41: RiceCacheAdministrator cache = (RiceCacheAdministrator) getSpringContextResourceLoader()
42: .getService(new QName("cache"));
43: cache.flushAll();
44: //these waits are extreme and things rarely take this long but when CI bogs down it can take a while
45: Thread.sleep(4000);
46: assertCachesEmpty();
47:
48: loadCaches();
49: assertCachesNotEmpty();
50:
51: cache.flushEntry(this .key);
52: Thread.sleep(4000);
53: assertCachesEmpty();
54:
55: loadCaches();
56: assertCachesNotEmpty();
57:
58: cache.flushGroup(this .group);
59: Thread.sleep(4000);
60: assertCachesEmpty();
61:
62: loadCaches();
63: assertCachesNotEmpty();
64:
65: }
66:
67: private void assertCachesNotEmpty() throws Exception {
68: RiceCacheAdministrator cache = (RiceCacheAdministrator) getSpringContextResourceLoader()
69: .getService(new QName("cache"));
70: RiceCacheAdministrator client1Cache = (RiceCacheAdministrator) getServiceFromTestClient1SpringContext("cache");
71:
72: assertEquals(this .value, cache.getFromCache(this .key));
73: assertEquals(this .value, client1Cache.getFromCache(this .key));
74: }
75:
76: private void assertCachesEmpty() throws Exception {
77: RiceCacheAdministrator cache = (RiceCacheAdministrator) getSpringContextResourceLoader()
78: .getService(new QName("cache"));
79: RiceCacheAdministrator client1Cache = (RiceCacheAdministrator) getServiceFromTestClient1SpringContext("cache");
80:
81: assertNull(cache.getFromCache(this .key));
82: assertNull(client1Cache.getFromCache(this .key));
83: }
84:
85: private void loadCaches() throws Exception {
86: RiceCacheAdministrator cache = (RiceCacheAdministrator) getSpringContextResourceLoader()
87: .getService(new QName("cache"));
88: RiceCacheAdministrator client1Cache = (RiceCacheAdministrator) getServiceFromTestClient1SpringContext("cache");
89:
90: cache.putInCache(this.key, this.value, this.group);
91: client1Cache.putInCache(this.key, this.value, this.group);
92: }
93:
94: }
|