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

📄 testadminget.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------Name:      TestAdminGet.javaProject:   xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE file------------------------------------------------------------------------------*/package org.xmlBlaster.test.admin;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.SessionName;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.def.Constants;import org.xmlBlaster.util.property.PropString;import org.xmlBlaster.util.qos.QuerySpecQos;import org.xmlBlaster.util.MsgUnit;import org.xmlBlaster.client.I_Callback;import org.xmlBlaster.client.I_XmlBlasterAccess;import org.xmlBlaster.client.key.GetKey;import org.xmlBlaster.client.key.PublishKey;import org.xmlBlaster.client.key.SubscribeKey;import org.xmlBlaster.client.key.UnSubscribeKey;import org.xmlBlaster.client.key.UpdateKey;import org.xmlBlaster.client.qos.*;import org.xmlBlaster.test.MsgInterceptor;import junit.framework.*;/** * Tests the activation/deactivation of the DispatchManager. * <br /> * If the DispatchManager is disactivated, asynchronous dispatch should not * be possible. * <p> * Invoke examples:<br /> * <pre> *   java junit.textui.TestRunner -noloading org.xmlBlaster.test.client.TestAdminGet *   java junit.swingui.TestRunner -noloading org.xmlBlaster.test.client.TestAdminGet * </pre> */public class TestAdminGet extends TestCase implements I_Callback{      public class PublisherThread extends Thread {      private Global global;      private long delay;      private MsgUnit[] msgUnits;      private Exception ex;            public PublisherThread(Global global, long timeToWaitBeforePublishing, MsgUnit[] msgUnits) {         this.global = global;         this.delay = timeToWaitBeforePublishing;         this.msgUnits = msgUnits;         start();      }            public boolean hasException() {         return (this.ex != null);      }            public void run() {         try {            if (this.delay > 0L) sleep(this.delay);            this.global.getXmlBlasterAccess().publishArr(this.msgUnits);         }         catch (Exception ex) {            ex.printStackTrace();            this.ex = ex;         }      }   }      private static String ME = "TestAdminGet";      private Global glob;   private static Logger log = Logger.getLogger(TestAdminGet.class.getName());   private MsgInterceptor updateInterceptor;   private String senderName;   private final String contentMime = "text/plain";      private String sessionName = "dispatchTester/1";   public TestAdminGet(String testName) {      this(null, testName);   }   public TestAdminGet(Global glob, String testName) {      super(testName);      this.senderName = testName;   }   /**    * Sets up the fixture.    * <p />    * Connect to xmlBlaster and login    */   protected void setUp() {      this.glob = (this.glob == null) ? Global.instance() : this.glob;      this.updateInterceptor = new MsgInterceptor(this.glob, log, null);            try {         I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess(); // Find orb         String passwd = "secret";         ConnectQos connectQos = new ConnectQos(this.glob, senderName, passwd); // == "<qos>...</qos>";         connectQos.setSessionName(new SessionName(this.glob, this.sessionName));         con.connect(connectQos, this);  // Login to xmlBlaster, register for updates      }      catch (XmlBlasterException e) {          log.warning("setUp() - login failed: " + e.getMessage());          fail("setUp() - login fail: " + e.getMessage());      }      catch (Exception e) {          log.severe("setUp() - login failed: " + e.toString());          e.printStackTrace();          fail("setUp() - login fail: " + e.toString());      }   }      /**    * Tears down the fixture.    * <p />    * cleaning up .... erase() the previous message OID and logout    */   protected void tearDown() {      log.info("Entering tearDown(), test is finished");      String xmlKey = "<key oid='' queryType='XPATH'>\n" +                      "   //TestAdminGet-AGENT" +                      "</key>";      String qos = "<qos><forceDestroy>true</forceDestroy></qos>";      I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess();      try {         EraseReturnQos[] arr = con.erase(xmlKey, qos);         PropString defaultPlugin = new PropString("CACHE,1.0");         String propName = defaultPlugin.setFromEnv(this.glob, glob.getStrippedId(), null, "persistence", Constants.RELATING_TOPICSTORE, "defaultPlugin");         log.info("Lookup of propName=" + propName + " defaultValue=" + defaultPlugin.getValue());      }      catch(XmlBlasterException e) {         log.severe("XmlBlasterException: " + e.getMessage());      }      finally {         con.disconnect(null);         // reset to default server bootstrapPort (necessary if other tests follow in the same JVM).         this.glob = null;         con = null;         Global.instance().shutdown();      }   }   /**    * TEST: Subscribe to a specific oid    */   private void doSubscribe(String oid) {      try {         SubscribeKey key = new SubscribeKey(this.glob, oid);         SubscribeQos qos = new SubscribeQos(this.glob); // "<qos><persistent>true</persistent></qos>";         qos.setWantNotify(false); // to avoig getting erased messages         SubscribeReturnQos subscriptionId = this.glob.getXmlBlasterAccess().subscribe(key, qos, this.updateInterceptor);         log.info("Success: Subscribe on subscriptionId=" + subscriptionId.getSubscriptionId() + " done");         assertTrue("returned null subscriptionId", subscriptionId != null);      } catch(XmlBlasterException e) {         log.warning("XmlBlasterException: " + e.getMessage());         assertTrue("subscribe - XmlBlasterException: " + e.getMessage(), false);      }   }    private void doUnSubscribe(String oid) {      try {         UnSubscribeKey key = new UnSubscribeKey(this.glob, oid);         UnSubscribeQos qos = new UnSubscribeQos(this.glob);         this.glob.getXmlBlasterAccess().unSubscribe(key, qos);      }       catch(XmlBlasterException e) {         log.warning("XmlBlasterException: " + e.getMessage());         assertTrue("subscribe - XmlBlasterException: " + e.getMessage(), false);      }   }    /**    * TEST: Construct a message and publish it.    * If the counter is negative, the content of the message will be an empty string.    * <p />    */   public void doPublish(int counter, String oid) throws XmlBlasterException {      log.info("Publishing a message " + oid + " ...");      String xmlKey = "<key oid='" + oid + "' contentMime='" + contentMime + "'><test></test></key>";      String content = "" + counter;      PublishQos qosWrapper = new PublishQos(glob); // == "<qos></qos>"      MsgUnit msgUnit = null;      if (counter > -1) msgUnit = new MsgUnit(xmlKey, content.getBytes(), qosWrapper.toXml());      else  msgUnit = new MsgUnit(xmlKey, "", qosWrapper.toXml());      this.glob.getXmlBlasterAccess().publish(msgUnit);      log.info("Success: Publishing of " + oid + " done");   }   /**    * Tests the activation flag setting and getting, i.e. disactivating/activating of the    * dispatcher.    */   public void testActivationFlag() {      try {         String oid = "TestActivationFlag";         log.info("Going to publish 3 times on message '" + oid + "' (first time before subscribing)");         doPublish(1, oid);         doSubscribe(oid);         doPublish(2, oid);         doPublish(3, oid);         assertEquals("wrong number of updates received", 3, this.updateInterceptor.waitOnUpdate(500L));         this.updateInterceptor.clear();         String getOid = "__cmd:client/" + this.sessionName + "/?dispatcherActive=one,two,three";         MsgUnit[] msg = this.glob.getXmlBlasterAccess().get(new GetKey(this.glob, getOid), new GetQos(this.glob));         assertEquals("wrong number of messages returned", 1, msg.length);         for (int i=0; i < msg.length; i++) {            log.info("testActivationFlag: dispatcherActive: (" + i + ") : '" + msg[i].getContentStr() + "'");            assertEquals("wrong return value", "true", msg[i].getContentStr());         }               getOid = "__cmd:client/" + this.sessionName + "/?dispatcherActive=false";         doPublish(-1, getOid);         getOid = "__cmd:client/" + this.sessionName + "/?dispatcherActive";         msg = this.glob.getXmlBlasterAccess().get(new GetKey(this.glob, getOid), new GetQos(this.glob));         assertEquals("wrong number of messages returned", 1, msg.length);         for (int i=0; i < msg.length; i++) {            log.info("testActivationFlag: dispatcherActive (result): (" + i + ") : '" + msg[i].getContentStr() + "'");            assertEquals("wrong return value", "false", msg[i].getContentStr());         }         doPublish(4, oid);         doPublish(5, oid);         int numArrived = this.updateInterceptor.waitOnUpdate(2000L);         assertEquals("wrong number of messages arrived", 0, numArrived);                           getOid = "__cmd:client/" + this.sessionName + "/?dispatcherActive=true";         doPublish(-1, getOid);

⌨️ 快捷键说明

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