Esempio n. 1
0
 def test_time_controller(self):
     buffer = Buffer(time_threshold=0.01)
     payload = [1, 2, 3]
     records = [Record(payload=p) for p in payload]
     result_false = buffer._time_controller(records)
     time.sleep(0.01)
     result_true = buffer._time_controller(records)
     self.assertFalse(
         result_false,
         'Time controller should return False after less than 0.01 seconds')
     self.assertTrue(
         result_true,
         'Time controller should return True after sleeping for 0.01 seconds'
     )
Esempio n. 2
0
 def test_execute_disjoint(self):
     custom_controller = MagicMock(side_effect=lambda x: False)
     buffer = Buffer(count_threshold=1,
                     time_threshold=1,
                     custom_controllers=custom_controller)
     buffer._count_controller = MagicMock(side_effect=lambda x: False)
     buffer._time_controller = MagicMock(side_effect=lambda x: False)
     payload = [1, 2, 3]
     records = [Record(payload=p) for p in payload]
     buffer._execute(records)
     buffer._count_controller.assert_called_with(records)
     buffer._time_controller.assert_called_with(records)
     custom_controller.assert_called_with(records)
Esempio n. 3
0
 def test_execute_conjoint_true(self):
     custom_controller = MagicMock(side_effect=lambda x: True)
     buffer = Buffer(count_threshold=1,
                     time_threshold=1,
                     custom_controllers=custom_controller,
                     conjugate_controllers=True)
     buffer._count_controller = MagicMock(side_effect=lambda x: True)
     buffer._time_controller = MagicMock(side_effect=lambda x: True)
     payload = [1, 2, 3]
     records = [Record(payload=p) for p in payload]
     result = buffer._execute(records)
     buffer._count_controller.assert_called_with(records)
     buffer._time_controller.assert_called_with(records)
     custom_controller.assert_called_with(records)
     self.assertEqual(result, records)