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

    SaveType saveType = SaveType.REPOSITORY;
    NDNHandle writeHandle = NDNHandle.open();
    NDNHandle readHandle = NDNHandle.open();

    try {
      ContentName testName =
          new ContentName(testHelper.getTestNamespace("testUpdateListener"), stringObjName);

      NDNStringObject writeObject =
          new NDNStringObject(testName, "Something to listen to.", saveType, writeHandle);
      writeObject.save();

      CounterListener ourListener = new CounterListener();
      NDNStringObject readObject = new NDNStringObject(testName, null, null, readHandle);
      readObject.addListener(ourListener);
      boolean result = readObject.update();

      Assert.assertTrue(result);
      Assert.assertTrue(ourListener.getCounter() == 1);

      readObject.updateInBackground();

      writeObject.save("New stuff! New stuff!");
      synchronized (readObject) {
        while (ourListener.getCounter() == 1) readObject.wait();
      }
      // For some reason, we're getting two updates on our updateInBackground...
      Assert.assertTrue(ourListener.getCounter() > 1);
    } finally {
      writeHandle.close();
      readHandle.close();
      KeyManager.closeDefaultKeyManager();
    }

    Log.info(Log.FAC_TEST, "Completed testUpdateListener");
  }
  @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");
  }