| Method from com.opensymphony.oscache.base.algorithm.TestQueueCache Detail: |
public void testClear() {
getCache().clear();
assertEquals(0, getCache().size());
}
|
public void testContainsKey() {
getCache().put(KEY, CONTENT);
assertTrue(getCache().containsKey(KEY));
getCache().clear();
}
Test the ContainsKey method |
public void testGet() {
// Add an entry and verify that it is there
getCache().put(KEY, CONTENT);
assertTrue(getCache().get(KEY).equals(CONTENT));
// Call with invalid parameters
try {
getCache().get(null);
fail("Get called with null parameters!");
} catch (Exception e) { /* This is what we expect */
}
getCache().clear();
}
|
public void testGetSetMaxEntries() {
// Check that the cache is full, then chop it by one and assert that
// an element has been removed
for (int count = 0; count < MAX_ENTRIES; count++) {
getCache().put(KEY + count, CONTENT + count);
}
assertEquals(MAX_ENTRIES, getCache().size());
getCache().setMaxEntries(MAX_ENTRIES - 1);
assertEquals(MAX_ENTRIES - 1, getCache().getMaxEntries());
assertEquals(MAX_ENTRIES - 1, getCache().size());
// Specify an invalid capacity
try {
getCache().setMaxEntries(INVALID_MAX_ENTRIES);
fail("Cache capacity set with an invalid argument");
} catch (Exception e) {
// This is what we expect
}
getCache().clear();
}
Test the getter and setter for the max entries |
public void testIterator() {
// Verify that the iterator returns MAX_ENTRIES and no more elements
int nbEntries = getCache().size();
Iterator iterator = getCache().entrySet().iterator();
assertNotNull(iterator);
for (int count = 0; count < nbEntries; count++) {
assertNotNull(iterator.next());
}
assertTrue(!iterator.hasNext());
}
|
public void testPut() {
// Put elements in cache
for (int count = 0; count < MAX_ENTRIES; count++) {
getCache().put(KEY + count, CONTENT + count);
}
// Call with invalid parameters
try {
getCache().put(null, null);
fail("Put called with null parameters!");
} catch (Exception e) { /* This is what we expect */
}
getCache().clear();
}
|
public void testPutOverflow() {
// Create a listener
PersistenceListener listener = new DiskPersistenceListener();
Properties p = new Properties();
p.setProperty("cache.path", TestDiskPersistenceListener.CACHEDIR);
p.setProperty("cache.memory", "true");
p.setProperty("cache.persistence.overflow.only", "true");
p.setProperty("cache.persistence.class", "com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener");
listener.configure(new Config(p));
getCache().setPersistenceListener(listener);
getCache().clear();
getCache().setMaxEntries(MAX_ENTRIES);
getCache().setOverflowPersistence(true);
if (getCache() instanceof UnlimitedCache) {
return; // nothing to test since memory will never overflow.
}
// Put elements in cache
for (int count = 0; count < = MAX_ENTRIES; count++) {
getCache().put(KEY + count, CONTENT + count);
}
try {
int numPersisted = 0;
// Check that number of elements persisted == 1 if it is an overflow cache or all
// if it is not overflow and writes every time.
for (int count = 0; count < = MAX_ENTRIES; count++) {
if (getCache().getPersistenceListener().isStored(KEY + count)) {
numPersisted++;
}
}
if (getCache().isOverflowPersistence()) {
assertTrue("Only 1 element should have been persisted ", numPersisted == 1);
} else {
assertTrue("All elements should have been persisted ", numPersisted == (MAX_ENTRIES + 1));
}
} catch (Exception e) {
fail();
}
getCache().clear();
}
Test the put method with overflow parameter set |
public void testRemove() {
getCache().put(KEY, CONTENT);
// Remove the object and assert the return
assertNotNull(getCache().remove(KEY));
getCache().clear();
}
Test the remove from cache |
abstract public void testRemoveItem()
Test the specific algorithms |