Package org.xmlBlaster.client

Examples of org.xmlBlaster.client.I_XmlBlasterAccess


      this.serverGlobal = this.glob.getClone(args);
     
      serverThread = EmbeddedXmlBlaster.startXmlBlaster(this.serverGlobal);
      log.info("XmlBlaster is ready for testing on bootstrapPort " + serverPort);
      try {
         I_XmlBlasterAccess con = glob.getXmlBlasterAccess(); // Find orb

         String passwd = "secret";
         ConnectQos connectQos = new ConnectQos(glob, senderName, passwd); // == "<qos>...</qos>";
         // set the persistent connection
         connectQos.setPersistent(false);
         this.updateInterceptor = new MsgInterceptor(this.glob, log, null); // Collect received msgs
         con.connect(connectQos, this.updateInterceptor)// Login to xmlBlaster, register for updates
      }
      catch (XmlBlasterException e) {
          log.warning("setUp() - login failed: " + e.getMessage());
          fail("setUp() - login fail: " + e.getMessage());
      }
View Full Code Here


      String xmlKey = "<key oid='' queryType='XPATH'>\n" +
                      "   //TestHistoryZero-AGENT" +
                      "</key>";

      String qos = "<qos><forceDestroy>true</forceDestroy></qos>";
      I_XmlBlasterAccess con = this.glob.getXmlBlasterAccess();
      try {
         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);
         EmbeddedXmlBlaster.stopXmlBlaster(this.serverThread);
         this.serverThread = null;
         // reset to default server bootstrapPort (necessary if other tests follow in the same JVM).
         Util.resetPorts(this.serverGlobal);
         Util.resetPorts(glob);
View Full Code Here

    * Test the three creation variants of XmlBlasterAccess and tests
    * all methods with null arguments
    */
   public void testCreation() {
      System.out.println("***XmlBlasterAccessTest: testCreation ...");
      I_XmlBlasterAccess xmlBlasterAccess = null;
      for (int i=0; i<3; i++) {
         if (i == 0) {
            Global nullGlobal = null;
            xmlBlasterAccess = new XmlBlasterAccess(nullGlobal);
         }
         else if (i == 1) {
            String[] nullArgs = null;
            xmlBlasterAccess = new XmlBlasterAccess(nullArgs);
         }
         else {
            xmlBlasterAccess = glob.getXmlBlasterAccess();
         }

         xmlBlasterAccess.setServerNodeId("/node/test");
         assertEquals("", "/node/test", xmlBlasterAccess.getServerNodeId());

         xmlBlasterAccess.setServerNodeId("FRISH FISH");
         assertEquals("", "/node/FRISH FISH", xmlBlasterAccess.getServerNodeId());

         try {
            ConnectQos connectQos = new ConnectQos(glob);
            Address address = new Address(glob);
            address.setBootstrapPort(8999); // a wrong port to avoid connection
            address.setRetries(0);       // switch off polling
            connectQos.setAddress(address);
            xmlBlasterAccess.connect(connectQos, null);
            fail("Not expected successful connect");
         }
         catch (XmlBlasterException e) {
            if (e.isErrorCode(ErrorCode.COMMUNICATION_NOCONNECTION_DEAD))
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testDefaultConnectWithoutServer failed: " + e.getMessage());
         }

         if (xmlBlasterAccess.isAlive()) {
            log.severe("No testing possible when xmlBlaster is running - ignoring this test");
            xmlBlasterAccess.disconnect(null);
            continue;
         }

         assertTrue("", null != xmlBlasterAccess.getQueue());
         assertEquals("", false, xmlBlasterAccess.isAlive());
         assertEquals("", false, xmlBlasterAccess.isPolling());
         assertEquals("", false, xmlBlasterAccess.isDead());
         log.info("SUCCESS: Check I_ConnectionHandler");

         assertEquals("", false, xmlBlasterAccess.isConnected());
         xmlBlasterAccess.registerConnectionListener((I_ConnectionStateListener)null);


         assertTrue("", xmlBlasterAccess.getCbServer() == null);
         try {
            I_CallbackServer cbServer = xmlBlasterAccess.initCbServer(null, null);
            assertTrue("", cbServer != null);
            assertTrue("", cbServer.getCbProtocol() != null);
            assertTrue("", cbServer.getCbAddress() != null);
            log.info("SUCCESS: initCbServer protocol=" + cbServer.getCbProtocol() + " address=" + cbServer.getCbAddress());
            cbServer.shutdown();
            log.info("SUCCESS: CbServer.shutdown()");
            assertTrue("", xmlBlasterAccess.getCbServer() == null); // is not cached in xmlBlasterAccess
         }
         catch (XmlBlasterException e) {
            fail("testCreation failed: " + e.getMessage());
         }

         assertTrue("", xmlBlasterAccess.getSecurityPlugin() != null);
         assertEquals("", true, xmlBlasterAccess.disconnect(null));
         assertTrue("", xmlBlasterAccess.getConnectReturnQos() == null);
         assertTrue("", xmlBlasterAccess.getConnectQos() == null);
         assertTrue("", xmlBlasterAccess.getId() != null);
         assertTrue("", xmlBlasterAccess.getSessionName() == null);

         try {
            xmlBlasterAccess.subscribe((SubscribeKey)null, null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }

         try {
            xmlBlasterAccess.subscribe((String)null, null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }

         try {
            xmlBlasterAccess.subscribe((SubscribeKey)null, null, null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }

         try {
            xmlBlasterAccess.get((String)null, null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }

         try {
            xmlBlasterAccess.get((GetKey)null, null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }

         try {
            xmlBlasterAccess.unSubscribe((String)null, null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }

         try {
            xmlBlasterAccess.unSubscribe((UnSubscribeKey)null, null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }

         try {
            xmlBlasterAccess.publish(null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }
           
         try {
            xmlBlasterAccess.publishOneway(null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }
           
         try {
            xmlBlasterAccess.publishArr(null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }
           
         try {
            xmlBlasterAccess.erase((String)null, null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }

         try {
            xmlBlasterAccess.erase((EraseKey)null, null);
         }
         catch (XmlBlasterException e) {
            if (e.isUser())
               log.info("Exception is OK if not connected: " + e.getErrorCode());
            else
               fail("testCreation failed: " + e.getMessage());
         }

         assertTrue("", xmlBlasterAccess.getGlobal() != null);
         assertTrue("", xmlBlasterAccess.toXml() != null);

         log.info("SUCCESS: Check I_XmlBlasterAccess");
      }

      System.out.println("***XmlBlasterAccessTest: testCreation [SUCCESS]");
View Full Code Here

   }

   public void testDefaultConnectWithoutServer() throws Exception {
      System.out.println("***XmlBlasterAccessTest: testDefaultConnectWithoutServer ...");
      Global nullGlobal = null;
      I_XmlBlasterAccess xmlBlasterAccess = new XmlBlasterAccess(nullGlobal);

      assertEquals("", false, xmlBlasterAccess.isConnected());

      ConnectQos q = new ConnectQos(null);
      log.info("Default ConnectQos=" + q.toXml() + " retries=" + q.getAddress().getRetries() + " delay=" + q.getAddress().getDelay());
      assertEquals("", -1, q.getAddress().getRetries()); // retry forever
      assertEquals("", q.getAddress().getDefaultDelay(), q.getAddress().getDelay()); // 5000L
View Full Code Here

   {
      log.info("testZeroSessions() ...");
      try {
         log.info("Connecting ...");
         Global glob = this.glob.getClone(null);
         I_XmlBlasterAccess con = glob.getXmlBlasterAccess();
         ConnectQos qos = new ConnectQos(glob, name, passwd);
         qos.setMaxSessions(-16);
         con.connect(qos, this); // Login to xmlBlaster
         assertTrue("Connecting with zero sessions should not be possible", false);
      }
      catch (Exception e) {
         log.info("Success, can't connect with zero sessions");
      }
View Full Code Here

      }

      try {
         log.info("Connecting other ...");
         Global glob2 = glob.getClone(null);
         I_XmlBlasterAccess con2 = glob2.getXmlBlasterAccess();

         // Activate plugin for callback only:
         ConnectQos qos = new ConnectQos(glob2, "JOE/1", "secret");
         SessionQos sessionQos = qos.getSessionQos();
         sessionQos.setMaxSessions(1);
         sessionQos.setReconnectSameClientOnly(true);
         con2.connect(qos, this);
         fail(ME+": Reconnect to xmlBlaster should not be possible");
      }
      catch (XmlBlasterException e) {
         log.info("SUCCESS, reconnect is not possible: " + e.getMessage());
      }

      // boolean isSocket = Client
      // boolean isRpc = (this.con.getCbServer() instanceof XmlRpcCallbackImpl);

      try {
         Client.shutdownCb(con, Client.Shutdown.LEAVE_SERVER);
      }
      catch (XmlBlasterException e) {
         fail("Can't setup test: " + e.getMessage());
      }
      try { Thread.sleep(2000); } catch( InterruptedException i) {} // Wait

      try {
         log.info("Connecting other ...");
         Global glob2 = glob.getClone(null);
         I_XmlBlasterAccess con2 = glob2.getXmlBlasterAccess();

         // Activate plugin for callback only:
         ConnectQos qos = new ConnectQos(glob2, "JOE/1", "secret");
         SessionQos sessionQos = qos.getSessionQos();
         sessionQos.setMaxSessions(1);
         sessionQos.setReconnectSameClientOnly(true);
         con2.connect(qos, this);
         log.info("SUCCESS, reconnect is OK after first session died");
      }
      catch (XmlBlasterException e) {
         fail(ME + ": Reconnect should now be possible: " + e.getMessage());
      }
View Full Code Here

    */
   public void testSessionTimeout()
   {
      log.info("testSessionTimeout() ...");
      long timeout = 1000L;
      I_XmlBlasterAccess con = null;
      Global glob = this.glob.getClone(null);
      try {
         try {
            con = glob.getXmlBlasterAccess();
            ConnectQos qos = new ConnectQos(glob, name, passwd);
            qos.setSessionTimeout(timeout);
            con.connect(qos, this);
         }
         catch (Exception e) {
            log.severe(e.toString());
            assertTrue("Login failed" + e.toString(), false);
         }

         try { Thread.sleep(timeout*2); } catch (Exception e) { } // wait until session expires

         try {
            log.info("Check that session has dissapeared ...");
            MsgUnit[] msgs = Util.adminGet(glob, "__cmd:?clientList");
            assertEquals("Can't access __cmd:?clientList", 1, msgs.length);
            log.info("Got userList=" + msgs[0].getContentStr());
            assertEquals("Session of " + name + " was not destroyed by failing callback",
                      -1, msgs[0].getContentStr().indexOf(name));
         }
         catch (XmlBlasterException e) {
            fail("Session was not destroyed: " + e.toString());
         }
      }
      finally { // clean up
         try {
            con.disconnect(null);
         }
         catch (Throwable e) {
            assertTrue(e.toString(), false);
         }
      }
View Full Code Here

    */
   public void testSessionRefresh()
   {
      log.info("testSessionRefresh() ...");
      long timeout = 2000L;
      I_XmlBlasterAccess con = null;
      Global glob = this.glob.getClone(null);
      try {
         try {
            con = glob.getXmlBlasterAccess();
            ConnectQos qos = new ConnectQos(glob, name, passwd);
            qos.setRefreshSession(true);
            qos.setSessionTimeout(timeout);
            con.connect(qos, this);
         }
         catch (Exception e) {
            log.severe(e.toString());
            assertTrue("Login failed" + e.toString(), false);
         }

         log.info("Wait " + timeout*2 + " sec if session expires (because of inactivity)");
         try { Thread.sleep(timeout*2); } catch (Exception e) { }

         try {
            for (int ii=0; ii<1; ii++) {
               try { Thread.sleep(timeout/2); } catch (Exception e) { }
               log.info("Check access #" + ii + " ...");
               con.get("<key oid='__cmd:?freeMem'/>", null);
               log.info("Check access #" + ii + " OK");
            }
         }
         catch (Exception e) {
            log.severe("No access: " + e.toString());
            assertTrue("Session is expired", false);
         }
      }
      finally { // clean up
         try {
            con.disconnect(null);
         }
         catch (Throwable e) {
            assertTrue(e.toString(), false);
         }
      }
View Full Code Here

    */
   public void testSessionTimeoutRespan()
   {
      log.info("testSessionTimeoutRespan() ...");
      long timeout = 2000L;
      I_XmlBlasterAccess con = null;
      Global glob = this.glob.getClone(null);
      try {
         try {
            con = glob.getXmlBlasterAccess();
            ConnectQos qos = new ConnectQos(glob, name, passwd);
            qos.setSessionTimeout(timeout);
            con.connect(qos, this);
         }
         catch (Exception e) {
            log.severe(e.toString());
            assertTrue("Login failed" + e.toString(), false);
         }

         try {
            for (int ii=0; ii<4; ii++) {
               try { Thread.sleep(timeout/2); } catch (Exception e) { }
               log.info("Check access #" + ii + " ...");
               con.get("<key oid='__cmd:?freeMem'/>", null);
               log.info("Check access #" + ii + " OK");
            }
         }
         catch (Exception e) {
            log.severe("No access: " + e.toString());
            assertTrue("Session is expired", false);
         }
      }
      finally { // clean up
         try {
            con.disconnect(null);
         }
         catch (Throwable e) {
            assertTrue(e.toString(), false);
         }
      }
View Full Code Here

      int sweeps = glob.getProperty().get("sweeps", 500);
      Point[] points = new Point[nmax];
      Rectangle bound = new Rectangle(0, 0, 1000, 500);
      for (int i=0; i < nmax; i++) points[i] = newPoint(null, bound);

      I_XmlBlasterAccess con = null;
      try {
         con = glob.getXmlBlasterAccess();

         ConnectQos qos = new ConnectQos(glob);
         con.connect(qos, null)// Login to xmlBlaster, register for updates

         for (int j=0; j < sweeps; j++) {
            for (int i=0; i < nmax; i++) {
               points[i] = newPoint(points[i], bound);
               String content = new String(points[i].x + ";" + points[i].y);
               con.publish(new MsgUnit(glob, "<key oid='" + oidPrefix + "." + (i+1) + "'><" + oidPrefix + "/></key>", content.getBytes(),
                                           "<qos/>"));
            }
            Thread.sleep(200L);
         }

         for (int i=0; i < nmax; i++) {
            con.erase("<key oid='" + oidPrefix + "." + (i+1) + "'/>", null);
         }
      }
      catch (Exception e) {
         System.err.println(e.getMessage());
      }
      finally {
         try {
            if (con != null) con.disconnect(null);
         }
         catch (Exception ex) {        
            System.err.println(ex.getMessage());
         }
      }
View Full Code Here

TOP

Related Classes of org.xmlBlaster.client.I_XmlBlasterAccess

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.