Пример #1
0
  @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");
  }
  @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");
  }