Esempio n. 1
0
    def test_order_submitted_event(self):
        """Test to verify the mechanics of the order submitted event"""

        # Constants
        initial_time = hour_to_sec(15)
        placement_time = time(15, 0, 0)
        preparation_time = time(15, 1, 0)
        ready_time = time(15, 15, 0)

        # Services
        env = Environment(initial_time=initial_time)
        dispatcher = Dispatcher(env=env, matching_policy=DummyMatchingPolicy())

        # Creates an order and submits it to the dispatcher
        order = Order(order_id=32, placement_time=placement_time)
        dispatcher.order_submitted_event(order, preparation_time, ready_time)
        env.run(until=initial_time + 121)

        # Verify order properties are set and it is correctly allocated
        self.assertEqual(order.preparation_time, preparation_time)
        self.assertEqual(order.ready_time, ready_time)
        self.assertIn(order.order_id, dispatcher.unassigned_orders.keys())
Esempio n. 2
0
    def test_buffer_event(self):
        """Test to verify how the mechanics of the dispatcher buffering orders work"""

        # Constants
        initial_time = hour_to_sec(16)
        placement_time = time(16, 0, 0)
        time_delta = min_to_sec(10)

        # Verifies two test cases for how the dispatcher buffers orders
        # For each test, assert the correct number of orders are buffered

        # Test 1: schedules the submission of three orders and assert that only two are buffered
        env = Environment(initial_time=initial_time)
        dispatcher = Dispatcher(
            env=env,
            buffering_policy=RollingBufferingPolicy(),
            matching_policy=DummyMatchingPolicy()
        )
        order_1 = Order(order_id=1, placement_time=placement_time)
        order_2 = Order(order_id=2, placement_time=placement_time)
        order_3 = Order(order_id=3, placement_time=placement_time)
        dispatcher.order_submitted_event(order_1, preparation_time=time(16, 0, 27), ready_time=time(16, 10, 0))
        dispatcher.order_submitted_event(order_2, preparation_time=time(16, 0, 43), ready_time=time(16, 10, 0))
        dispatcher.order_submitted_event(order_3, preparation_time=time(18, 0, 0), ready_time=time(18, 10, 0))

        env.run(until=initial_time + time_delta)
        self.assertEqual(len(dispatcher.unassigned_orders), 2)

        # Test 2: schedules the submission of three orders and assert that all three orders are buffered
        env = Environment(initial_time=initial_time)
        dispatcher = Dispatcher(
            env=env,
            buffering_policy=RollingBufferingPolicy(),
            matching_policy=DummyMatchingPolicy()
        )
        order_1 = Order(order_id=1, placement_time=placement_time)
        order_2 = Order(order_id=2, placement_time=placement_time)
        order_3 = Order(order_id=3, placement_time=placement_time)
        dispatcher.order_submitted_event(order_1, preparation_time=time(16, 0, 27), ready_time=time(16, 10, 0))
        dispatcher.order_submitted_event(order_2, preparation_time=time(16, 0, 43), ready_time=time(16, 10, 0))
        dispatcher.order_submitted_event(order_3, preparation_time=time(16, 4, 1), ready_time=time(16, 14, 0))
        env.run(until=initial_time + time_delta)
        self.assertEqual(len(dispatcher.unassigned_orders), 3)