String testString = new String( "This is a test");
Object retrievedObject = null;
CachedObject cacheObject1 = null;
CachedObject cacheObject2 = null;
GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
.getInstance()
.getService( GlobalCacheService.SERVICE_NAME );
// Create and add Object #1
cacheObject1 = new CachedObject(testString);
assertNotNull( "Failed to create a cachable object 1", cacheObject1);
globalCache.addObject(cacheKey, cacheObject1);
retrievedObject = globalCache.getObject(cacheKey);
assertNotNull( "Did not retrieved a cached object 1", retrievedObject);
assertEquals( "Did not retrieved correct cached object", cacheObject1, retrievedObject);
// Create and add Object #2
cacheObject2 = new CachedObject(testString);
assertNotNull( "Failed to create a cachable object 2", cacheObject2);
globalCache.addObject(cacheKey_2, cacheObject2);
retrievedObject = globalCache.getObject(cacheKey_2);
assertNotNull( "Did not retrieved a cached object 2", retrievedObject);
assertEquals( "Did not retrieved correct cached object 2", cacheObject2, retrievedObject);
// Get object #1
retrievedObject = globalCache.getObject(cacheKey);
assertNotNull( "Did not retrieved a cached object 1. Attempt #2", retrievedObject);
assertEquals( "Did not retrieved correct cached object 1. Attempt #2", cacheObject1, retrievedObject);
// Get object #1
retrievedObject = globalCache.getObject(cacheKey);
assertNotNull( "Did not retrieved a cached object 1. Attempt #3", retrievedObject);
assertEquals( "Did not retrieved correct cached object 1. Attempt #3", cacheObject1, retrievedObject);
// Get object #2
retrievedObject = globalCache.getObject(cacheKey_2);
assertNotNull( "Did not retrieved a cached object 2. Attempt #2", retrievedObject);
assertEquals( "Did not retrieved correct cached object 2 Attempt #2", cacheObject2, retrievedObject);
// Remove objects
globalCache.removeObject(cacheKey);
globalCache.removeObject(cacheKey_2);
}