📄 i_maptest.java
字号:
//------------------------------------ public void testGetAllSwappedMsgs() { String queueType = "unknown"; try { QueuePropertyBase prop = new MsgUnitStoreProperty(glob, "/node/test"); queueType = this.currMap.toString(); StorageId queueId = new StorageId("msgUnitStore", "MapPlugin/getAllSwappedMsgs"); prop.setMaxEntries(10); // Overall size (RAM or JDBC or CACHE) prop.setMaxEntriesCache(2); // Is only interpreted for cache implementations (-> the size of the RAM map) this.currMap.initialize(queueId, prop); this.currMap.clear(); assertEquals(ME + "wrong size before starting ", 0, this.currMap.getNumOfEntries()); getAllSwappedMsgs(this.currMap); } catch (XmlBlasterException ex) { log.severe("Exception when testing getAllSwappedMsgs probably due to failed initialization of the queue " + queueType + ": " + ex.getMessage()); } } /** * Tests getAll() and the entries are swapped as the RAM size is only 2 * NOTE: see NOTE of getAllMsgs(I_Map) */ private void getAllSwappedMsgs(I_Map i_map) { ME = "I_MapTest.getAllSwappedMsgs(" + i_map.getStorageId() + ")[" + i_map.getClass().getName() + "]"; System.out.println("***" + ME); QueuePropertyBase prop = (QueuePropertyBase)i_map.getProperties(); assertEquals(ME+": Wrong capacity", 10, prop.getMaxEntries()); assertEquals(ME+": Wrong cache capacity", 2, prop.getMaxEntriesCache()); log.info("Current settings: " + prop.toXml()); try { //========== Test 1: getAllSwapped() { MsgUnitWrapper[] queueEntries = { new MsgUnitWrapper(glob, createMsgUnit(IS_TRANSIENT), i_map.getStorageId()), new MsgUnitWrapper(glob, createMsgUnit(IS_TRANSIENT), i_map.getStorageId()), new MsgUnitWrapper(glob, createMsgUnit(IS_TRANSIENT), i_map.getStorageId()), new MsgUnitWrapper(glob, createMsgUnit(IS_TRANSIENT), i_map.getStorageId()) }; for(int i=0; i<queueEntries.length; i++) { i_map.put(queueEntries[i]); log.info("#" + i + " id=" + queueEntries[i].getUniqueId() + " numSizeBytes()=" + queueEntries[i].getSizeInBytes()); } //log.info("storage bytes sum=" + i_map.getNumOfBytes() + " with persistent bytes=" + i_map.getNumOfPersistentBytes()); log.info("storage state=" + i_map.toXml("")); assertEquals("", queueEntries.length, i_map.getNumOfEntries()); for (int ii=0; ii<10; ii++) { I_MapEntry[] results = i_map.getAll(null); for(int jj=0; jj<results.length; jj++) { log.info("#" + jj + ": " + results[jj].getUniqueId()); } assertEquals("Missing entry", queueEntries.length, results.length); assertEquals(ME+": Wrong result", queueEntries[0].getUniqueId(), results[0].getUniqueId()); assertEquals(ME+": Wrong result", queueEntries[1].getUniqueId(), results[1].getUniqueId()); assertEquals(ME+": Wrong result", queueEntries[2].getUniqueId(), results[2].getUniqueId()); assertEquals(ME+": Wrong result", queueEntries[3].getUniqueId(), results[3].getUniqueId()); } assertEquals("", 4, i_map.getNumOfEntries()); assertEquals("", 0, i_map.getNumOfPersistentEntries()); log.info("#1 Success, getAllSwapped()"); } System.out.println("***" + ME + " [SUCCESS]"); } catch(XmlBlasterException e) { e.printStackTrace(); fail(ME + ": Exception thrown: " + e.getMessage()); } finally { try { i_map.clear(); i_map.shutdown(); } catch(XmlBlasterException e) { e.printStackTrace(); fail(ME + ": Exception thrown in cleanup: " + e.getMessage()); } } } public void testPutEntriesTwice() { String queueType = "unknown"; try { QueuePropertyBase prop = new MsgUnitStoreProperty(glob, "/node/test"); queueType = this.currMap.toString(); StorageId queueId = new StorageId("msgUnitStore", "MapPlugin/putEntriesTwice"); this.currMap.initialize(queueId, prop); this.currMap.clear(); assertEquals(ME + " wrong size before starting ", 0, this.currMap.getNumOfEntries()); putEntriesTwice(this.currMap); } catch (XmlBlasterException ex) { log.severe("Exception when testing putEntriesTwice probably due to failed initialization of the queue " + queueType + ": " + ex.getMessage()); } } private void putEntriesTwice(I_Map i_map) { ME = "I_MapTest.putEntriesTwice(" + i_map.getStorageId() + ")[" + i_map.getClass().getName() + "]"; System.out.println("***" + ME); try { //========== Test 1: checks if entries are returned in the correct // order even if they are inserted in the wrong order { log.fine("putEntriesTwice test 1"); int imax = 5; long size = 0L; MsgUnitWrapper[] entries = new MsgUnitWrapper[imax]; for (int i=0; i < entries.length; i++) { entries[i] = new MsgUnitWrapper(glob, createMsgUnit(false), i_map.getStorageId()); size += entries[i].getSizeInBytes(); } for(int i=0; i<entries.length; i++) { int numPut = i_map.put(entries[i]); assertEquals("Putting first entry should be OK", 1, numPut); numPut = i_map.put(entries[i]); assertEquals("Putting entries twices should fail", 0, numPut); } assertEquals(ME+": Wrong number of entries after putting same entries twice", entries.length, i_map.getNumOfEntries()); assertEquals(ME+": Wrong size after putting same entries twice", size, i_map.getNumOfBytes()); i_map.clear(); assertEquals(ME+": Wrong num entries after cleaning", i_map.getNumOfEntries(), 0); } System.out.println("***" + ME + " [SUCCESS]"); } catch(XmlBlasterException e) { fail(ME + ": Exception thrown: " + e.getMessage()); } } public void tearDown() { try { this.currMap.destroy(); } catch (Exception ex) { ex.printStackTrace(); log.severe("error when tearing down " + ex.getMessage()); } } /** * @see checkSizeAndEntries(String, I_MapEntry[], I_Map) */ private void checkSizeAndEntries(String txt, ArrayList queueEntries, I_Map map) { checkSizeAndEntries(txt, (I_MapEntry[])queueEntries.toArray(new I_MapEntry[queueEntries.size()]), map); } /** * Helper method to do a generic size check (size and number of entries) */ private void checkSizeAndEntries(String txt, I_MapEntry[] queueEntries, I_Map i_map) { long sizeOfTransients = 0L; long numOfPersistents = 0; long numOfTransients = 0; long sizeOfPersistents = 0L; for (int i=0; i < queueEntries.length; i++) { I_MapEntry entry = queueEntries[i]; if (entry.isPersistent()) { sizeOfPersistents += entry.getSizeInBytes(); numOfPersistents++; } else { sizeOfTransients += entry.getSizeInBytes(); numOfTransients++; } } long queueNumOfPersistents = i_map.getNumOfPersistentEntries(); long queueNumOfTransients = i_map.getNumOfEntries() - queueNumOfPersistents; long queueSizeOfPersistents = i_map.getNumOfPersistentBytes(); long queueSizeOfTransients = i_map.getNumOfBytes() - queueSizeOfPersistents; txt += " getNumOfPersistentEntries=" + queueNumOfPersistents + " NumOfTransients=" + queueNumOfTransients; txt += " getNumOfPersistentBytes=" + queueSizeOfPersistents + " SizeOfTransients=" + queueSizeOfTransients; assertEquals(ME + ": " + txt + " wrong number of persistents ", numOfPersistents, queueNumOfPersistents); assertEquals(ME + ": " + txt + " wrong number of transients ", numOfTransients, queueNumOfTransients); assertEquals(ME + ": " + txt + " wrong size of persistents ", sizeOfPersistents, queueSizeOfPersistents); assertEquals(ME + ": " + txt + " wrong size of transients ", sizeOfTransients, queueSizeOfTransients); } /** * Method is used by TestRunner to load these tests */ public static Test suite() { TestSuite suite= new TestSuite(); ServerScope glob = new ServerScope(); suite.addTest(new I_MapTest("testByteOverflow", 2)); // For CACHE only for (int i=0; i<PLUGIN_TYPES.length; i++) { suite.addTest(new I_MapTest("testConfig", i)); suite.addTest(new I_MapTest("testPutMsg", i)); suite.addTest(new I_MapTest("testGetMsg", i)); suite.addTest(new I_MapTest("testGetAllMsgs", i)); suite.addTest(new I_MapTest("testGetAllSwappedMsgs", i)); suite.addTest(new I_MapTest("testPutEntriesTwice", i)); } return suite; } /** * <pre> * java -Dtrace=true org.xmlBlaster.test.classtest.msgstore.I_MapTest > test.log * </pre> */ public static void main(String args[]) { ServerScope glob = new ServerScope(args); I_MapTest testSub = new I_MapTest("I_MapTest", 1); // JDBC check //I_MapTest testSub = new I_MapTest("I_MapTest", 2); // CACHE check long startTime = System.currentTimeMillis(); testSub.setUp(); testSub.testGetAllMsgs(); testSub.tearDown(); long usedTime = System.currentTimeMillis() - startTime; testSub.log.info("time used for tests: " + usedTime/1000 + " seconds"); /* for (int i=0; i < PLUGIN_TYPES.length; i++) { testSub = new I_MapTest("I_MapTest", i); startTime = System.currentTimeMillis(); testSub.setUp(); testSub.testConfig(); testSub.tearDown(); testSub.setUp(); testSub.testPutMsg(); testSub.tearDown(); testSub.setUp(); testSub.testGetMsg(); testSub.tearDown(); testSub.setUp(); testSub.testGetAllMsgs(); testSub.tearDown(); testSub.setUp(); testSub.testGetAllSwappedMsgs(); testSub.tearDown(); testSub.setUp(); testSub.testPutEntriesTwice(); testSub.tearDown(); usedTime = System.currentTimeMillis() - startTime; testSub.log.info("time used for tests: " + usedTime/1000 + " seconds"); } */ }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -