@Test public void testLinkToUnversioned() throws Exception { Log.info(Log.FAC_TEST, "Starting testLinkToUnversioned"); // test dereferencing link to unversioned data. CCNRepositoryWriter writer = new CCNRepositoryWriter(putHandle); ContentName unversionedDataName = testHelper.getTestChildName("testLinkToUnversioned", "UnversionedBigData"); // generate some segmented data; doesn't version the name writer.newVersion(unversionedDataName, bigDataContent); Link uvBigDataLink = new Link( unversionedDataName, "big", new LinkAuthenticator(new PublisherID(putHandle.keyManager().getDefaultKeyID()))); ContentObject bigDataTarget = uvBigDataLink.dereference(SystemConfiguration.SETTABLE_SHORT_TIMEOUT, getHandle); Log.info( Log.FAC_TEST, "BigData: Dereferenced link " + uvBigDataLink + ", retrieved content " + ((null == bigDataTarget) ? "null" : bigDataTarget.name())); Assert.assertNotNull(bigDataTarget); Assert.assertTrue(uvBigDataLink.targetName().isPrefixOf(bigDataTarget.name())); Assert.assertTrue(SegmentationProfile.isFirstSegment(bigDataTarget.name())); Log.info(Log.FAC_TEST, "Completed testLinkToUnversioned"); }
@Test public void testMissingTarget() throws Exception { Log.info(Log.FAC_TEST, "Starting testMissingTarget"); Link linkToNowhere = new Link(testHelper.getTestChildName("testMissingTarget", "linkToNowhere")); ContentObject nothing = linkToNowhere.dereference(SystemConfiguration.SHORT_TIMEOUT, getHandle); Assert.assertNull(nothing); Log.info(Log.FAC_TEST, "Completed testMissingTarget"); }
@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 testAutomatedDereferenceForStreams() throws Exception { Log.info(Log.FAC_TEST, "Starting testAutomatedDereferenceForStreams"); Link bigDataLink = new Link( bigData, "big", new LinkAuthenticator(new PublisherID(putHandle.keyManager().getDefaultKeyID()))); LinkObject bigDataLinkObject = new LinkObject( testHelper.getTestChildName("testAutomatedDereferenceForStreams", "bigDataLink"), bigDataLink, SaveType.REPOSITORY, putHandle); bigDataLinkObject.save(); TestUtils.checkObject(putHandle, bigDataLinkObject); Link twoHopLink = new Link(bigDataLinkObject.getBaseName()); LinkObject twoHopLinkObject = new LinkObject( testHelper.getTestChildName("testAutomatedDereferenceForStreams", "twoHopLink"), twoHopLink, SaveType.REPOSITORY, putHandle); twoHopLinkObject.save(); TestUtils.checkObject(putHandle, twoHopLinkObject); CCNReader reader = new CCNReader(putHandle); byte[] bigDataReadback = reader.getVersionedData( bigDataLinkObject.getVersionedName(), null, SystemConfiguration.getDefaultTimeout()); byte[] bdrdigest = CCNDigestHelper.digest(bigDataReadback); Log.info( Log.FAC_TEST, "Read back big data via link, got " + bigDataReadback.length + " bytes of an expected " + bigDataLength + ", digest match? " + (0 == DataUtils.compare(bdrdigest, bigValueDigest))); Assert.assertEquals(bigDataLength, bigDataReadback.length); Assert.assertArrayEquals(bdrdigest, bigValueDigest); byte[] bigDataReadback2 = reader.getVersionedData( twoHopLinkObject.getBaseName(), null, SystemConfiguration.getDefaultTimeout()); byte[] bdr2digest = CCNDigestHelper.digest(bigDataReadback); Log.info( Log.FAC_TEST, "Read back big data via two links, got " + bigDataReadback2.length + " bytes of an expected " + bigDataLength + ", digest match? " + (0 == DataUtils.compare(bdr2digest, bigValueDigest))); Assert.assertEquals(bigDataLength, bigDataReadback2.length); Assert.assertArrayEquals(bdr2digest, bigValueDigest); Log.info(Log.FAC_TEST, "Completed testAutomatedDereferenceForStreams"); }