⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i_maptest.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            i_map.put(queueEntry);         }         assertEquals(ME+": Wrong total size", numLoop+total, i_map.getNumOfEntries());         this.checkSizeAndEntries(" put(I_MapEntry) ", list, i_map);         log.info("#2 Success, filled " + i_map.getNumOfEntries() + " messages into queue");         i_map.clear();         checkSizeAndEntries("Test 2 put()", new I_MapEntry[0], i_map);         assertEquals(ME+": Wrong empty size", 0L, i_map.getNumOfEntries());         System.out.println("***" + ME + " [SUCCESS]");         i_map.shutdown();      }      catch(XmlBlasterException e) {         fail(ME + ": Exception thrown: " + e.getMessage());      }   }   /**    * 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("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());      }   }//------------------------------------   public void testGetMsg() {      String queueType = "unknown";      try {         QueuePropertyBase prop = new MsgUnitStoreProperty(glob, "/node/test");         queueType = this.currMap.toString();         StorageId queueId = new StorageId("msgUnitStore", "MapPlugin/getMsg");         this.currMap.initialize(queueId, prop);         this.currMap.clear();         assertEquals(ME + "wrong size before starting ", 0, this.currMap.getNumOfEntries());         getMsg(this.currMap);      }      catch (XmlBlasterException ex) {         log.severe("Exception when testing getMsg probably due to failed initialization of the queue " + queueType + ": " + ex.getMessage());      }   }   /**    * Tests get() and get(int num) and remove()    * For a discussion of the sorting order see Javadoc of this class    */   private void getMsg(I_Map i_map) {      ME = "I_MapTest.getMsg(" + i_map.getStorageId() + ")[" + i_map.getClass().getName() + "]";      System.out.println("***" + ME);      try {         //========== Test 1: get()         {            MsgUnitWrapper[] queueEntries = {                         new MsgUnitWrapper(glob, createMsgUnit(false), i_map.getStorageId()),                         new MsgUnitWrapper(glob, createMsgUnit(true), i_map.getStorageId()),                         new MsgUnitWrapper(glob, createMsgUnit(true), 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());            assertEquals("", 3, i_map.getNumOfEntries());            assertEquals("", 2, i_map.getNumOfPersistentEntries());            for (int ii=0; ii<10; ii++) {               I_MapEntry result = i_map.get(queueEntries[0].getUniqueId());               assertTrue("Missing entry", result != null);               assertEquals(ME+": Wrong result", queueEntries[0].getUniqueId(), result.getUniqueId());               result = i_map.get(queueEntries[1].getUniqueId());               assertTrue("Missing entry", result != null);               assertEquals(ME+": Wrong result", queueEntries[1].getUniqueId(), result.getUniqueId());               result = i_map.get(queueEntries[2].getUniqueId());               assertTrue("Missing entry", result != null);               assertEquals(ME+": Wrong result", queueEntries[2].getUniqueId(), result.getUniqueId());            }            assertEquals("", 3, i_map.getNumOfEntries());            assertEquals("", 2, i_map.getNumOfPersistentEntries());            log.info("storage before remove [0], bytes sum=" + i_map.getNumOfBytes() + " with persistent bytes=" + i_map.getNumOfPersistentBytes());            i_map.remove(queueEntries[0]); // Remove one            log.info("storage after remove [0], bytes sum=" + i_map.getNumOfBytes() + " with persistent bytes=" + i_map.getNumOfPersistentBytes());            ArrayList list = new ArrayList();            list.add(queueEntries[1]);            list.add(queueEntries[2]);            this.checkSizeAndEntries(" getMsg() ", list, i_map);            for (int ii=0; ii<10; ii++) {               I_MapEntry result = i_map.get(queueEntries[1].getUniqueId());               assertTrue("Missing entry", result != null);               assertEquals(ME+": Wrong result", queueEntries[1].getUniqueId(), result.getUniqueId());            }            i_map.remove(queueEntries[1].getUniqueId()); // Remove one            assertEquals("", 1, i_map.getNumOfEntries());            assertEquals("", 1, i_map.getNumOfPersistentEntries());            for (int ii=0; ii<10; ii++) {               I_MapEntry result = i_map.get(queueEntries[2].getUniqueId());               assertTrue("Missing entry", result != null);               assertEquals(ME+": Wrong result", queueEntries[2].getUniqueId(), result.getUniqueId());            }            i_map.remove(queueEntries[2]); // Remove one            for (int ii=0; ii<10; ii++) {               I_MapEntry result = i_map.get(queueEntries[0].getUniqueId());               assertTrue("Unexpected entry", result == null);            }            assertEquals("", 0, i_map.getNumOfEntries());            assertEquals("", 0, i_map.getNumOfPersistentEntries());            log.info("#1 Success, get()");         }         System.out.println("***" + ME + " [SUCCESS]");         i_map.clear();         i_map.shutdown();      }      catch(XmlBlasterException e) {         e.printStackTrace();         fail(ME + ": Exception thrown: " + e.getMessage());      }   }//------------------------------------   public void testGetAllMsgs() {      String queueType = "unknown";      try {         QueuePropertyBase prop = new MsgUnitStoreProperty(glob, "/node/test");         queueType = this.currMap.toString();         StorageId queueId = new StorageId("msgUnitStore", "MapPlugin/getAllMsgs");         this.currMap.initialize(queueId, prop);         this.currMap.clear();         assertEquals(ME + "wrong size before starting ", 0, this.currMap.getNumOfEntries());         getAllMsgs(this.currMap);      }      catch (XmlBlasterException ex) {         log.severe("Exception when testing getAllMsgs probably due to failed initialization of the queue " + queueType + ": " + ex.getMessage());      }   }   /**    * Tests get() and get(int num) and remove()    * NOTE: Currently the MapPlugin returns getAll() sorted (it uses a TreeMap)    *       But we haven't yet forced this in the I_Map#getAll() Javadoc!    *       This test assumes sorting order and needs to be changed if we once    *       decide to specify the exact behaviour in I_Map#getAll() javadoc    */   private void getAllMsgs(I_Map i_map) {      ME = "I_MapTest.getAllMsgs(" + i_map.getStorageId() + ")[" + i_map.getClass().getName() + "]";      System.out.println("***" + ME);      try {         //========== Test 1: getAll()         {            MsgUnitWrapper[] queueEntries = {                         new MsgUnitWrapper(glob, createMsgUnit(IS_TRANSIENT), i_map.getStorageId()),                         new MsgUnitWrapper(glob, createMsgUnit(IS_DURABLE), i_map.getStorageId()),                         new MsgUnitWrapper(glob, createMsgUnit(IS_DURABLE), 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());            assertEquals("", 3, i_map.getNumOfEntries());            assertEquals("", 2, i_map.getNumOfPersistentEntries());            for (int ii=0; ii<10; ii++) {               I_MapEntry[] results = i_map.getAll(null);               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("", 3, i_map.getNumOfEntries());            assertEquals("", 2, i_map.getNumOfPersistentEntries());            /*            I_MapEntry[] results = i_map.getAll(new I_EntryFilter() {               public I_Entry intercept(I_Entry entry, I_Storage storage) {                  assertTrue("NULL storage", storage!=null);                  if (!storage.isTransient()) return entry;                  entryCounter++;                  if (entryCounter == 2)                     return null;                  return entry;               }            });            assertEquals("Missing entry", queueEntries.length-1, results.length);            assertEquals(ME+": Wrong result", queueEntries[0].getUniqueId(), results[0].getUniqueId());            assertEquals(ME+": Wrong result", queueEntries[2].getUniqueId(), results[1].getUniqueId());            */            i_map.clear();            log.info("#1 Success, getAll()");         }         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());         }      }   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -