Exemplo n.º 1
0
    def test_roll_window(self):
        counter = TimeWindow(key='test_key', cycle_time=.01, window=1,
                             roll=True)
        counter.setup(self.redis_conn)
        counter.increment()
        counter.increment()
        counter.increment()
        time.sleep(1.5)
        counter.increment()
        counter.increment()
        counter.stop()

        keys = self.redis_conn.keys('test_key:*')
        keys.sort()
        self.assertEqual(len(keys), 2)
        self.assertEqual(self.redis_conn.zcard(keys[0]), 3)
        self.assertEqual(counter.value(), 2)
        counter.stop()
        self.clean_keys(counter.key)
Exemplo n.º 2
0
    def test_roll_window(self):
        counter = TimeWindow(key='test_key',
                             cycle_time=.01,
                             window=1,
                             roll=True)
        counter.setup(self.redis_conn)
        counter.increment()
        counter.increment()
        counter.increment()
        time.sleep(1.5)
        counter.increment()
        counter.increment()
        counter.stop()

        keys = self.redis_conn.keys('test_key:*')
        keys.sort()
        self.assertEqual(len(keys), 2)
        self.assertEqual(self.redis_conn.zcard(keys[0]), 3)
        self.assertEqual(counter.value(), 2)
        counter.stop()
        self.clean_keys(counter.key)
Exemplo n.º 3
0
    def test_window(self):
        counter = TimeWindow(key='test_key', cycle_time=.1, window=1)
        counter.setup(self.redis_conn)
        counter.increment()
        counter.increment()
        counter.increment()
        time.sleep(1.1)
        counter.increment()
        counter.stop()
        self.assertEqual(counter.value(), 3)

        self.clean_keys(counter.key)
Exemplo n.º 4
0
    def test_window(self):
        counter = TimeWindow(key='test_key', cycle_time=.1, window=1)
        counter.setup(self.redis_conn)
        counter.increment()
        counter.increment()
        counter.increment()
        time.sleep(1.1)
        counter.increment()
        counter.stop()
        self.assertEqual(counter.value(), 3)

        self.clean_keys(counter.key)