Exemple #1
0
    def test_request_object_backup(self):
        cache = Cache(100)
        cache.set_fetcher(self.Fetcher)
        cache.request_object(1, "fresh", self.object_handler,
                self.error_handler, self.timeout_handler)
        self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
        sleep(0.05)
        self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
        sleep(0.3)
        self.failUnlessEqual(self.event,("success", 1, "value1", "new"))
        self.event = None
        self.force_error = True
        cache.request_object(1, "new", self.object_handler,
                self.error_handler, self.timeout_handler)
        self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
        sleep(0.05)
        self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
        sleep(0.3)
        self.failUnlessEqual(self.event,("error", 1, "Forced error"))
        self.event = None

        self.force_error = True
        cache.request_object(1, "new", self.object_handler,
                self.error_handler, self.timeout_handler,
                backup_state = "stale")
        self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
        sleep(0.05)
        self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
        sleep(0.3)
        self.failUnlessEqual(self.event,("success", 1, "value1", "stale"))
Exemple #2
0
 def test_request_object_success(self):
     cache = Cache(100)
     cache.set_fetcher(self.Fetcher)
     cache.request_object(1, "fresh", self.object_handler,
             self.error_handler, self.timeout_handler)
     self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
     sleep(0.05)
     self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
     sleep(0.3)
     self.failUnlessEqual(self.event,("success", 1, "value1", "new"))
     self.event = None
     cache.request_object(1, "fresh", self.object_handler,
             self.error_handler, self.timeout_handler)
     self.failUnlessEqual(self.event,("success", 1, "value1", "fresh"))
     self.event = None
     cache.request_object(2, "fresh", self.object_handler,
             self.error_handler, self.timeout_handler)
     self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
     sleep(0.05)
     cache.tick()
     self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
     sleep(0.3)
     cache.tick()
     self.failUnlessEqual(self.event,("success", 2, "value2", "new"))
     self.event = None
     cache.request_object(2, "fresh", self.object_handler,
             self.error_handler, self.timeout_handler)
     self.failUnlessEqual(self.event,("success", 2, "value2", "fresh"))
     cache.tick()
     self.event = None
     cache.request_object(1, "fresh", self.object_handler,
             self.error_handler, self.timeout_handler)
     self.failUnlessEqual(self.event,("success", 1, "value1", "fresh"))
Exemple #3
0
 def test_request_object_failure(self):
     cache = Cache(100)
     cache.set_fetcher(self.Fetcher)
     cache.request_object(-1, "fresh", self.object_handler,
             self.error_handler, self.timeout_handler)
     self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
     sleep(0.05)
     cache.tick()
     self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
     sleep(0.3)
     cache.tick()
     self.failUnlessEqual(self.event,("error", -1, "Negative address"))
Exemple #4
0
 def test_request_object_timeout(self):
     cache = Cache(100)
     cache.set_fetcher(self.Fetcher)
     cache.request_object(1, "fresh", self.object_handler,
             self.error_handler, self.timeout_handler,
             timeout=timedelta(seconds=0.1))
     self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
     sleep(0.05)
     cache.tick()
     self.failUnlessEqual(self.event,None,"Early event: %r" % (self.event,))
     sleep(0.05)
     cache.tick()
     sleep(0.05)
     cache.tick()
     sleep(0.05)
     cache.tick()
     sleep(0.3)
     cache.tick()
     self.failUnlessEqual(self.event,("timeout", 1))