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