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