@Test
  public void testPathfinder() throws Exception {
    Log.info(Log.FAC_TEST, "Starting testPathfinder");

    // Make the content
    ContentName testRoot = testHelper.getTestNamespace("testPathfinder");
    ContentName startingPoint =
        new ContentName(testRoot, "This", "is", "a", "longer", "path", "than", "necessary.");

    CCNStringObject targetObject =
        new CCNStringObject(
            new ContentName(startingPoint.parent().parent().parent(), TARGET_POSTFIX_NAME),
            "The target!",
            SaveType.REPOSITORY,
            writeHandle);
    targetObject.save();

    Pathfinder finder =
        new Pathfinder(
            startingPoint,
            null,
            TARGET_POSTFIX_NAME,
            true,
            false,
            SystemConfiguration.SHORT_TIMEOUT,
            null,
            readHandle);
    SearchResults results = finder.waitForResults();
    Assert.assertNotNull(results.getResult());

    Log.info(Log.FAC_TEST, "Completed testPathfinder");
  }
  @Test
  public void testLinkQueue() throws Exception {
    Log.info(Log.FAC_TEST, "Started testLinkQueue");

    String prefix = String.format("/repotest/test_%016X", rnd.nextLong());
    String queuenamestring = prefix + "/queue";
    String objnamestring = prefix + "/obj";
    ContentName queuename = ContentName.fromNative(queuenamestring);
    ContentName objname = ContentName.fromNative(objnamestring);
    int objsize = 1024 * 600;
    CCNHandle recvhandle = CCNHandle.getHandle();
    CCNHandle sendhandle = CCNHandle.open(recvhandle.keyManager());

    char[] buf = new char[objsize];
    Arrays.fill(buf, 'x');
    String objfill = String.valueOf(buf);

    VersioningInterest vi = new VersioningInterest(recvhandle);
    TestListener listener = new TestListener();
    vi.expressInterest(queuename, listener);

    Thread.sleep(1000);

    CCNStringObject so =
        new CCNStringObject(objname, objfill, SaveType.LOCALREPOSITORY, sendhandle);
    so.save();
    so.close();

    Link link = new Link(so.getVersionedName());
    LinkObject lo = new LinkObject(queuename, link, SaveType.LOCALREPOSITORY, sendhandle);
    lo.save();
    lo.close();

    sendhandle.close();

    // now see if we got it in the TestListener

    Assert.assertTrue(listener.cl.waitForValue(1, 60000));

    ReceivedData rd = listener.received.get(0);

    ContentObject co = rd.object;

    CCNStringObject so2 = new CCNStringObject(co.name(), recvhandle);

    Assert.assertEquals(so, so2);

    Log.info(Log.FAC_TEST, "Completed testLinkQueue");
  }
  @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);
  }
Beispiel #4
0
  private User getFriendlyName(
      PublisherPublicKeyDigest digest, CCNHandle tempReadHandle, CCNHandle tempWriteHandle)
      throws MalformedContentNameStringException, IOException {
    User userFriendlyName = null;
    if (_userToDigestHash.containsKey(digest)) {
      userFriendlyName = _userToDigestHash.get(digest);
      Log.info("GET digest: " + digest.digest() + " --> " + userFriendlyName.getUserName());
    } else {
      Log.info("We DON'T have an entry in our hash for this " + digest);
    }

    if (userFriendlyName == null) {

      // Its not in the hashMap.. So, try and read the user's
      // friendly name from the ContentName and then add it to
      // the hashMap....
      String userNameStr = _namespaceStr + MEMBER_COMPONENT;
      _userNamespace =
          KeyProfile.keyName(ContentName.fromURI(userNameStr), _readString.getContentPublisher());

      try {
        _readNameString =
            new CCNStringObject(_userNamespace, (String) null, SaveType.RAW, tempReadHandle);
      } catch (Exception e) {
        e.printStackTrace();
      }

      _readNameString.update(WAIT_TIME_FOR_FRIENDLY_NAME);

      if (_readNameString.available()) {

        if (_readString.getContentPublisher().equals(_readNameString.getContentPublisher())) {
          userFriendlyName =
              addNameToHash(_readNameString.getContentPublisher(), _readNameString.string());
        }
      } else {
        userFriendlyName =
            new Speaker(
                "", "", _readString.getContentPublisher().shortFingerprint().substring(0, 8));
      }
    }
    return userFriendlyName;
  }
  @Test
  public void testAutomatedDereferenceForGone() throws Exception {
    Log.info(Log.FAC_TEST, "Starting testAutomatedDereferenceForGone");

    Link versionedLink = new Link(gone.getVersionedName());
    LinkObject versionedLinkObject =
        new LinkObject(
            testHelper.getTestChildName("testAutomatedDereferenceForGone", "versionedLink"),
            versionedLink,
            SaveType.REPOSITORY,
            putHandle);
    versionedLinkObject.save();
    TestUtils.checkObject(putHandle, versionedLinkObject);

    Link unversionedLink = new Link(gone.getBaseName());
    LinkObject unversionedLinkObject =
        new LinkObject(
            testHelper.getTestChildName("testAutomatedDereferenceForGone", "unversionedLink"),
            unversionedLink,
            SaveType.REPOSITORY,
            putHandle);
    unversionedLinkObject.save();
    TestUtils.checkObject(putHandle, unversionedLinkObject);

    Link twoHopLink = new Link(unversionedLinkObject.getBaseName());
    LinkObject twoHopLinkObject =
        new LinkObject(
            testHelper.getTestChildName("testAutomatedDereferenceForGone", "twoHopLink"),
            twoHopLink,
            SaveType.REPOSITORY,
            putHandle);
    twoHopLinkObject.save();
    TestUtils.checkObject(putHandle, twoHopLinkObject);

    // read via the name iself
    CCNStringObject readObjectControl = new CCNStringObject(gone.getBaseName(), null);
    Assert.assertEquals(readObjectControl.getVersionedName(), gone.getVersionedName());
    Assert.assertTrue(readObjectControl.isGone());

    // read via the versioned link.
    CCNStringObject versionedReadObject =
        new CCNStringObject(versionedLinkObject.getBaseName(), getHandle);
    Assert.assertEquals(versionedReadObject.getVersionedName(), gone.getVersionedName());
    Assert.assertTrue(versionedReadObject.isGone());
    Assert.assertNotNull(versionedReadObject.getDereferencedLink());
    Assert.assertEquals(versionedReadObject.getDereferencedLink(), versionedLinkObject);

    // read latest version via the unversioned link
    CCNStringObject unversionedReadObject =
        new CCNStringObject(unversionedLinkObject.getBaseName(), getHandle);
    Assert.assertEquals(unversionedReadObject.getVersionedName(), gone.getVersionedName());
    Assert.assertTrue(unversionedReadObject.isGone());
    Assert.assertNotNull(unversionedReadObject.getDereferencedLink());
    Assert.assertEquals(unversionedReadObject.getDereferencedLink(), unversionedLinkObject);

    // read via the two-hop link
    CCNStringObject twoHopReadObject =
        new CCNStringObject(twoHopLinkObject.getBaseName(), getHandle);
    Assert.assertEquals(twoHopReadObject.getVersionedName(), gone.getVersionedName());
    Assert.assertTrue(twoHopReadObject.isGone());
    Assert.assertNotNull(twoHopReadObject.getDereferencedLink());
    Assert.assertEquals(twoHopReadObject.getDereferencedLink(), unversionedLinkObject);
    Assert.assertNotNull(twoHopReadObject.getDereferencedLink().getDereferencedLink());
    Assert.assertEquals(
        twoHopReadObject.getDereferencedLink().getDereferencedLink(), twoHopLinkObject);

    Log.info(Log.FAC_TEST, "Completed testAutomatedDereferenceForGone");
  }
  @Test
  public void testThumbnails() throws Exception {
    Log.info(Log.FAC_TEST, "Starting testThumbnails");

    byte[] fakeImageData1 = "xxx".getBytes();
    ContentName thumbNailBase =
        new ContentName(testHelper.getTestNamespace("testThumbnails"), "thumbnailBaseFile");
    CCNStringObject cso =
        new CCNStringObject(
            thumbNailBase, "thumbNailBase", CCNFlowControl.SaveType.REPOSITORY, putHandle);
    cso.save();
    cso.close();
    ContentName origVersion =
        SegmentationProfile.segmentRoot(
            VersioningProfile.getLatestVersion(
                    thumbNailBase,
                    cso.getContentPublisher(),
                    SystemConfiguration.LONG_TIMEOUT,
                    putHandle.defaultVerifier(),
                    getHandle)
                .name());
    ContentName thumbName =
        ThumbnailProfile.getLatestVersion(
            thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle);

    Log.info(Log.FAC_TEST, "Check that we can retrieve a simple thumbnail");
    RepositoryFileOutputStream thumbImage1 = new RepositoryFileOutputStream(thumbName, putHandle);
    thumbImage1.write(fakeImageData1, 0, fakeImageData1.length);
    thumbImage1.close();
    ContentName checkThumbName =
        ThumbnailProfile.getLatestVersion(
            thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle);
    checkData(checkThumbName, fakeImageData1);

    Log.info(Log.FAC_TEST, "Check that we can retrieve a second version of a thumbnail");
    byte[] fakeImageData2 = "yyy".getBytes();
    ContentName thumbName2 = VersioningProfile.updateVersion(checkThumbName);
    RepositoryFileOutputStream thumbImage2 = new RepositoryFileOutputStream(thumbName2, putHandle);
    thumbImage2.write(fakeImageData2, 0, fakeImageData2.length);
    thumbImage2.close();

    checkThumbName =
        ThumbnailProfile.getLatestVersion(
            thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle);
    checkData(checkThumbName, fakeImageData2);

    Log.info(
        Log.FAC_TEST,
        "Check that we can retrieve a thumbnail associated with a second version of a file");
    cso =
        new CCNStringObject(
            thumbNailBase, "thumbNailBase", CCNFlowControl.SaveType.REPOSITORY, putHandle);
    cso.save();
    cso.close();
    byte[] fakeImageData3 = "zzz".getBytes();
    thumbName =
        ThumbnailProfile.getLatestVersion(
            thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle);
    RepositoryFileOutputStream thumbImage3 = new RepositoryFileOutputStream(thumbName, putHandle);
    thumbImage3.write(fakeImageData3, 0, fakeImageData3.length);
    thumbImage3.close();

    checkThumbName =
        ThumbnailProfile.getLatestVersion(
            thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle);
    checkData(checkThumbName, fakeImageData3);

    Log.info(
        Log.FAC_TEST,
        "Check that we can retrieve a second thumbnail associated with a second version of a file");
    byte[] fakeImageData4 = "fff".getBytes();
    thumbName2 = VersioningProfile.updateVersion(checkThumbName);
    RepositoryFileOutputStream thumbImage4 = new RepositoryFileOutputStream(thumbName2, putHandle);
    thumbImage4.write(fakeImageData4, 0, fakeImageData4.length);
    thumbImage4.close();

    checkThumbName =
        ThumbnailProfile.getLatestVersion(
            thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle);
    checkData(checkThumbName, fakeImageData4);

    Log.info(
        Log.FAC_TEST,
        "Check that we can retrieve the correct thumbnail associated with an arbitrary version of a file");
    checkThumbName =
        ThumbnailProfile.getLatestVersion(
            origVersion, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle);
    checkData(checkThumbName, fakeImageData2);

    Log.info(Log.FAC_TEST, "Completed testThumbnails");
  }