Package org.xmlBlaster.util

Examples of org.xmlBlaster.util.Timestamp


         conn = pool.reserve();
         conn.setAutoCommit(true);
         XBStore newStore = storeFactory.getByName(store.getNodeDb(), store.getTypeDb(), store.getPostfixDb(), conn,
               timeout);
         if (newStore == null) {
            store.setId(new Timestamp().getTimestamp());
            storeFactory.insert(store, conn, timeout);
            newStore = store;
         }
         return newStore;
      }
View Full Code Here


         assertEquals("", false, qos.getRouteNodes()[1].getDirtyRead());
         assertEquals("", false, qos.getRouteNodes()[2].getDirtyRead());

         assertEquals("", PriorityEnum.HIGH_PRIORITY, qos.getPriority());
         assertEquals("", false, qos.isFromPersistenceStore());
         Timestamp timestamp = new Timestamp();
         assertTrue("timestamp.getTimestamp()="+timestamp.getTimestamp()+" qos.getRcvTimestamp().getTimestamp()="+qos.getRcvTimestamp().getTimestamp() , timestamp.getTimestamp() > qos.getRcvTimestamp().getTimestamp());
         assertTrue("timestamp.getTimestamp()="+timestamp.getTimestamp()+" qos.getRcvTimestamp().getTimestamp()="+qos.getRcvTimestamp().getTimestamp() , timestamp.getTimestamp() < (qos.getRcvTimestamp().getTimestamp()+10000000));
         assertEquals("", 2, qos.getDestinations().size());
         assertEquals("", true, ((Destination)qos.getDestinations().get(0)).forceQueuing());
      }
      catch (XmlBlasterException e) {
         fail("testPublishQosServer failed: " + e.toString());
View Full Code Here

    */
   public void testGetReturnQos() {
      System.out.println("***MsgQosFactoryTest: testGetReturnQos ...");
     
      try {
         Timestamp timestamp = new Timestamp();
         String xml =
            "<qos>\n" +
            "   <destination queryType='EXACT' forceQueuing='true'>\n" +
            "      Tim\n" +
            "   </destination>\n" +
            "   <destination queryType='EXACT'>\n" +
            "      Ben\n" +
            "   </destination>\n" +
            /*
            "   <destination queryType='XPATH'>\n" +
            "      //[GROUP='Manager']\n" +
            "   </destination>\n" +
            "   <destination queryType='XPATH'>\n" +
            "      //ROLE/[@id='Developer']\n" +
            "   </destination>\n" +
            */
            "   <sender>\n" +
            "      Gesa\n" +
            "   </sender>\n" +
            "   <priority>7</priority>\n" +
            "   <expiration lifeTime='2400' remainingLife='12000'/>\n" +
            "   <rcvTimestamp nanos='" + timestamp.getTimestamp() + "'/>\n" + // if from persistent store
            "   <persistent/>\n" +
            "   <forceUpdate>false</forceUpdate>\n" +
            "   <route>\n" +
            "      <node id='bilbo' stratum='2' timestamp='9408630500' dirtyRead='true'/>\n" +
            "      <node id='frodo' stratum='1' timestamp='9408630538' dirtyRead='false'/>\n" +
            "      <node id='heron' stratum='0' timestamp='9408630564'/>\n" +
            "   </route>\n" +
            "</qos>\n";

         GetReturnQos qos = new GetReturnQos(glob, xml);

         assertEquals("", false, qos.isVolatile());
         assertEquals("", true, qos.isPersistent());
         assertEquals("", false, qos.isReadonly());
         assertEquals("", "Gesa", qos.getSender().getLoginName());

         assertEquals("", 3, qos.getRouteNodes().length);
         assertEquals("", 2, qos.getRouteNodes()[0].getStratum());
         assertEquals("", 0, qos.getRouteNodes()[2].getStratum());
         assertEquals("", 9408630500L, qos.getRouteNodes()[0].getTimestamp().getTimestamp());
         assertEquals("", true, qos.getRouteNodes()[0].getDirtyRead());
         assertEquals("", false, qos.getRouteNodes()[1].getDirtyRead());
         assertEquals("", false, qos.getRouteNodes()[2].getDirtyRead());

         assertEquals("", PriorityEnum.HIGH_PRIORITY, qos.getPriority());
         assertEquals("", timestamp.getTimestamp(), qos.getRcvTimestamp().getTimestamp());
      }
      catch (XmlBlasterException e) {
         fail("testGetReturnQos failed: " + e.toString());
      }

View Full Code Here

    */
   public void testUpdateQos() {
      System.out.println("***MsgQosFactoryTest: testUpdateQos ...");
     
      try {
         Timestamp timestamp = new Timestamp();
         String xml =
            "<qos>\n" +
            "   <destination queryType='EXACT' forceQueuing='true'>\n" +
            "      Tim\n" +
            "   </destination>\n" +
            "   <destination queryType='EXACT'>\n" +
            "      Ben\n" +
            "   </destination>\n" +
            /*
            "   <destination queryType='XPATH'>\n" +
            "      //[GROUP='Manager']\n" +
            "   </destination>\n" +
            "   <destination queryType='XPATH'>\n" +
            "      //ROLE/[@id='Developer']\n" +
            "   </destination>\n" +
            */
            "   <sender>\n" +
            "      Gesa\n" +
            "   </sender>\n" +
            "   <priority>7</priority>\n" +
            "   <expiration lifeTime='2400' remainingLife='12000'/>\n" +
            "   <rcvTimestamp nanos='" + timestamp.getTimestamp() + "'/>\n" + // if from persistent store
            "   <persistent/>\n" +
            "   <forceUpdate>false</forceUpdate>\n" +
            "   <route>\n" +
            "      <node id='bilbo' stratum='2' timestamp='9408630500' dirtyRead='true'/>\n" +
            "      <node id='frodo' stratum='1' timestamp='9408630538' dirtyRead='false'/>\n" +
            "      <node id='heron' stratum='0' timestamp='9408630564'/>\n" +
            "   </route>\n" +
            "   <topic readonly='true'/>\n" +
            "</qos>\n";

         UpdateQos qos = new UpdateQos(glob, xml);

         assertEquals("", true, qos.isSubscribable());
         assertEquals("", true, qos.isPtp());
         assertEquals("", false, qos.isVolatile());
         assertEquals("", true, qos.isPersistent());
         assertEquals("", true, qos.isReadonly());
         assertEquals("", "Gesa", qos.getSender().getLoginName());

         assertEquals("", 3, qos.getRouteNodes().length);
         assertEquals("", 2, qos.getRouteNodes()[0].getStratum());
         assertEquals("", 0, qos.getRouteNodes()[2].getStratum());
         assertEquals("", 9408630500L, qos.getRouteNodes()[0].getTimestamp().getTimestamp());
         assertEquals("", true, qos.getRouteNodes()[0].getDirtyRead());
         assertEquals("", false, qos.getRouteNodes()[1].getDirtyRead());
         assertEquals("", false, qos.getRouteNodes()[2].getDirtyRead());

         assertEquals("", PriorityEnum.HIGH_PRIORITY, qos.getPriority());
         assertEquals("", timestamp.getTimestamp(), qos.getRcvTimestamp().getTimestamp());
      }
      catch (XmlBlasterException e) {
         fail("testUpdateQos failed: " + e.toString());
      }

View Full Code Here

    */
   public void testFromPersistentStore() {
      System.out.println("***MsgQosFactoryTest: testFromPersistentStore ...");
     
      try {
         Timestamp timestamp = new Timestamp();
         String xml =
            "<qos>\n" +
            "   <rcvTimestamp nanos='" + timestamp.getTimestamp() + "'/>\n" + // if from persistent store
            "</qos>\n";

         MsgQosSaxFactory factory = new MsgQosSaxFactory(glob);
         MsgQosData qos = factory.readObject(xml);

         assertEquals("", timestamp.getTimestamp(), qos.getRcvTimestamp().getTimestamp());
      }
      catch (XmlBlasterException e) {
         fail("testFromPersistentStore failed: " + e.toString());
      }

View Full Code Here

   /**
    * Test basics
    */
   public void testTimestamp() {
      Timestamp ts1 = new Timestamp();
      Timestamp ts2 = new Timestamp();
      assertFalse("Same timestamp", ts1.equals(ts2));
      assertTrue("timestamp descending", ts2.compareTo(ts1) == 1);
      assertEquals("string parse", ts2.toString(), Timestamp.valueOf(ts2.toString()).toString());
      System.out.println("***TimestampTest: testTimestamp [SUCCESS]");
   }
View Full Code Here

    */
   public void testUnique() {
      long last = 0L;
      int n = 10000;
      for(int i=0; i<n; i++) {
         Timestamp ts = new Timestamp();
         assertTrue("Timestamp not ascending or unique last="+last+" curr="+ts.getTimestamp(), ts.getTimestamp() > last);
         last = ts.getTimestamp();
      }
      System.out.println("***TimestampTest: testUnique [SUCCESS]");
   }
View Full Code Here

         threadArr[iThread] = new Thread() {
            public void run() {
               super.setName(""+iThread);
               long last = 0L;
               for(int j=0; j<m; j++) {
                  Timestamp ts = new Timestamp();
                  set.add(ts.getTimestampLong());
                  assertTrue("Timestamp not ascending or unique", ts.getTimestamp() > last);
                  last = ts.getTimestamp();
               }
               System.out.println("Thread #" + super.getName() + " done");
            }
         };
         threadArr[iThread].start();
View Full Code Here

      System.out.println("***TimeoutTest: testTimeout ...");

      {
         event = false;
         Timeout timeout = new Timeout(ME);
         Timestamp timeoutHandle = timeout.addTimeoutListener(new I_Timeout() {
               public void timeout(Object userData) {
                  event = true;
                  log.info("Timeout happened after 0 millisec");
               }
            },
            0L, null);

         try { Thread.sleep(100L); } catch (InterruptedException e) {}
         assertEquals("Timeout not occurred after 0 msec.", true, event);
      }
     
      {
         event = false;
         Timeout timeout = new Timeout(ME);
         Timestamp timeoutHandle = timeout.addTimeoutListener(new I_Timeout() {
               public void timeout(Object userData) {
                  event = true;
                  log.info("Timeout happened after 500 millisec");
               }
            },
            500L, null);

         try { Thread.sleep(800L); } catch (InterruptedException e) {}
         assertEquals("Timeout not occurred after 1 sec.", true, event);
      }
     
      {
         event = false;
         Timeout timeout = new Timeout(ME);
         Timestamp timeoutHandle = timeout.addTimeoutListener(new I_Timeout() {
               public void timeout(Object userData) {
                  event = true;
                  log.severe("Timeout happened after 1 sec");
               }
            },
View Full Code Here

      Timeout timeout = new Timeout();
      counter = 0;

      // Test to remove invalid keys
      timeout.removeTimeoutListener(null);
      timeout.removeTimeoutListener(new Timestamp(12));

      // We have the internal knowledge that the key is the scheduled timeout in millis since 1970
      // so we use it here for testing ...
      final Timestamp[] keyArr = new Timestamp[4];
      class Dummy1 implements I_Timeout {
         private String ME = "Dummy1";
         public void timeout(Object userData) {
            long time = System.currentTimeMillis();
            long diff = time - keyArr[counter].getMillis();
            if (Math.abs(diff) < 40)
               // Allow 40 millis wrong notification (for code execution etc.) ...
               log.info("Timeout occurred for " + userData.toString() + " at " + time + " millis, real time failure=" + diff + " millis.");
            else {
               System.err.println("*****ERROR: Wrong timeout occurred for " + userData.toString() + " at " + time + " millis, scheduled was " + keyArr[counter] + " , real time failure=" + diff + " millis.");
               fail("*****ERROR: Wrong timeout occurred for " + userData.toString() + " at " + time + " millis, scheduled was " + keyArr[counter] + " , real time failure=" + diff + " millis.");
            }
            counter++;
         }
      }
      Dummy1 dummy = new Dummy1();
      keyArr[2] = timeout.addTimeoutListener(dummy, 4000L, "timer-4000");

      keyArr[3] = timeout.addTimeoutListener(dummy, 2000L, "timer-5500");
      try { keyArr[3] = timeout.refreshTimeoutListener(keyArr[3], 5500L); } catch (XmlBlasterException e) { fail("Refresh failed: " + e.getMessage()); }
      long diffT = keyArr[3].getMillis() - System.currentTimeMillis();
      assertTrue("ERROR: refresh failed", (Math.abs(5500L - diffT) <= 30));

      keyArr[0] = timeout.addTimeoutListener(dummy, 1000L, "timer-1000");
      keyArr[1] = timeout.addTimeoutListener(dummy, 1000L, "timer-1000");

      long span = timeout.spanToTimeout(keyArr[2]);
      assertTrue("*****ERROR: This short span to timeout = " + span + " is probably wrong, or you have a very slow computer.", span >= 3000L);

      Timestamp key = timeout.addTimeoutListener(dummy, 1000L, "timer-1000");
      timeout.removeTimeoutListener(key);
      try { key = timeout.refreshTimeoutListener(key, 1500L); } catch (XmlBlasterException e) { log.info("Refresh failed which is OK (it is a test): " + e.getMessage()); }

      assertEquals("Should not be expired", false, timeout.isExpired(keyArr[2]));

View Full Code Here

TOP

Related Classes of org.xmlBlaster.util.Timestamp

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.