Ejemplo n.º 1
0
    def test_round_nearest_step(self):
        now = datetime.datetime(2017, 5, 15, 15, 11, 22)
        five_min = datetime.datetime(2017, 5, 15, 15, 15)
        ten_min = datetime.datetime(2017, 5, 15, 15, 20)
        fifteen_min = datetime.datetime(2017, 5, 15, 15, 15)
        thirty_min = datetime.datetime(2017, 5, 15, 15, 30)
        sixty_min = datetime.datetime(2017, 5, 15, 16)

        sc = StatsCache()
        assert sc.round_nearest_step(now, 5) == five_min
        assert sc.round_nearest_step(now, 10) == ten_min
        assert sc.round_nearest_step(now, 15) == fifteen_min
        assert sc.round_nearest_step(now, 30) == thirty_min
        assert sc.round_nearest_step(now, 60) == sixty_min
Ejemplo n.º 2
0
    def test_round_nearest_step(self):
        now = datetime.datetime(2017, 5, 15, 15, 11, 22)
        five_min = datetime.datetime(2017, 5, 15, 15, 15)
        ten_min = datetime.datetime(2017, 5, 15, 15, 20)
        fifteen_min = datetime.datetime(2017, 5, 15, 15, 15)
        thirty_min = datetime.datetime(2017, 5, 15, 15, 30)
        sixty_min = datetime.datetime(2017, 5, 15, 16)

        sc = StatsCache()
        assert sc.round_nearest_step(now, 5) == five_min
        assert sc.round_nearest_step(now, 10) == ten_min
        assert sc.round_nearest_step(now, 15) == fifteen_min
        assert sc.round_nearest_step(now, 30) == thirty_min
        assert sc.round_nearest_step(now, 60) == sixty_min
Ejemplo n.º 3
0
    def test_update_increment(self):
        sc = StatsCache()
        sc._init_stats()
        dt = datetime.datetime.now()
        key = sc.round_nearest_step(dt, 15).strftime(sc.dt_ftm)
        sc.update(name="test1", step_size=15)

        assert sc.stats["test1"][key] == 1
Ejemplo n.º 4
0
    def test_update_increment(self):
        sc = StatsCache()
        sc._init_stats()
        dt = datetime.datetime.now()
        key = sc.round_nearest_step(dt, 15).strftime(sc.dt_ftm)
        sc.update(name="test1", step_size=15)

        assert sc.stats["test1"][key] == 1
Ejemplo n.º 5
0
    def test_update_key_prefix(self):
        sc = StatsCache()
        sc._init_stats()
        value = os.urandom(64)
        dt1 = datetime.datetime(2017, 5, 15, 15, 9, 22)
        dt2 = datetime.datetime(2017, 5, 15, 15, 11, 42)
        sc.update(
            name="test3", step_size=15, set_dt=dt1,
            set_value=value, key_prefix="node1"
        )

        key = "node1%s" % sc.round_nearest_step(dt1, 15).strftime(sc.dt_ftm)
        assert sc.get_stat("test3", dt2, 15, key_prefix="node1") == value
        assert sc.stats["test3"][key] == value
Ejemplo n.º 6
0
    def test_update_key_prefix(self):
        sc = StatsCache()
        sc._init_stats()
        value = os.urandom(64)
        dt1 = datetime.datetime(2017, 5, 15, 15, 9, 22)
        dt2 = datetime.datetime(2017, 5, 15, 15, 11, 42)
        sc.update(name="test3",
                  step_size=15,
                  set_dt=dt1,
                  set_value=value,
                  key_prefix="node1")

        key = "node1%s" % sc.round_nearest_step(dt1, 15).strftime(sc.dt_ftm)
        assert sc.get_stat("test3", dt2, 15, key_prefix="node1") == value
        assert sc.stats["test3"][key] == value