tests: Fix issue with UnitTestClock-based event scheduling (extra sleep required)

Change-Id: I77f24f630697b6e41b3d935f0f1416e806516412
Refs: #2152
diff --git a/src/security/certificate-cache-ttl.hpp b/src/security/certificate-cache-ttl.hpp
index 650a9e7..55cbc5a 100644
--- a/src/security/certificate-cache-ttl.hpp
+++ b/src/security/certificate-cache-ttl.hpp
@@ -30,42 +30,42 @@
 
 namespace ndn {
 
+/**
+ * @brief Cache of validated certificates with freshness-based eviction policy
+ *
+ * Validated certificates will stay in cache for the duration of their freshness period.
+ * The lifetime of the certificate in cache can be extended by "re-inserting" it in the cache.
+ */
 class CertificateCacheTtl : public CertificateCache
 {
 public:
   explicit
   CertificateCacheTtl(boost::asio::io_service& io,
-                      const time::seconds& defaultTtl = time::seconds(3600))
-    : m_defaultTtl(defaultTtl)
-    , m_scheduler(io)
-  {
-  }
+                      const time::seconds& defaultTtl = time::seconds(3600));
 
   virtual
-  ~CertificateCacheTtl()
-  {
-  }
+  ~CertificateCacheTtl();
 
-  virtual inline void
+  virtual void
   insertCertificate(shared_ptr<const IdentityCertificate> certificate);
 
-  virtual inline shared_ptr<const IdentityCertificate>
+  virtual shared_ptr<const IdentityCertificate>
   getCertificate(const Name& certificateNameWithoutVersion);
 
-  virtual inline void
+  virtual void
   reset();
 
-  virtual inline size_t
+  virtual size_t
   getSize();
 
 private:
-  inline void
+  void
   insert(shared_ptr<const IdentityCertificate> certificate);
 
-  inline void
+  void
   remove(const Name& certificateName);
 
-  inline void
+  void
   removeAll();
 
 protected:
@@ -73,77 +73,10 @@
 
   time::seconds m_defaultTtl;
   Cache m_cache;
+  boost::asio::io_service& m_io;
   Scheduler m_scheduler;
 };
 
-inline void
-CertificateCacheTtl::insertCertificate(shared_ptr<const IdentityCertificate> certificate)
-{
-  m_scheduler.scheduleEvent(time::seconds(0),
-                            bind(&CertificateCacheTtl::insert, this, certificate));
-}
-
-inline shared_ptr<const IdentityCertificate>
-CertificateCacheTtl::getCertificate(const Name& certificateName)
-{
-  Cache::iterator it = m_cache.find(certificateName);
-  if (it != m_cache.end())
-    return it->second.first;
-  else
-    return shared_ptr<IdentityCertificate>();
-}
-
-inline void
-CertificateCacheTtl::reset()
-{
-  m_scheduler.scheduleEvent(time::seconds(0),
-                            bind(&CertificateCacheTtl::removeAll, this));
-}
-
-inline size_t
-CertificateCacheTtl::getSize()
-{
-  return m_cache.size();
-}
-
-inline void
-CertificateCacheTtl::insert(shared_ptr<const IdentityCertificate> certificate)
-{
-  time::milliseconds expire = (certificate->getFreshnessPeriod() >= time::seconds::zero() ?
-                               certificate->getFreshnessPeriod() : m_defaultTtl);
-
-  Name index = certificate->getName().getPrefix(-1);
-
-  Cache::iterator it = m_cache.find(index);
-  if (it != m_cache.end())
-    m_scheduler.cancelEvent(it->second.second);
-
-  EventId eventId = m_scheduler.scheduleEvent(expire,
-                                              bind(&CertificateCacheTtl::remove,
-                                                   this, certificate->getName()));
-
-  m_cache[index] = std::make_pair(certificate, eventId);
-}
-
-inline void
-CertificateCacheTtl::remove(const Name& certificateName)
-{
-  Name name = certificateName.getPrefix(-1);
-  Cache::iterator it = m_cache.find(name);
-  if (it != m_cache.end())
-    m_cache.erase(it);
-}
-
-inline void
-CertificateCacheTtl::removeAll()
-{
-  for(Cache::iterator it = m_cache.begin(); it != m_cache.end(); it++)
-    m_scheduler.cancelEvent(it->second.second);
-
-  m_cache.clear();
-}
-
-
 } // namespace ndn
 
-#endif //NDN_SECURITY_CERTIFICATE_CACHE_TTL_HPP
+#endif // NDN_SECURITY_CERTIFICATE_CACHE_TTL_HPP