@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); }
@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"); }