예제 #1
0
 def check_block(self, event_block):
     if self.event_blocks == []:
         return
     end_time = self.event_blocks[0].end_time
     if (end_time > event_block.start_time):
         self.alerts.append(
             ALERT_TIMEWARP.format(end_time=display_time(end_time),
                                   start_time=display_time(
                                       event_block.start_time)))
         self.event_blocks = []
예제 #2
0
 def test_timewarp(self):
     watcher = TrafficWatcher(DEFAULT_WINDOW, DEFAULT_RATE)
     count = DEFAULT_RATE
     start_time = DEFAULT_START_TIME
     end_time = start_time + TIME_PER_BLOCK
     watcher.update(
         TrafficEventBlock(count=count,
                           start_time=start_time,
                           end_time=end_time))
     alert = ALERT_TIMEWARP.format(start_time=display_time(start_time),
                                   end_time=display_time(end_time))
     # Note: start_time has not changed
     assert alert in watcher.update(
         TrafficEventBlock(count=count,
                           start_time=start_time,
                           end_time=end_time))
예제 #3
0
 def summarize(self, block):
     report = []
     report_time = time()
     report.append("\nDate: {}".format(display_time(report_time)))
     block_summary = BlockSummary(block)
     report += block_summary.summarize()
     report += self.update_whole(report_time, block_summary)
     report += self.summarize_whole()
     return report
예제 #4
0
 def test_alert_recovery(self):
     watcher = TrafficWatcher(DEFAULT_WINDOW, DEFAULT_RATE)
     count = DEFAULT_WINDOW * DEFAULT_RATE + 1
     start_time = DEFAULT_START_TIME
     end_time = start_time + TIME_PER_BLOCK
     alert = ALERT_HIGH_TRAFFIC.format(count=count,
                                       time=display_time(end_time))
     assert alert in watcher.update(
         TrafficEventBlock(count=count,
                           start_time=start_time,
                           end_time=end_time))
     for i in range(int(DEFAULT_WINDOW / DEFAULT_RATE) + 1):
         start_time = end_time
         end_time = end_time + TIME_PER_BLOCK
         result = watcher.update(
             TrafficEventBlock(count=0,
                               start_time=start_time,
                               end_time=end_time))
     alert = RECOVER_HIGH_TRAFFIC.format(time=display_time(end_time))
     assert alert in result
예제 #5
0
 def test_alert_triggered(self):
     watcher = TrafficWatcher(DEFAULT_WINDOW, DEFAULT_RATE)
     count = DEFAULT_WINDOW * DEFAULT_RATE + 1
     start_time = DEFAULT_START_TIME
     end_time = start_time + TIME_PER_BLOCK
     alert = ALERT_HIGH_TRAFFIC.format(count=count,
                                       time=display_time(end_time))
     assert alert in watcher.update(
         TrafficEventBlock(count=count,
                           start_time=start_time,
                           end_time=end_time))
예제 #6
0
파일: test_utils.py 프로젝트: mo-nathan/ddc
 def test_display_time(self):
     assert "1970" in display_time(0)
예제 #7
0
 def cancel_alert(self):
     if self.alert_mode:
         self.alert_mode = False
         self.alerts.append(
             RECOVER_HIGH_TRAFFIC.format(
                 time=display_time(self.last_end_time())))
예제 #8
0
 def alert_triggered(self):
     self.alert_mode = True
     self.alerts.append(
         ALERT_HIGH_TRAFFIC.format(count=self.event_count(),
                                   time=display_time(self.last_end_time())))