StorageId storageId = new StorageId(this.glob, "cb:queue1");
String queueName = storageId.getStrippedId();
long size = 100; // entry.getSizeInBytes();
DummyEntry entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, storageId, size, true);
try {
this.manager.addEntry(queueName, entry);
assertTrue(me + " adding an entry with no queue nor node associated should fail", false);
}
catch (XmlBlasterException ex) {
log.info("the previous exception is expected and is OK in this context");
}
try {
this.manager.addEntry(queueName, entry);
assertTrue(me + " adding an entry with no queue associated should fail", false);
}
catch (XmlBlasterException ex) {
log.info("the previous exception is expected and is OK in this context");
}
boolean ret = this.manager.addEntry(queueName, entry);
assertEquals(me + " adding an entry should give back true", true, ret);
long totalSize = size;
ret = this.manager.addEntry(queueName, entry);
assertEquals(me + " adding an entry the second time should give back 'false'", false, ret);
// add some more entries
entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, storageId, size, true);
this.manager.addEntry(queueName, entry);
totalSize += size;
entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, storageId, size, false);
this.manager.addEntry(queueName, entry);
totalSize += size;
// check here a modification of an entry:
long oldNumOfEntries = this.manager.getNumOfEntries(queueName);
long oldNumOfBytes = this.manager.getNumOfBytes(queueName);
entry.setPersistent(true);
this.manager.modifyEntry(queueName, entry, entry);
long[] dataIds = new long[1];
dataIds[0] = entry.getUniqueId();
ArrayList tmp = this.manager.getEntries(storageId, dataIds);
assertEquals(me + " modified entry is not correct ", true, ((DummyEntry)(tmp.get(0))).isPersistent());
entry.setPersistent(false);
this.manager.modifyEntry(queueName, entry, entry);
dataIds = new long[1];
dataIds[0] = entry.getUniqueId();
tmp = this.manager.getEntries(storageId, dataIds);
assertEquals(me + " modified entry is not correct ", false, ((DummyEntry)(tmp.get(0))).isPersistent());
// did the modification change the number or the size of the entries ?
assertEquals(me + " modification did change the number of entries", oldNumOfEntries, this.manager.getNumOfEntries(queueName));
assertEquals(me + " modification did change the number of bytes", oldNumOfBytes, this.manager.getNumOfBytes(queueName));
long numOfBytes = this.manager.getNumOfBytes(queueName);
assertEquals(me + " num of bytes in queue 'queue1'", totalSize, numOfBytes);
// count the number of entries here: they should be 4
this.manager.deleteAllTransient(queueName);
numOfBytes = this.manager.getNumOfBytes(queueName);
totalSize -= size;
assertEquals(me + " num of bytes in queue 'queue1' after deleting transients", totalSize, numOfBytes);
ReturnDataHolder retHolder = this.manager.getAndDeleteLowest(storageId, 2, -1, 10, -1, false, true);
assertEquals(me + " getAndDeleteLowest check", 2, retHolder.countEntries);
long entriesToDelete[] = new long[2];
entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, storageId, size, true);
entriesToDelete[0] = entry.getUniqueId();
this.manager.addEntry(queueName, entry);
entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, storageId, size, true);
this.manager.addEntry(queueName, entry);
entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, storageId, size, true);
entriesToDelete[1] = entry.getUniqueId();
this.manager.addEntry(queueName, entry);
entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, storageId, size, true);
this.manager.addEntry(queueName, entry);
boolean[] tmpArr = this.manager.deleteEntries(queueName, entriesToDelete);
int numOfDel = 0;
for (int i=0; i < tmpArr.length; i++) {
if ( tmpArr[i] ) numOfDel++;
}
assertEquals(me + " deleteEntries check", 2, numOfDel);
retHolder = this.manager.deleteFirstEntries(queueName, 1L, 10000L);
assertEquals(me + " deleteFirstEntries check", 1, retHolder.countEntries);
ArrayList arrayList = this.manager.getEntriesByPriority(storageId, -1, -1, 0, 9, null);
assertEquals(me + " getEntriesByPriority check", 1, arrayList.size());
long[] entriesToGet = new long[2];
entry = new DummyEntry(glob, PriorityEnum.MAX_PRIORITY, storageId, size, true);
entriesToGet[0] = entry.getUniqueId();
this.manager.addEntry(queueName, entry);
arrayList = this.manager.getEntriesBySamePriority(storageId, -1, -1);
assertEquals(me + " getEntriesBySamePriority check", 1, arrayList.size());
arrayList = this.manager.getEntries(storageId, -1, -1, null);
assertEquals(me + " getEntries check", 2, arrayList.size());
entry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, storageId, size, true);
entriesToGet[1] = entry.getUniqueId();
this.manager.addEntry(queueName, entry);
arrayList = this.manager.getEntriesWithLimit(storageId, entry);
assertEquals(me + " getEntriesWithLimit check", 2, arrayList.size());