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

📄 i_queuetest.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
         assertEquals(me+": Wrong sequence in takeLowest", origEntries[i].getUniqueId(), ref);      }      return entriesLeft - currentEntries;   }   /**    * Test takeLowest(I_Queue)    */   private void takeLowest(I_Queue queue) {      if (queue instanceof CacheQueueInterceptorPlugin) return;      ME = "I_QueueTest.takeLowest(" + queue.getStorageId() + ")[" + queue.getClass().getName() + "]";      System.out.println("***" + ME);      try {         //========== Test 1: takeLowest without restrictions         {            log.fine("takeLowest test 1");            int imax = 50;            long size = 0L;            long msgSize = 100L; // every msg is 100 bytes long            int entriesLeft = imax;            this.queue.removeStorageSizeListener(null);            this.queue.addStorageSizeListener(this.queueSizeListener);            this.queueSizeListener.clear();            DummyEntry[] entries = new DummyEntry[imax];            for (int i=0; i < imax; i++) {               entries[i] = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), msgSize, true);               size += entries[i].getSizeInBytes();               queue.put(entries[i], false);            }            assertEquals(ME+": Wrong number put", imax, queue.getNumOfEntries());            assertEquals(ME+": Wrong expected size in bytes of entries", msgSize*imax, size);            assertEquals(ME+": Wrong size in bytes put", size, queue.getNumOfBytes());            entriesLeft = assertCheckForTakeLowest(queue,  0, -1L, null, true, entries, entriesLeft, 0, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  1, -1L, null, true, entries, entriesLeft, 1, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  2, -1L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue, -1, 0L, null, true, entries, entriesLeft, 0, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  0, 0L, null, true, entries, entriesLeft, 0, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  1, 0L, null, true, entries, entriesLeft, 1, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  2, 0L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue, -1, 50L, null, true, entries, entriesLeft, 1, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  0, 50L, null, true, entries, entriesLeft, 1, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  1, 50L, null, true, entries, entriesLeft, 1, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  2, 50L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue, -1, 100L, null, true, entries, entriesLeft, 1, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  0, 100L, null, true, entries, entriesLeft, 1, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  1, 100L, null, true, entries, entriesLeft, 1, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  2, 100L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue, -1, 150L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  0, 150L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  1, 150L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  2, 150L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue, -1, 200L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  0, 200L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  1, 200L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue,  2, 200L, null, true, entries, entriesLeft, 2, msgSize);            entriesLeft = assertCheckForTakeLowest(queue, -1, -1L, null, true, entries, entriesLeft, entriesLeft-1, msgSize);            entriesLeft = assertCheckForTakeLowest(queue, -1, -1L, null, false, entries, entriesLeft, 1, msgSize);            assertEquals(ME+": Wrong size in takeLowest after cleaning ", queue.getNumOfEntries(), 0);            queue.clear();         }         //========== Test 2: takeLowest which should return an empty array         {            log.fine("takeLowest test 2");            int imax = 20;            long size = 0L;            DummyEntry[] entries = new DummyEntry[imax];            for (int i=0; i < imax; i++) {               entries[i] = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true);               size += entries[i].getSizeInBytes();               queue.put(entries[i], false);            }            DummyEntry queueEntry = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true);            assertEquals(ME+": Wrong number put", imax, queue.getNumOfEntries());            assertEquals(ME+": Wrong size in bytes put", size, queue.getNumOfBytes());            // should return an empty array since the timestamp is  the last            ArrayList list = queue.takeLowest(-1, -1, queueEntry, true);            assertEquals(ME+": Wrong size in takeLowest return ", 0, list.size());            queue.clear();            assertEquals(ME+": Wrong size in takeLowest after cleaning ", 0, queue.getNumOfEntries());         }         //========== Test 3: takeLowest should return 13 entries         {            log.fine("takeLowest test 3");            int imax = 20;            long size = 0L;            DummyEntry[] entries = new DummyEntry[imax];            for (int i=0; i < imax; i++) {               entries[i] = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true);               size += entries[i].getSizeInBytes();               queue.put(entries[i], false);            }            DummyEntry queueEntry = entries[6];            assertEquals(ME+": Wrong number put", imax, queue.getNumOfEntries());            assertEquals(ME+": Wrong size in bytes put", size, queue.getNumOfBytes());            // should return an empty array since the timestamp is  the last            ArrayList list = queue.takeLowest(-1, -1, queueEntry, true);            assertEquals(ME+": Wrong size in takeLowest return ", list.size(), imax-6-1);            queue.clear();            assertEquals(ME+": Wrong size in takeLowest after cleaning ", queue.getNumOfEntries(), 0);         }         //========== Test 4: takeLowest without restrictions         {            log.fine("takeLowest test 4 (with entry null)");            int imax = 20;            long size = 0L;            DummyEntry[] entries = new DummyEntry[imax];            for (int i=0; i < imax; i++) {               entries[i] = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true);               size += entries[i].getSizeInBytes();               queue.put(entries[i], false);            }            assertEquals(ME+": Wrong number put", imax, queue.getNumOfEntries());            assertEquals(ME+": Wrong size in bytes put", size, queue.getNumOfBytes());            ArrayList list = queue.takeLowest(-1, -1, null, true);            assertEquals(ME+": Wrong size in takeLowest return ", list.size(), entries.length-1);            for (int i=1; i < imax; i++) {               int j = imax - 1 - i;               long ref = ((I_QueueEntry)list.get(j)).getUniqueId();               assertEquals(ME+": Wrong unique ID", entries[i].getUniqueId(), ref);            }            queue.clear();            assertEquals(ME+": Wrong size in takeLowest after cleaning ", queue.getNumOfEntries(), 0);         }      }      catch(XmlBlasterException e) {         fail(ME + ": Exception thrown: " + e.getMessage());      }   }   public void testWrongOrder() {      String queueType = "unknown";      try {         QueuePropertyBase prop = new CbQueueProperty(glob, Constants.RELATING_CALLBACK, "/node/test");         queueType = this.queue.toString();         StorageId queueId = new StorageId(Constants.RELATING_CALLBACK, "QueuePlugin/takeLowest");         this.queue.initialize(queueId, prop);         queue.clear();         assertEquals(ME + "wrong size before starting ", 0, queue.getNumOfEntries());         wrongOrder(this.queue);      }      catch (XmlBlasterException ex) {         log.severe("Exception when testing removeRandomLong probably due to failed initialization of the queue " + queueType);      }   }   /**    * Test wrongOrder(I_Queue)    */   private void wrongOrder(I_Queue queue) {      ME = "I_QueueTest.wrongOrder(" + queue.getStorageId() + ")[" + queue.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("wrongOrder test 1");            int imax = 5;            long size = 0L;            DummyEntry[] entries = new DummyEntry[imax];            for (int i=0; i < imax; i++) {               entries[i] = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true);               size += entries[i].getSizeInBytes();            }            DummyEntry[] putEntries = new DummyEntry[imax];            putEntries[0] = entries[3];            putEntries[1] = entries[4];            putEntries[2] = entries[2];            putEntries[3] = entries[0];            putEntries[4] = entries[1];            queue.put(putEntries, false);            assertEquals(ME+": Wrong number put", imax, queue.getNumOfEntries());            assertEquals(ME+": Wrong size in bytes put", size, queue.getNumOfBytes());            ArrayList listPeekSamePrio = queue.peekSamePriority(-1, -1L);            ArrayList listPeekWithPrio = queue.peekWithPriority(-1, -1L, 0, 10);            ArrayList listPeek = queue.peek(-1, -1L);            //they all should give the same result ...            for (int i=0; i<imax; i++) {               long id = entries[i].getUniqueId();               long idPeekSamePrio = ((I_QueueEntry)listPeekSamePrio.get(i)).getUniqueId();               long idPeekWithPrio = ((I_QueueEntry)listPeekWithPrio.get(i)).getUniqueId();               long idPeek = ((I_QueueEntry)listPeek.get(i)).getUniqueId();               assertEquals(ME+": Wrong entry for peekSamePrio ", id, idPeekSamePrio);               assertEquals(ME+": Wrong entry for peekWithPrio ", id, idPeekWithPrio);               assertEquals(ME+": Wrong entry for peek ", id, idPeek);            }            queue.clear();            assertEquals(ME+": Wrong size in takeLowest after cleaning ", queue.getNumOfEntries(), 0);         }      }      catch(XmlBlasterException e) {         fail(ME + ": Exception thrown: " + e.getMessage());      }   }   public void testPutEntriesTwice() {      String queueType = "unknown";      try {         QueuePropertyBase prop = new CbQueueProperty(glob, Constants.RELATING_CALLBACK, "/node/test");         queueType = this.queue.toString();         StorageId queueId = new StorageId(Constants.RELATING_CALLBACK, "QueuePlugin/putEntriesTwice");         this.queue.initialize(queueId, prop);         queue.clear();         assertEquals(ME + " wrong size before starting ", 0, queue.getNumOfEntries());         putEntriesTwice(this.queue);      }      catch (XmlBlasterException ex) {         log.severe("Exception when testing putEntriesTwice probably due to failed initialization of the queue " + queueType);      }   }   /**    * Test wrongOrder(I_Queue)    */   private void putEntriesTwice(I_Queue queue) {      ME = "I_QueueTest.putEntriesTwice(" + queue.getStorageId() + ")[" + queue.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;            DummyEntry[] entries = new DummyEntry[imax];            for (int i=0; i < imax; i++) {               entries[i] = new DummyEntry(glob, PriorityEnum.NORM_PRIORITY, queue.getStorageId(), true);               size += entries[i].getSizeInBytes();            }            queue.put(entries, false);            queue.put(entries, false);           

⌨️ 快捷键说明

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