@BeforeClass public static void setUpBeforeClass() throws Exception { Log.info( Log.FAC_TEST, "Setting up NDNNetworkObjectTestRepo, prefix {0}", testHelper.getClassNamespace()); NDNHandle myhandle = NDNHandle.open(); try { ns = new ContentName[NUM_LINKS]; for (int i = 0; i < NUM_LINKS; ++i) { ns[i] = new ContentName(testHelper.getClassNamespace(), "Links", prefix + Integer.toString(i)); } Arrays.fill(publisherid1, (byte) 6); Arrays.fill(publisherid2, (byte) 3); pubID1 = new PublisherID(publisherid1, PublisherType.KEY); pubID2 = new PublisherID(publisherid2, PublisherType.ISSUER_KEY); las[0] = new LinkAuthenticator(pubID1); las[1] = null; las[2] = new LinkAuthenticator(pubID2, null, null, SignedInfo.ContentType.DATA, contenthash1); las[3] = new LinkAuthenticator(pubID1, null, NDNTime.now(), null, contenthash1); for (int j = 4; j < NUM_LINKS; ++j) { las[j] = new LinkAuthenticator(pubID2, null, NDNTime.now(), null, null); } lrs = new Link[NUM_LINKS]; for (int i = 0; i < lrs.length; ++i) { lrs[i] = new Link(ns[i], las[i]); } empty = new Collection(); small1 = new Collection(); small2 = new Collection(); for (int i = 0; i < 5; ++i) { small1.add(lrs[i]); small2.add(lrs[i + 5]); } big = new Collection(); for (int i = 0; i < NUM_LINKS; ++i) { big.add(lrs[i]); } Log.info( Log.FAC_TEST, "Finihed setting up NDNNetworkObjectTestRepo, prefix {0}", testHelper.getClassNamespace()); } finally { myhandle.close(); KeyManager.closeDefaultKeyManager(); } }
@Test public void testSaveAsGone() throws Exception { Log.info(Log.FAC_TEST, "Starting testSaveAsGone"); NDNHandle thandle = NDNHandle.open(); NDNHandle rhandle = NDNHandle.open(); NDNHandle shandle = NDNHandle.open(); try { ContentName testName = new ContentName(testHelper.getTestNamespace("testSaveAsGone"), collectionObjName); CollectionObject c0 = new CollectionObject(testName, empty, SaveType.REPOSITORY, thandle); setupNamespace(testName); NDNTime t0 = saveAsGoneAndLog("Gone", c0); Assert.assertTrue("Should be gone", c0.isGone()); ContentName goneVersionName = c0.getVersionedName(); NDNTime t1 = saveAndLog("NotGone", c0, null, small1); TestUtils.checkObject(thandle, c0); Assert.assertFalse("Should not be gone", c0.isGone()); Assert.assertTrue(t1.after(t0)); CollectionObject c1 = new CollectionObject(testName, rhandle); NDNTime t2 = waitForDataAndLog(testName.toString(), c1); Assert.assertFalse("Read back should not be gone", c1.isGone()); Assert.assertEquals(t2, t1); NDNTime t3 = updateAndLog(goneVersionName.toString(), c1, goneVersionName); Assert.assertTrue(VersioningProfile.isVersionOf(c1.getVersionedName(), testName)); Assert.assertEquals(t3, t0); Assert.assertTrue("Read back should be gone.", c1.isGone()); t0 = saveAsGoneAndLog("GoneAgain", c0); Assert.assertTrue("Should be gone", c0.isGone()); CollectionObject c2 = new CollectionObject(testName, shandle); NDNTime t4 = waitForDataAndLog(testName.toString(), c2); Assert.assertTrue( "Read back of " + c0.getVersionedName() + " should be gone, got " + c2.getVersionedName(), c2.isGone()); Assert.assertEquals(t4, t0); } finally { thandle.close(); rhandle.close(); shandle.close(); KeyManager.closeDefaultKeyManager(); } Log.info(Log.FAC_TEST, "Completed testSaveAsGone"); }
@Test public void testUpdateOtherName() throws Exception { Log.info(Log.FAC_TEST, "Starting testUpdateOtherName"); NDNHandle thandle = NDNHandle.open(); NDNHandle rhandle = NDNHandle.open(); try { ContentName testName = new ContentName( testHelper.getTestNamespace("testUpdateOtherName"), collectionObjName, "name1"); ContentName testName2 = new ContentName( testHelper.getTestNamespace("testUpdateOtherName"), collectionObjName, "name2"); CollectionObject c0 = new CollectionObject(testName, empty, SaveType.REPOSITORY, rhandle); setupNamespace(testName); NDNTime t0 = saveAndLog("Empty", c0, null, empty); TestUtils.checkObject(rhandle, c0); CollectionObject c1 = new CollectionObject(testName2, small1, SaveType.REPOSITORY, thandle); // Cheat a little, make this one before the setupNamespace... CollectionObject c2 = new CollectionObject(testName2, small1, SaveType.REPOSITORY, null); setupNamespace(testName2); NDNTime t1 = saveAndLog("Small", c1, null, small1); TestUtils.checkObject(thandle, c1); Assert.assertTrue("First version should come before second", t0.before(t1)); NDNTime t2 = saveAndLog("Small2ndWrite", c2, null, small1); TestUtils.checkObject(c2.getHandle(), c2); Assert.assertTrue("Third version should come after second", t1.before(t2)); Assert.assertTrue(c2.contentEquals(c1)); Assert.assertFalse(c2.equals(c1)); NDNTime t3 = updateAndLog(c0.getVersionedName().toString(), c0, testName2); Assert.assertTrue(VersioningProfile.isVersionOf(c0.getVersionedName(), testName2)); Assert.assertEquals(t3, t2); Assert.assertTrue(c0.contentEquals(c2)); t3 = updateAndLog(c0.getVersionedName().toString(), c0, c1.getVersionedName()); Assert.assertTrue(VersioningProfile.isVersionOf(c0.getVersionedName(), testName2)); Assert.assertEquals(t3, t1); Assert.assertTrue(c0.contentEquals(c1)); } finally { thandle.close(); rhandle.close(); KeyManager.closeDefaultKeyManager(); } Log.info(Log.FAC_TEST, "Completed testUpdateOtherName"); }
@Test public void testSaveToVersion() throws Exception { Log.info(Log.FAC_TEST, "Starting testSaveToVersion"); // Testing problem of disappearing versions, inability to get latest. Use simpler // object than a collection. NDNHandle lput = NDNHandle.open(); NDNHandle lget = NDNHandle.open(); try { ContentName testName = new ContentName(testHelper.getTestNamespace("testSaveToVersion"), stringObjName); NDNTime desiredVersion = NDNTime.now(); NDNStringObject so = new NDNStringObject(testName, "First value", SaveType.REPOSITORY, lput); setupNamespace(testName); saveAndLog("SpecifiedVersion", so, desiredVersion, "Time: " + desiredVersion); TestUtils.checkObject(lput, so); Assert.assertEquals("Didn't write correct version", desiredVersion, so.getVersion()); NDNStringObject ro = new NDNStringObject(testName, lget); ro.waitForData(); Assert.assertEquals("Didn't read correct version", desiredVersion, ro.getVersion()); ContentName versionName = ro.getVersionedName(); saveAndLog("UpdatedVersion", so, null, "ReplacementData"); TestUtils.checkObject(lput, so); updateAndLog("UpdatedData", ro, null); Assert.assertTrue( "New version " + so.getVersion() + " should be later than old version " + desiredVersion, (desiredVersion.before(so.getVersion()))); Assert.assertEquals("Didn't read correct version", so.getVersion(), ro.getVersion()); NDNStringObject ro2 = new NDNStringObject(versionName, null); ro2.waitForData(); Assert.assertEquals("Didn't read correct version", desiredVersion, ro2.getVersion()); } finally { lput.close(); lget.close(); KeyManager.closeDefaultKeyManager(); } Log.info(Log.FAC_TEST, "Completed testSaveToVersion"); }
@Test public void testVersioning() throws Exception { Log.info(Log.FAC_TEST, "Starting testVersioning"); // Testing problem of disappearing versions, inability to get latest. Use simpler // object than a collection. NDNHandle lput = NDNHandle.open(); NDNHandle lget = NDNHandle.open(); try { ContentName testName = new ContentName(testHelper.getTestNamespace("testVersioning"), stringObjName); NDNStringObject so = new NDNStringObject(testName, "First value", SaveType.REPOSITORY, lput); setupNamespace(testName); NDNStringObject ro = null; NDNStringObject ro2 = null; NDNStringObject ro3, ro4; // make each time, to get a new handle. NDNTime soTime, srTime, sr2Time, sr3Time, sr4Time, so2Time; for (int i = 0; i < numbers.length; ++i) { soTime = saveAndLog(numbers[i], so, null, numbers[i]); TestUtils.checkObject(lput, so); ro = new NDNStringObject(testName, lget); srTime = waitForDataAndLog(numbers[i], ro); ro2 = new NDNStringObject(testName, null); sr2Time = waitForDataAndLog(numbers[i], ro2); ro3 = new NDNStringObject(ro.getVersionedName(), null); // read specific version sr3Time = waitForDataAndLog("UpdateToROVersion", ro3); // Save a new version and pull old so2Time = saveAndLog(numbers[i] + "-Update", so, null, numbers[i] + "-Update"); TestUtils.checkObject(lput, so); ro4 = new NDNStringObject(ro.getVersionedName(), null); // read specific version sr4Time = waitForDataAndLog("UpdateAnotherToROVersion", ro4); Log.info( Log.FAC_TEST, "Update " + i + ": Times: " + soTime + " " + srTime + " " + sr2Time + " " + sr3Time + " different: " + so2Time); Assert.assertEquals("SaveTime doesn't match first read", soTime, srTime); Assert.assertEquals("SaveTime doesn't match second read", soTime, sr2Time); Assert.assertEquals("SaveTime doesn't match specific version read", soTime, sr3Time); Assert.assertFalse("UpdateTime isn't newer than read time", soTime.equals(so2Time)); Assert.assertEquals("SaveTime doesn't match specific version read", soTime, sr4Time); } } finally { lput.close(); lget.close(); KeyManager.closeDefaultKeyManager(); } Log.info(Log.FAC_TEST, "Completed testVersioning"); }