@Test
  public void testLocalCopyListener() throws Exception {
    Log.info(Log.FAC_TEST, "Starting testLocalCopyListener");

    NDNHandle rhandle = NDNHandle.open();
    try {
      // The local copy wrapper API isn't applicable in very many situations. Try this instead.
      ContentName testName =
          new ContentName(testHelper.getTestNamespace("testLocalCopyListener"), collectionObjName);

      LocalCopyListener copyListener = new LocalCopyListener();

      // Would like to test functionality that arranges for existing version to get written
      // to the repo, but can't do that without a flosser or using a flow server.
      NDNStringObject so = new NDNStringObject(testName, rhandle);
      so.addListener(copyListener);

      Assert.assertFalse(so.available());

      class Record {
        boolean callback = false;
      }
      Record record = new Record();

      class Listener implements UpdateListener {
        Record _rec;

        public Listener(Record r) {
          _rec = r;
        }

        public void newVersionAvailable(NDNNetworkObject<?> newVersion, boolean wasSave) {
          synchronized (_rec) {
            _rec.callback = true;
            _rec.notifyAll();
          }
        }
      };

      // ask for it in background
      so.updateInBackground(false, new Listener(record));

      NDNHandle thandle = NDNHandle.open();
      try {
        NDNStringObject sowrite =
            new NDNStringObject(testName, "Now we write", SaveType.RAW, thandle);
        setupNamespace(testName);
        saveAndLog("Delayed write", sowrite, null, "Now we write");
        TestUtils.checkObject(thandle, sowrite);
        so.waitForData();
        Assert.assertTrue(so.available());
        Assert.assertEquals(so.string(), sowrite.string());
        Assert.assertEquals(so.getVersionedName(), sowrite.getVersionedName());

        new Waiter(UPDATE_TIMEOUT) {
          @Override
          protected boolean check(Object o, Object check) throws Exception {
            return ((Record) o).callback;
          }
        }.wait(record, record);
        Assert.assertEquals(true, record.callback);
        if (!RepositoryControl.localRepoSync(rhandle, so)) {
          Thread.sleep(SystemConfiguration.MEDIUM_TIMEOUT);
          // Should be in the repo by now
          Assert.assertTrue(RepositoryControl.localRepoSync(rhandle, so));
        }
      } finally {
        thandle.close();
      }
    } finally {
      rhandle.close();
      KeyManager.closeDefaultKeyManager();
    }

    Log.info(Log.FAC_TEST, "Completed testLocalCopyListener");
  }
  @Test
  public void testLocalCopyWrapper() throws Exception {
    Log.info(Log.FAC_TEST, "Starting testLocalCopyWrapper");

    NDNHandle thandle = NDNHandle.open();
    NDNHandle rhandle = NDNHandle.open();

    try {
      ContentName testName =
          new ContentName(testHelper.getTestNamespace("testLocalCopyWrapper"), collectionObjName);
      NDNStringObject so = new NDNStringObject(testName, rhandle);
      LocalCopyWrapper wo = new LocalCopyWrapper(so);
      Assert.assertFalse(wo.available());
      class Record {
        boolean callback = false;
      }
      Record record = new Record();

      class Listener implements UpdateListener {
        Record _rec;

        public Listener(Record r) {
          _rec = r;
        }

        public void newVersionAvailable(NDNNetworkObject<?> newVersion, boolean wasSave) {
          synchronized (_rec) {
            _rec.callback = true;
            _rec.notifyAll();
          }
        }
      };

      // ask for it in background
      wo.updateInBackground(false, new Listener(record));

      NDNStringObject sowrite =
          new NDNStringObject(testName, "Now we write", SaveType.RAW, thandle);
      setupNamespace(testName);
      saveAndLog("Delayed write", sowrite, null, "Now we write");
      TestUtils.checkObject(thandle, sowrite);
      wo.waitForData();
      Assert.assertTrue(wo.available());
      Assert.assertEquals(((NDNStringObject) wo.object()).string(), sowrite.string());
      Assert.assertEquals(wo.getVersionedName(), sowrite.getVersionedName());

      new Waiter(UPDATE_TIMEOUT) {
        @Override
        protected boolean check(Object o, Object check) throws Exception {
          return ((Record) o).callback;
        }
      }.wait(record, record);
      Assert.assertEquals(true, record.callback);

      if (!RepositoryControl.localRepoSync(rhandle, so)) {
        Thread.sleep(SystemConfiguration.MEDIUM_TIMEOUT);
        // Should be in the repo by now
        Assert.assertTrue(RepositoryControl.localRepoSync(rhandle, so));
      }
    } finally {
      thandle.close();
      rhandle.close();
      KeyManager.closeDefaultKeyManager();
    }

    Log.info(Log.FAC_TEST, "Completed testLocalCopyWrapper");
  }