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

📄 testtopiclifecycle.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
         log.fine(dump);         // Expecting something like:         // <TopicHandler id='http_192_168_1_4_3412/topic/TestTopicLifeCycleMsg' state='UNCONFIGURED'>         //  <uniqueKey>TestTopicLifeCycleMsg</uniqueKey>         assertTrue("Missing topic", dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") != -1);         assertTrue("Topic in wrong state:" + dump, dump.indexOf("TestTopicLifeCycleMsg' state='UNCONFIGURED'") != -1);      }      {  // topic transition from START -> [1] -> UNCONFIGURED         subscribeMsg();         String dump = getDump();         log.fine(dump);         // Expecting something like:         // <TopicHandler id='http_192_168_1_4_3412/topic/TestTopicLifeCycleMsg' state='UNCONFIGURED'>         //  <uniqueKey>TestTopicLifeCycleMsg</uniqueKey>         assertTrue("Missing topic", dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") != -1);         assertTrue("Topic in wrong state:" + dump, dump.indexOf("TestTopicLifeCycleMsg' state='UNCONFIGURED'") != -1);      }      {  // topic transition from UNCONFIGURED -> [9] -> DEAD         boolean forceDestroy = false;         this.updateInterceptor.countErased(true);         EraseReturnQos[] erq = sendErase(forceDestroy);         log.info("erase num=" + erq.length);         assertEquals("erase failed", 1, erq.length);         assertEquals("", 2, this.updateInterceptor.waitOnUpdate(1000L, publishOid, Constants.STATE_ERASED, 2)); // Expecting two erase events (for the above subscriptions)         try { Thread.sleep(1000L); } catch( InterruptedException i) {} // Give server a change to destroy topic after delivery of erase event messages         this.updateInterceptor.countErased(false);         String dump = getDump();         assertTrue("Not expected a dead topic:" + dump, dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") == -1);      }      log.info("SUCCESS testUnconfiguredSubscribeSubscribe");   }   /**    * THIS IS THE TEST    * Transitions [1] -> [4] -> [7] -> [12]    */   public void testSoftErased() {      log.info("Entering testSoftErased ...");      this.updateInterceptor.clear();      {  // topic transition from START -> [1] -> UNCONFIGURED         subscribeMsg();         String dump = getDump();         log.fine(dump);         // Expecting something like:         // <TopicHandler id='http_192_168_1_4_3412/msg/TestTopicLifeCycleMsg' state='UNCONFIGURED'>         //  <uniqueKey>TestTopicLifeCycleMsg</uniqueKey>         assertTrue("Missing topic", dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") != -1);         assertTrue("Topic in wrong state:" + dump, dump.indexOf("TestTopicLifeCycleMsg' state='UNCONFIGURED'") != -1);      }      {  // topic transition from UNCONFIGURED -> [4] -> ALIVE         long topicDestroyDelay = 4000L;         long msgLifeTime = 40000000L;         this.blockUpdateTime = 3000L; // Blocking callback thread for 3 sec to force state SOFTERASED !!         sendExpiringMsg(true, topicDestroyDelay, msgLifeTime);          assertEquals("numReceived after sending", 1, this.updateInterceptor.waitOnUpdate(2000L, 1)); // message arrived?         String dump = getDump();         log.fine(dump);         // Expecting something like:         // <TopicHandler id='http_192_168_1_4_3412/msg/TestTopicLifeCycleMsg' state='ALIVE'>         //  <uniqueKey>TestTopicLifeCycleMsg</uniqueKey>         assertTrue("Missing topic", dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") != -1);         assertTrue("Topic in wrong state:" + dump, dump.indexOf("TestTopicLifeCycleMsg' state='ALIVE'") != -1);      }      {  // topic transition from ALIVE -> [7] -> SOFTERASED         boolean forceDestroy = false;         EraseReturnQos[] erq = sendErase(forceDestroy);         assertEquals("erase failed", 1, erq.length);         this.updateInterceptor.waitOnUpdate(1000L, 1); // Expecting one erase event (for the above subscription)         try { Thread.sleep(1000L); } catch( InterruptedException i) {} // Give server a change to destroy topic after delivery of erase event messages         String dump = getDump();         assertTrue("Missing topic", dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") != -1);         assertTrue("Topic in wrong state:" + dump, dump.indexOf("TestTopicLifeCycleMsg' state='SOFTERASED'") != -1);      }      {  // topic transition from SOFTERASED -> [12] --> DEAD         try { Thread.sleep(4500L); } catch( InterruptedException i) {}         String dump = getDump();         assertTrue("Not expected a dead topic:" + dump, dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") == -1);      }      log.info("SUCCESS testSoftErased");   }   /**    * THIS IS THE TEST    * Transitions [1] -> [4] -> [10]    */   public void testForcedErased() {      log.info("Entering testForcedErased ...");      this.updateInterceptor.clear();      {  // topic transition from START -> [1] -> UNCONFIGURED         subscribeMsg();         if (log.isLoggable(Level.FINE)) log.fine("Retrieving initial dump=" + getDump());         String dump = getDump();         log.fine(dump);         // Expecting something like:         // <TopicHandler id='http_192_168_1_4_3412/topic/TestTopicLifeCycleMsg' state='UNCONFIGURED'>         //  <uniqueKey>TestTopicLifeCycleMsg</uniqueKey>         assertTrue("Missing topic", dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") != -1);         assertTrue("Topic in wrong state:" + dump, dump.indexOf("TestTopicLifeCycleMsg' state='UNCONFIGURED'") != -1);      }      {  // topic transition from UNCONFIGURED -> [4] -> ALIVE         long topicDestroyDelay = 400000L;         long msgLifeTime = 400000L;         this.blockUpdateTime = 0L;         sendExpiringMsg(true, topicDestroyDelay, msgLifeTime);          assertEquals("numReceived after sending", 1, this.updateInterceptor.waitOnUpdate(2000L, 1));         String dump = getDump();         log.fine(dump);         // Expecting something like:         // <TopicHandler id='http_192_168_1_4_3412/topic/TestTopicLifeCycleMsg' state='ALIVE'>         //  <uniqueKey>TestTopicLifeCycleMsg</uniqueKey>         assertTrue("Missing topic", dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") != -1);         assertTrue("Topic in wrong state:" + dump, dump.indexOf("TestTopicLifeCycleMsg' state='ALIVE'") != -1);      }      {  // topic transition from ALIVE -> [10] -> DEAD         boolean forceDestroy = true;         EraseReturnQos[] erq = sendErase(forceDestroy);         assertEquals("erase failed", 1, erq.length);         String dump = getDump();         assertTrue("Not expected a dead topic:" + dump, dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") == -1);      }      log.info("SUCCESS testForcedErased");   }   /**    * THIS IS THE TEST    * Transitions [1] -> [9]    */   public void testUnconfiguredErased() {      log.info("Entering testUnconfiguredErased ...");      this.updateInterceptor.clear();      this.updateInterceptor.countErased(true);      {  // topic transition from START -> [1] -> UNCONFIGURED         subscribeMsg();         String dump = getDump();         if (log.isLoggable(Level.FINE)) log.fine("Retrieving initial dump=" + dump);         // Expecting something like:         // <TopicHandler id='http_192_168_1_4_3412/topic/TestTopicLifeCycleMsg' state='UNCONFIGURED'>         //  <uniqueKey>TestTopicLifeCycleMsg</uniqueKey>         assertTrue("Missing topic", dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") != -1);         assertTrue("Topic in wrong state:" + dump, dump.indexOf("TestTopicLifeCycleMsg' state='UNCONFIGURED'") != -1);      }      {  // topic transition from UNCONFIGURED -> [9] -> DEAD         boolean forceDestroy = false;         EraseReturnQos[] erq = sendErase(forceDestroy);         assertEquals("erase failed", 1, erq.length);         this.updateInterceptor.waitOnUpdate(1000L, 1); // Expecting one erase event (for the above subscription)         assertEquals("Expected ERASE", 1, this.updateInterceptor.getMsgs(this.publishOid,Constants.STATE_ERASED).length);         try { Thread.sleep(1000L); } catch( InterruptedException i) {} // Give server a change to destroy topic after delivery of erase event messages         String dump = getDump();         assertTrue("Not expected a dead topic:" + dump, dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") == -1);      }      log.info("SUCCESS testUnconfiguredErased");   }   /**    * THIS IS THE TEST    * Transitions [1] -> [9] (by unSubscribe)    */   public void testUnconfiguredUnSubscribe() {      log.info("Entering testUnconfiguredUnSubscribe ...");      this.updateInterceptor.clear();      {  // topic transition from START -> [1] -> UNCONFIGURED         subscribeMsg();         if (log.isLoggable(Level.FINE)) log.fine("Retrieving initial dump=" + getDump());         String dump = getDump();         log.fine(dump);         // Expecting something like:         // <TopicHandler id='http_192_168_1_4_3412/topic/TestTopicLifeCycleMsg' state='UNCONFIGURED'>         //  <uniqueKey>TestTopicLifeCycleMsg</uniqueKey>         assertTrue("Missing topic", dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") != -1);         assertTrue("Topic in wrong state:" + dump, dump.indexOf("TestTopicLifeCycleMsg' state='UNCONFIGURED'") != -1);      }      {  // topic transition from UNCONFIGURED -> [9] -> DEAD         unSubscribeMsg();         String dump = getDump();         assertTrue("Not expected a dead topic:" + dump, dump.indexOf("<uniqueKey>"+publishOid+"</uniqueKey>") == -1);      }      log.info("SUCCESS testUnconfiguredUnSubscribe");   }   /**    * This is the callback method invoked from xmlBlaster    * delivering us a new asynchronous message.     * @see org.xmlBlaster.client.I_Callback#update(String, UpdateKey, byte[], UpdateQos)    */   public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {      log.info("Receiving update of a message " + updateKey.getOid() + " " + updateQos.getState());      if (updateQos.isOk()) {         //assertEquals("Wrong oid of message returned", publishOid, updateKey.getOid());         assertEquals("Message content is corrupted", new String(senderContent), new String(content));      }      if (this.blockUpdateTime > 0L) {         log.info("Blocking the update callback for " + this.blockUpdateTime + " millis");         try { Thread.sleep(this.blockUpdateTime); } catch( InterruptedException i) {}         this.blockUpdateTime = 0L;         log.info("Block released, reset blockTimer");      }      return "";   }   /**    * Method is used by TestRunner to load these tests    */   public static Test suite() {       TestSuite suite= new TestSuite();       suite.addTest(new TestTopicLifeCycle(new Global(), "testSoftErased"));       suite.addTest(new TestTopicLifeCycle(new Global(), "testExpiry"));       suite.addTest(new TestTopicLifeCycle(new Global(), "testUnreferencedAlive"));       suite.addTest(new TestTopicLifeCycle(new Global(), "testVolatile"));       suite.addTest(new TestTopicLifeCycle(new Global(), "testSubscribeVolatile"));       suite.addTest(new TestTopicLifeCycle(new Global(), "testUnconfiguredSubscribeSubscribe"));       suite.addTest(new TestTopicLifeCycle(new Global(), "testSoftErased"));       suite.addTest(new TestTopicLifeCycle(new Global(), "testForcedErased"));       suite.addTest(new TestTopicLifeCycle(new Global(), "testUnconfiguredErased"));       suite.addTest(new TestTopicLifeCycle(new Global(), "testUnconfiguredUnSubscribe"));       return suite;   }   /**    * Invoke: java org.xmlBlaster.test.topic.TestTopicLifeCycle -startEmbedded false    */   public static void main(String args[]) {      try {         TestTopicLifeCycle testSub = new TestTopicLifeCycle(new Global(args), "TestTopicLifeCycle");         testSub.setUp();         //testSub.testExpiry();         //testSub.testUnreferencedAlive();         //testSub.testVolatile();         //testSub.testSubscribeVolatile();         //testSub.testUnconfiguredSubscribeSubscribe();         //testSub.testSoftErased();         //testSub.testForcedErased();         testSub.testUnconfiguredErased();         //testSub.testUnconfiguredUnSubscribe();         testSub.tearDown();      }      catch(Exception e) {         e.printStackTrace();         System.out.println("ERROR!!!!: " + e.toString());      }   }}

⌨️ 快捷键说明

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