def test_01_increase_and_decrease(self): r = increase("hallo_counter1") self.assertEqual(r, 1) for x in range(1, 5): increase("hallo_counter1") counter = EventCounter.query.filter_by( counter_name="hallo_counter1").first() self.assertEqual(counter.counter_value, 5) r = decrease("hallo_counter1") self.assertEqual(r, 4) for x in range(1, 8): decrease("hallo_counter1") counter = EventCounter.query.filter_by( counter_name="hallo_counter1").first() self.assertEqual(counter.counter_value, 0) # Test reading counter r = read("hallo_counter1") self.assertEqual(r, 0) r = read("unknown counter") self.assertEqual(r, None)
def do(self, action, options=None): """ This method executes the defined action in the given event. :param action: :param options: Contains the flask parameters g, request, response and the handler_def configuration :type options: dict :return: """ ret = True #g = options.get("g") handler_def = options.get("handler_def") handler_options = handler_def.get("options", {}) counter_name = handler_options.get("counter_name") if action == "increase_counter": increase(counter_name) log.debug(u"Increased the counter {0!s}.".format(counter_name)) elif action == "decrease_counter": allow_negative = handler_options.get("allow_negative_values") decrease(counter_name, allow_negative) log.debug(u"Decreased the counter {0!s}.".format(counter_name)) elif action == "reset_counter": reset(counter_name) log.debug(u"Reset the counter {0!s} to 0.".format(counter_name)) return ret
def test_00_create_and_increase(self): r = increase("hallo_counter") self.assertEqual(r, 1) r = increase("counter2") self.assertEqual(r, 1) r = increase("hallo_counter") self.assertEqual(r, 2) counter = EventCounter.query.filter_by(counter_name="hallo_counter").first() self.assertEqual(counter.counter_value, 2)
def do(self, action, options=None): """ This method executes the defined action in the given event. :param action: :param options: Contains the flask parameters g, request, response and the handler_def configuration :type options: dict :return: """ ret = True #g = options.get("g") handler_def = options.get("handler_def") handler_options = handler_def.get("options", {}) counter_name = handler_options.get("counter_name") if action == "increase_counter": r = increase(counter_name) log.debug(u"Increased the counter {0!s} to {1!s}.".format(counter_name, r)) elif action == "decrease_counter": allow_negative = handler_options.get("allow_negative_values") r = decrease(counter_name, allow_negative) log.debug(u"Decreased the counter {0!s} to {1!s}.".format(counter_name, r)) elif action == "reset_counter": reset(counter_name) log.debug(u"Reset the counter {0!s} to 0.".format(counter_name)) return ret
def test_02_decrease_beyond_zero(self): r = increase("hallo_counter2") self.assertEqual(r, 1) for x in range(1, 8): decrease("hallo_counter2", allow_negative=True) counter = EventCounter.query.filter_by(counter_name="hallo_counter2").first() self.assertEqual(counter.counter_value, -6)
def test_02_decrease_beyond_zero(self): r = increase("hallo_counter2") self.assertEqual(r, 1) for x in range(1, 8): decrease("hallo_counter2", allow_negative=True) counter = EventCounter.query.filter_by( counter_name="hallo_counter2").first() self.assertEqual(counter.counter_value, -6)
def test_00_read_eventcounter_to_monitoringstats(self): r = increase("counter1") self.assertEqual(r, 1) r = increase("counter2") self.assertEqual(r, 1) r = increase("counter1") self.assertEqual(r, 2) r = read("counter1") self.assertEqual(r, 2) et = EventCounterTask() params = { "event_counter": "counter1", "stats_key": "C1", "reset_event_counter": "True" } # Now we execute the task et.do(params) # The counter "counter1" should be resetted self.assertEqual(read("counter1"), 0) # The value "2" should be written to the statistics key C1. stats = get_values("C1") self.assertTrue(len(stats), 1) self.assertTrue(stats[0][1], 2) # Now we increase the event counter again increase("counter1") # ..and run the event counter task et.do(params) stats = get_values("C1") self.assertTrue(len(stats), 2) self.assertTrue(stats[0][1], 2) self.assertTrue(stats[0][1], 1)
def test_00_read_eventcounter_to_monitoringstats(self): r = increase("counter1") self.assertEqual(r, 1) r = increase("counter2") self.assertEqual(r, 1) r = increase("counter1") self.assertEqual(r, 2) r = read("counter1") self.assertEqual(r, 2) et = EventCounterTask() params = {"event_counter": "counter1", "stats_key": "C1", "reset_event_counter": "True"} # Now we execute the task et.do(params) # The counter "counter1" should be resetted self.assertEqual(read("counter1"), 0) # The value "2" should be written to the statistics key C1. stats = get_values("C1") self.assertTrue(len(stats), 1) self.assertTrue(stats[0][1], 2) # Now we increase the event counter again increase("counter1") # ..and run the event counter task et.do(params) stats = get_values("C1") self.assertTrue(len(stats), 2) self.assertTrue(stats[0][1], 2) self.assertTrue(stats[0][1], 1)
def test_01_increase_and_decrease(self): r = increase("hallo_counter1") self.assertEqual(r, 1) for x in range(1, 5): increase("hallo_counter1") counter = EventCounter.query.filter_by(counter_name="hallo_counter1").first() self.assertEqual(counter.counter_value, 5) r = decrease("hallo_counter1") self.assertEqual(r, 4) for x in range(1, 8): decrease("hallo_counter1") counter = EventCounter.query.filter_by(counter_name="hallo_counter1").first() self.assertEqual(counter.counter_value, 0) # Test reading counter r = read("hallo_counter1") self.assertEqual(r, 0) r = read("unknown counter") self.assertEqual(r, None)
def do(self, action, options=None): """ This method executes the defined action in the given event. :param action: :param options: Contains the flask parameters g, request, response and the handler_def configuration :type options: dict :return: """ ret = True #g = options.get("g") handler_def = options.get("handler_def") handler_options = handler_def.get("options", {}) if action == "increase_counter": counter_name = handler_options.get("counter_name") r = increase(counter_name) log.debug(u"Increased the counter {0!s} to {1!s}.".format(counter_name, r)) return ret