/**
* Tests overflow of maxNumOfBytes() of a CACHE.
*/
public void testByteOverflow() {
I_Map i_map = this.currMap;
ME = "I_MapTest.testByteOverflow(" + i_map.getStorageId() + ")[" + i_map.getClass().getName() + "]";
System.out.println("***" + ME);
try {
StorageId storageId = new StorageId(glob, "msgUnitStore", "ByteOverflowMapId");
QueuePropertyBase prop = new MsgUnitStoreProperty(glob, "/node/test");
MsgUnitWrapper mu = new MsgUnitWrapper(glob, createMsgUnit(false, 0), storageId);
long sizeEmpty = mu.getSizeInBytes();
MsgUnitWrapper[] queueEntries = {
new MsgUnitWrapper(glob, createMsgUnit(false, 0), storageId),
new MsgUnitWrapper(glob, createMsgUnit(false, 0), storageId),
new MsgUnitWrapper(glob, createMsgUnit(false, 0), storageId),
// Each above entry has 3,311 bytes = 9,922, the next one has 9,932 bytes
// so when it is entered two of the above need to be swapped away
// as maxBytes=13,244
new MsgUnitWrapper(glob, createMsgUnit(false, 2*sizeEmpty-1), storageId),
new MsgUnitWrapper(glob, createMsgUnit(false, 0), storageId)};
final long maxBytesCache = 4*sizeEmpty;
prop.setMaxBytes(1000000);
prop.setMaxBytesCache(maxBytesCache);
assertEquals(ME+": Wrong capacity", 1000000, prop.getMaxBytes());
assertEquals(ME+": Wrong cache capacity", maxBytesCache, prop.getMaxBytesCache());
i_map.initialize(storageId, prop);
assertEquals(ME+": Wrong queue ID", storageId, i_map.getStorageId());
long numOfBytes = 0;
for(int i=0; i<queueEntries.length; i++) {
i_map.put(queueEntries[i]);
numOfBytes += queueEntries[i].getSizeInBytes();
}
assertEquals(ME+": Wrong size", queueEntries.length, i_map.getNumOfEntries());
assertEquals(ME+": Wrong bytes", numOfBytes, i_map.getNumOfBytes());
System.out.println("***" + ME + " [SUCCESS]");
i_map.clear();
i_map.shutdown();
}
catch(XmlBlasterException e) {
log.severe("Exception thrown: " + e.getMessage());
fail(ME + ": Exception thrown: " + e.getMessage());
}