def test_setup_1(self): # check nothing crashes sys = UnitSystem() supervisor = SupervisorActor.start() InputActor.start(sys.create_input_paper_stack((0, 1))), OutputActor.start(sys.create_output_paper_stack((3, 1))), ConveyorActor.start(sys.create_conveyor((1, 1))), ConveyorActor.start(sys.create_conveyor((2, 1))), PlotterActor.start(sys.create_plotter((1, 0), color=Color.Red)), PlotterActor.start(sys.create_plotter((2, 0), color=Color.Green)), PlotterActor.start(sys.create_plotter((1, 3), color=Color.Yellow)), PlotterActor.start(sys.create_plotter((2, 3), color=Color.Blue)) time.sleep(10) ActorRegistry().stop_all(block=True)
def test_registration(self): f1 = FunctionalUnit((0, 0)) f2 = FunctionalUnit((0, 1)) f3 = FunctionalUnit((0, 2)) a1 = OperatorActor.start(f1) time.sleep(.1) a2 = OperatorActor.start(f2) time.sleep(.1) a3 = OperatorActor.start(f3) time.sleep(.1) registry = ActorRegistry() for ref in [registry.get_by_urn(ref.actor_urn) for ref in [a1, a2, a3]]: a = ref._actor
def test_setup_2(self): # smaller setup sys = UnitSystem() supervisor = SupervisorActor.start() InputActor.start(sys.create_input_paper_stack((0, 1))), ops = sys.create_output_paper_stack((2, 1)) OutputActor.start(ops), ConveyorActor.start(sys.create_conveyor((1, 1))), PlotterActor.start(sys.create_plotter((1, 0), color=Color.Red)), PlotterActor.start(sys.create_plotter((1, 2), color=Color.Blue)), sheet_orders = [SheetOrder({Color.Red: 1})] for order in sheet_orders: supervisor.tell(SheetOrderMessage(order)) SleepyActor.start(20).stop(True) for order in sheet_orders: self.assertIn(order, ops.received_sheets) ActorRegistry().stop_all(block=True)
def _unregister(self): for supervisor in ActorRegistry().get_by_class(SupervisorActor): supervisor.tell(UnRegistrationMessage(self.actor_ref))
def _register(self, unit_location: Location, attributes: Dict[str, object]): for supervisor in ActorRegistry().get_by_class(SupervisorActor): supervisor.tell( RegistrationMessage(self.actor_ref, unit_location, attributes))
def on_start(self): self._register(self.conveyor.location, {const.UNIT_TYPE_KEY: const.CONVEYOR_TYPE}) self.supervisor = ActorRegistry().get_by_class(SupervisorActor)[0]