예제 #1
0
 /**
  * If some or all of the children of this name are versions, returns the latest version among
  * them.
  *
  * @return ContentName The latest version component
  */
 public ContentName getLatestVersionChildName() {
   // of the available names in _children that are version components,
   // find the latest one (version-wise)
   // names are sorted, so the last one that is a version should be the latest version
   // ListIterator previous doesn't work unless you've somehow gotten it to point at the end...
   ContentName theName = null;
   ContentName latestName = null;
   CCNTime latestTimestamp = null;
   Iterator<ContentName> it = _children.iterator();
   // TODO these are sorted -- we just need to iterate through them in reverse order. Having
   // trouble finding something like C++'s reverse iterators to do that (linked list iterators
   // can go backwards -- but you have to run them to the end first).
   while (it.hasNext()) {
     theName = it.next();
     if (VersioningProfile.isVersionComponent(theName.component(0))) {
       if (null == latestName) {
         latestName = theName;
         latestTimestamp = VersioningProfile.getVersionComponentAsTimestamp(theName.component(0));
       } else {
         CCNTime thisTimestamp =
             VersioningProfile.getVersionComponentAsTimestamp(theName.component(0));
         if (thisTimestamp.after(latestTimestamp)) {
           latestName = theName;
           latestTimestamp = thisTimestamp;
         }
       }
     }
   }
   return latestName;
 }
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    CCNTestBase.setUpBeforeClass();
    CCNTime version = new CCNTime();
    ContentName stringName = testHelper.getClassChildName(STRING_VALUE_NAME);
    for (int i = 0; i < data.length; ++i) {
      // save multiple versions of the same object.
      data[i] = new CCNStringObject(stringName, "Value " + i, SaveType.REPOSITORY, putHandle);
      Log.info(Log.FAC_TEST, "Saving as version " + version);
      data[i].save(version);
      version.increment(1); // avoid version collisions
    }

    gone =
        new CCNStringObject(
            testHelper.getClassChildName(GONE_VALUE_NAME),
            GONE_VALUE_NAME,
            SaveType.REPOSITORY,
            putHandle);
    gone.saveAsGone();
    TestUtils.checkObject(putHandle, gone);

    bigData = testHelper.getClassChildName(BIG_VALUE_NAME);

    bigDataContent = new byte[bigDataLength];
    Random rand = new Random();
    rand.nextBytes(bigDataContent);
    bigValueDigest = CCNDigestHelper.digest(bigDataContent);

    // generate some segmented data
    CCNRepositoryWriter writer = new CCNRepositoryWriter(putHandle);
    writer.newVersion(bigData, bigDataContent);
  }
예제 #3
0
 /**
  * Wait for new children to arrive.
  *
  * @param timeout Maximum time to wait for new data.
  * @return a boolean value that indicates whether new data was found.
  *     <p>Deprecated - see #getNewData(long)
  */
 @Deprecated
 public boolean waitForNewChildren(long timeout) {
   boolean foundNewData = false;
   synchronized (_childLock) {
     CCNTime lastUpdate = _lastUpdate;
     long timeRemaining = timeout;
     long startTime = System.currentTimeMillis();
     while (((null == _lastUpdate) || ((null != lastUpdate) && !_lastUpdate.after(lastUpdate)))
         && ((timeout == SystemConfiguration.NO_TIMEOUT) || (timeRemaining > 0))) {
       try {
         _childLock.wait(
             (timeout != SystemConfiguration.NO_TIMEOUT)
                 ? Math.min(timeRemaining, SystemConfiguration.CHILD_WAIT_INTERVAL)
                 : SystemConfiguration.CHILD_WAIT_INTERVAL);
         if (timeout != SystemConfiguration.NO_TIMEOUT) {
           timeRemaining = timeout - (System.currentTimeMillis() - startTime);
         }
       } catch (InterruptedException e) {
       }
       if (Log.isLoggable(Level.INFO)) {
         Log.info(
             "Waiting for new data on prefix: {0}, updated {1}, our update {2}, have {3} children {4} new.",
             _namePrefix,
             _lastUpdate,
             lastUpdate,
             ((null == _children) ? 0 : _children.size()),
             ((null == _newChildren) ? 0 : _newChildren.size()));
       }
     }
     if ((null != _lastUpdate) && ((null == lastUpdate) || (_lastUpdate.after(lastUpdate))))
       foundNewData = true;
   }
   return foundNewData;
 }
예제 #4
0
 public void testDateTime(CCNTime testDateTime) {
   String strDateTime = TextXMLCodec.formatDateTime(testDateTime);
   System.out.println("DateTime: " + testDateTime + " XML version: " + strDateTime);
   CCNTime parsedDateTime = null;
   try {
     parsedDateTime = TextXMLCodec.parseDateTime(strDateTime);
   } catch (ParseException e) {
     System.out.println("Exception parsing date time: " + e.getMessage());
     e.printStackTrace();
     Assert.fail("Failed to parse date time: " + strDateTime);
   }
   System.out.println("Parsed version: " + parsedDateTime);
   if (!parsedDateTime.equals(testDateTime)) {
     System.out.println(
         "Time : "
             + parsedDateTime
             + "(long: "
             + parsedDateTime.getTime()
             + ") does not equal "
             + testDateTime
             + "(long: "
             + testDateTime.getTime()
             + ")");
   }
   Assert.assertTrue(parsedDateTime.equals(testDateTime));
 }
예제 #5
0
  /**
   * Test method for
   * org.ccnx.ccn.profiles.VersioningProfile#addVersion(org.ccnx.ccn.protocol.ContentName,
   * java.sql.Timestamp).
   */
  @Test
  public void testVersionNameContentNameTimestamp() {
    /* try with length 2 contentname */
    CCNTime ts = new CCNTime(1000);
    ts.setNanos(15722656);

    ContentName name = VersioningProfile.addVersion(abName, ts);
    if (!name.equals(abvName)) fail("timestamp encode version failed");
  }
예제 #6
0
  @Test
  public void testParseDateTime() {
    Log.info(Log.FAC_TEST, "Starting testParseDateTime");

    CCNTime now = CCNTime.now();
    testDateTime(now);

    now.setNanos(384);
    testDateTime(now);

    now.setNanos(1105384);
    testDateTime(now);
    now.setNanos(550105384);
    testDateTime(now);
    now.setNanos(550000000);

    testDateTime(now);
    now.setNanos(953405384);
    testDateTime(now);

    now.setNanos(110672800);
    testDateTime(now);

    Log.info(Log.FAC_TEST, "Completed testParseDateTime");
  }
예제 #7
0
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    name = new ContentName(baseName, subName, document1);
    name2 = new ContentName(baseName, subName, document2);
    name3 = new ContentName(baseName, subName, document3);
    name4 = ContentName.fromURI("/parc/home/briggs/collaborators.txt");
    ns = new ContentName[] {name, name2, name3, name4};
    Arrays.fill(contenthash1, (byte) 2);
    Arrays.fill(contenthash2, (byte) 4);
    Arrays.fill(publisherid1, (byte) 6);
    Arrays.fill(publisherid2, (byte) 3);

    pubID1 = new PublisherID(publisherid1, PublisherType.KEY);
    pubID2 = new PublisherID(publisherid2, PublisherType.ISSUER_KEY);

    las[0] = new LinkAuthenticator(pubID1);
    las[1] = null;
    las[2] = new LinkAuthenticator(pubID2, null, null, SignedInfo.ContentType.DATA, contenthash1);
    las[3] = new LinkAuthenticator(pubID1, null, CCNTime.now(), null, contenthash1);

    lrs = new Link[4];
    for (int i = 0; i < lrs.length; ++i) {
      lrs[i] = new Link(ns[i], las[i]);
    }
  }
예제 #8
0
  /**
   * Wait for new children to arrive.
   *
   * @param timeout Maximum time to wait for new data.
   * @param threadPoolContext Are we waiting in threadPoolContext (i.e. other threads can grab
   *     children first) See #getNewData(boolean, long).
   * @return a boolean value that indicates whether new data was found.
   */
  public boolean waitForNewChildren(boolean threadPoolContext, long timeout) {
    boolean foundNewData = false;

    Long id = threadPoolContext ? 0 : Thread.currentThread().getId();
    _newChildrenByThread.put(id, new NewChildrenByThread(id));
    synchronized (_childLock) {
      CCNTime lastUpdate = _lastUpdate;
      long timeRemaining = timeout;
      long startTime = System.currentTimeMillis();
      while (((null == _lastUpdate) || ((null != lastUpdate) && !_lastUpdate.after(lastUpdate)))
          && ((timeout == SystemConfiguration.NO_TIMEOUT) || (timeRemaining > 0))) {
        if (_shutdown) break;
        try {
          _childLock.wait(
              (timeout != SystemConfiguration.NO_TIMEOUT)
                  ? Math.min(timeRemaining, SystemConfiguration.CHILD_WAIT_INTERVAL)
                  : SystemConfiguration.CHILD_WAIT_INTERVAL);
          if (timeout != SystemConfiguration.NO_TIMEOUT) {
            timeRemaining = timeout - (System.currentTimeMillis() - startTime);
          }
        } catch (InterruptedException e) {
        }
        if (Log.isLoggable(Log.FAC_SEARCH, Level.INFO)) {
          SortedSet<ContentName> newChildren = _newChildrenByThread.get(id)._newChildren;
          Log.info(
              Log.FAC_SEARCH,
              "Waiting for new data on prefix: {0}, updated {1}, our update {2}, have {3} children {4} new.",
              _namePrefix,
              _lastUpdate,
              lastUpdate,
              ((null == _children) ? 0 : _children.size()),
              ((null == newChildren) ? 0 : newChildren.size()));
        }
      }
      if ((null != _lastUpdate) && ((null == lastUpdate) || (_lastUpdate.after(lastUpdate))))
        foundNewData = true;
    }
    return foundNewData;
  }
예제 #9
0
  @Test
  public void testPaddedVersions() throws Exception {
    ContentName name = ContentName.fromNative("/testme");
    long v0 = 0x80FFFF;
    byte[] b0 = {VersioningProfile.VERSION_MARKER, (byte) 0x80, (byte) 0xFF, (byte) 0xFF};

    ContentName vn0 = VersioningProfile.addVersion(name, v0);
    byte[] x0 = VersioningProfile.getLastVersionComponent(vn0);
    System.out.println("From long name   : " + vn0.toString());
    Assert.assertTrue(Arrays.areEqual(b0, x0));

    // now do it as ccntime
    CCNTime t0 = CCNTime.fromBinaryTimeAsLong(v0);
    vn0 = VersioningProfile.addVersion(name, t0);
    x0 = VersioningProfile.getLastVersionComponent(vn0);
    System.out.println("From ccntime name: " + vn0.toString());
    Assert.assertTrue(Arrays.areEqual(b0, x0));
  }
예제 #10
0
 /** Create a VersionNUmber with the current timestamp from the system clock. */
 public VersionNumber() {
   _version = CCNTime.now();
   _versionComponent = VersioningProfile.timeToVersionComponent(_version);
   _binaryTime = _version.toBinaryTimeAsLong();
 }
예제 #11
0
 public static VersionNumber now() {
   return new VersionNumber(CCNTime.now());
 }
예제 #12
0
 /**
  * Add (or subtract if negative) #arg from the current version and return a new object. The caller
  * should understand that the value is used as an unsigned long.
  *
  * @return
  */
 public VersionNumber addAndReturn(long count) {
   long binaryTime = _version.toBinaryTimeAsLong();
   binaryTime += count;
   return new VersionNumber(CCNTime.fromBinaryTimeAsLong(binaryTime));
 }