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

📄 queueserverentrytest.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
         try {            retMsgUnit = updateEntry.getMsgUnit();         }         catch (Throwable e) {  // Should not happen for RAM queue            log.severe("Lookup failed, probably engine.Global has no Requestbroker, wi ignore the problem: " + e.getMessage());            e.printStackTrace();            return;         }         MsgQosData retMsgQosData = updateEntry.getMsgQosData();         log.fine("Received" + retMsgQosData.toXml());         // check message unit:         assertEquals("The key of the message unit is different ", key.getOid(), retMsgUnit.getKeyData().getOid());         assertEquals("The content of the message unit is different ", new String(retMsgUnit.getContent()), new String(content));         //assertEquals("The qos of the message unit is different ", retMsgUnit.getQosData().isPersistent(), publishQosServer.isPersistent());         //assertEquals("The qos of the message unit is different OLD="+oldXml+" NEW="+newXml, oldXml, newXml);         assertEquals("msgQosData check failure: getSubscriptionId      ", msgQosData.getSubscriptionId(), retMsgQosData.getSubscriptionId());//         assertEquals("msgQosData check failure: getPersistent             ", msgQosData.getPersistent(), retMsgQosData.getPersistent());//         assertEquals("msgQosData check failure: getForceUpdate         ", msgQosData.getForceUpdate(), retMsgQosData.getForceUpdate());//         assertEquals("msgQosData check failure: getReadOnly            ", msgQosData.getReadOnly(), retMsgQosData.getReadOnly());         assertEquals("msgQosData check failure: getSender              ", msgQosData.getSender().toString(), retMsgQosData.getSender().toString());         assertEquals("msgQosData check failure: getRedeliver           ", msgQosData.getRedeliver(), retMsgQosData.getRedeliver());         assertEquals("msgQosData check failure: getQueueSize           ", msgQosData.getQueueSize(), retMsgQosData.getQueueSize());         assertEquals("msgQosData check failure: getQueueIndex          ", msgQosData.getQueueIndex(), retMsgQosData.getQueueIndex());         assertEquals("msgQosData check failure: getPriority            ", msgQosData.getPriority().getInt(), retMsgQosData.getPriority().getInt());//         assertEquals("msgQosData check failure: getFromPersistentStore ", msgQosData.getFromPersistentStore(), retMsgQosData.getFromPersistentStore());         assertEquals("msgQosData check failure: getLifeTime            ", msgQosData.getLifeTime(), retMsgQosData.getLifeTime());         //assertEquals("msgQosData check failure: getRemainingLifeStatic ", msgQosData.getRemainingLifeStatic(), retMsgQosData.getRemainingLifeStatic());         assertEquals("msgQosData check failure: receiver", receiver, updateEntry.getReceiver());         queue.removeRandom(returnEntry); //just for cleaning up         log.info("successfully completed tests for the updateEntry");      }      catch (XmlBlasterException ex) {         ex.printStackTrace();         log.severe("exception occured : " + ex.getMessage());         throw ex;      }   }   // --------------------------------------------------------------------------   public void testHistoryEntry() {      String queueType = "unknown";      try {         historyEntry();      }      catch (XmlBlasterException ex) {         fail("Exception when testing HistoryEntry probably due to failed initialization of the queue of type " + queueType + " " + ex.getMessage());         ex.printStackTrace();      }   }   public void historyEntry() throws XmlBlasterException {      // set up the queues ....      QueuePropertyBase prop = new CbQueueProperty(glob, Constants.RELATING_CALLBACK, "/node/test");      log.info("********* Starting historyEntry Test");      StorageId queueId = new StorageId(Constants.RELATING_HISTORY, "historyEntry");      this.queue.initialize(queueId, prop);      this.queue.clear();      try {         byte[] content = "this is the content".getBytes();         PublishKey key = new PublishKey(glob, "someKey");         PublishQosServer publishQosServer = new PublishQosServer(glob, "<qos><persistent/></qos>");         MsgQosData msgQosData = publishQosServer.getData();         ((MsgQosSaxFactory)glob.getMsgQosFactory()).sendRemainingLife(false); // so we can compare the toXml() directly         // populate it         msgQosData.setState("state");         msgQosData.setSubscriptionId("someId");         msgQosData.setPersistent(true);         msgQosData.setForceUpdate(false);         msgQosData.setReadonly(true);         msgQosData.setSender(new SessionName(glob, "somebody"));         msgQosData.setRedeliver(4);         msgQosData.setQueueSize(1000L);         msgQosData.setQueueIndex(500L);         //msgQosData.addRouteInfo(null);         //msgQosData.dirtyRead(null);//NodeId         msgQosData.setPriority(PriorityEnum.LOW4_PRIORITY);         msgQosData.setFromPersistenceStore(true);         msgQosData.setLifeTime(4000L);         msgQosData.setRemainingLifeStatic(6000L);         MsgUnit msgUnit  = new MsgUnit(key.toXml(), content, msgQosData.toXml());         log.fine("Testing" + msgQosData.toXml());         org.xmlBlaster.engine.ServerScope global = new org.xmlBlaster.engine.ServerScope();         MsgUnitWrapper msgWrapper = new MsgUnitWrapper(glob, msgUnit, queue.getStorageId());         MsgQueueHistoryEntry entry = new MsgQueueHistoryEntry(global, msgWrapper, queue.getStorageId());         queue.put(entry, false);         I_QueueEntry returnEntry = queue.peek();         boolean isHistory = (returnEntry instanceof MsgQueueHistoryEntry);         assertTrue("historyEntry: the return value is not an update ", isHistory);                  MsgQueueHistoryEntry historyEntry = (MsgQueueHistoryEntry)returnEntry;         assertEquals("The priority of the entry is different ", entry.getPriority(), historyEntry.getPriority());         assertEquals("The persistent of the entry is different ", entry.isPersistent(), historyEntry.isPersistent());         // The history queue is s LIFO, we have inverted the unique key         assertEquals("The uniqueId of the entry is different ", entry.getUniqueId(), historyEntry.getUniqueId());         assertEquals("The msgUnitWrapperUniqueId of the entry is different ", entry.getMsgUnitWrapperUniqueId(), historyEntry.getMsgUnitWrapperUniqueId());         assertEquals("The topic oid of the entry is different ", entry.getKeyOid(), historyEntry.getKeyOid());         assertEquals("The topic oid of the entry is different ", entry.getStorageId().getId(), historyEntry.getStorageId().getId());         log.info("Persistent fields are read as expected");         MsgUnit retMsgUnit = null;         try {            retMsgUnit = historyEntry.getMsgUnit();         }         catch (Throwable e) {  // Should not happen for RAM queue            log.severe("Lookup failed, probably engine.Global has no Requestbroker, wi ignore the problem: " + e.getMessage());            e.printStackTrace();            return;         }         MsgQosData retMsgQosData = historyEntry.getMsgQosData();         log.fine("Received" + retMsgQosData.toXml());         // check message unit:         assertEquals("The key of the message unit is different ", key.getOid(), retMsgUnit.getKeyData().getOid());         assertEquals("The content of the message unit is different ", new String(retMsgUnit.getContent()), new String(content));         //oldXml = oldXml.substring(oldXml.indexOf("remainingLife=");         //String newXml = retMsgUnit.getQosData().toXml().trim();  TODO: strip remaining life first         //assertEquals("The qos of the message unit is different OLD="+oldXml+" NEW="+newXml, oldXml, newXml); TODO         assertEquals("msgQosData check failure: getSubscriptionId      ", msgQosData.getSubscriptionId(), retMsgQosData.getSubscriptionId());         assertEquals("msgQosData check failure: getSender              ", msgQosData.getSender().toString(), retMsgQosData.getSender().toString());         assertEquals("msgQosData check failure: getRedeliver           ", msgQosData.getRedeliver(), retMsgQosData.getRedeliver());         assertEquals("msgQosData check failure: getQueueSize           ", msgQosData.getQueueSize(), retMsgQosData.getQueueSize());         assertEquals("msgQosData check failure: getQueueIndex          ", msgQosData.getQueueIndex(), retMsgQosData.getQueueIndex());         assertEquals("msgQosData check failure: getPriority            ", msgQosData.getPriority().getInt(), retMsgQosData.getPriority().getInt());         assertEquals("msgQosData check failure: getLifeTime            ", msgQosData.getLifeTime(), retMsgQosData.getLifeTime());         queue.removeRandom(returnEntry); //just for cleaning up         log.info("successfully completed tests for the historyEntry");      }      catch (XmlBlasterException ex) {         ex.printStackTrace();         log.severe("exception occured : " + ex.getMessage());         throw ex;      }   }   /**    * Method is used by TestRunner to load these tests    */   public static Test suite() {      TestSuite suite= new TestSuite();      ServerScope glob = new ServerScope();      for (int i=0; i < PLUGIN_TYPES.length; i++) {         suite.addTest(new QueueServerEntryTest(glob, "testUpdateEntry", i));         suite.addTest(new QueueServerEntryTest(glob, "testHistoryEntry", i));      }      return suite;   }    /**    * <pre>    *  java org.xmlBlaster.test.classtest.queue.QueueServerEntryTest    * </pre>    */   public static void main(String args[]) {      ServerScope glob = new ServerScope(args);      for (int i=0; i < PLUGIN_TYPES.length; i++) {         QueueServerEntryTest testSub = new QueueServerEntryTest(glob, "QueueServerEntryTest", i);         long startTime = System.currentTimeMillis();         testSub.setUp();         testSub.testUpdateEntry();         testSub.tearDown();         testSub.setUp();         testSub.testHistoryEntry();         testSub.tearDown();         long usedTime = System.currentTimeMillis() - startTime;         testSub.log.info("time used for tests: " + usedTime/1000 + " seconds");      }   }}

⌨️ 快捷键说明

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