def test_record_events(self): timestamp = str(time.time()).replace(".", "_") temp_file_path = f'{tempfile.gettempdir()}/{timestamp}.txt' try: EventBuffer(record_events=True, record_path=None) self.assertTrue(False) except ValueError: pass eb = EventBuffer(record_events=True, record_path=temp_file_path) eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.execute(1) eb.reset() eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.execute(1) del eb with open(temp_file_path, "r") as input_stream: texts = input_stream.readlines() self.assertListEqual(texts, [ 'episode,tick,event_type,payload\n', '0,1,1,"(1, 3)"\n', '0,1,1,"(1, 3)"\n', '0,1,1,"(1, 3)"\n', '0,1,1,"(1, 3)"\n', '1,1,1,"(1, 3)"\n', '1,1,1,"(1, 3)"\n', '1,1,1,"(1, 3)"\n', '1,1,1,"(1, 3)"\n' ])
def __init__(self, scenario: str = None, topology: str = None, start_tick: int = 0, durations: int = 100, snapshot_resolution: int = 1, max_snapshots: int = None, decision_mode: DecisionMode = DecisionMode.Sequential, business_engine_cls: type = None, options: dict = {}): super().__init__(scenario, topology, start_tick, durations, snapshot_resolution, max_snapshots, decision_mode, business_engine_cls, options) self._name = f'{self._scenario}:{self._topology}' if business_engine_cls is None \ else business_engine_cls.__name__ self._business_engine: AbsBusinessEngine = None self._event_buffer = EventBuffer() # The generator used to push the simulator forward. self._simulate_generator = self._simulate() # Initialize the business engine. self._init_business_engine()
def __init__(self, scenario: str = None, topology: str = None, start_tick: int = 0, durations: int = 100, snapshot_resolution: int = 1, max_snapshots: int = None, decision_mode: DecisionMode = DecisionMode.Sequential, business_engine_cls: type = None, disable_finished_events: bool = False, options: dict = {}): super().__init__(scenario, topology, start_tick, durations, snapshot_resolution, max_snapshots, decision_mode, business_engine_cls, disable_finished_events, options) self._name = f'{self._scenario}:{self._topology}' if business_engine_cls is None \ else business_engine_cls.__name__ self._business_engine: AbsBusinessEngine = None self._event_buffer = EventBuffer(disable_finished_events) # decision_events array for dump. self._decision_events = [] # The generator used to push the simulator forward. self._simulate_generator = self._simulate() # Initialize the business engine. self._init_business_engine() if "enable-dump-snapshot" in self._additional_options: parent_path = self._additional_options["enable-dump-snapshot"] self._converter = DumpConverter( parent_path, self._business_engine._scenario_name) self._converter.reset_folder_path()
def setUp(self): config_path = "tests/data/vm_scheduling" self.eb = EventBuffer() self.be = VmSchedulingBusinessEngine(event_buffer=self.eb, topology=config_path, start_tick=0, max_tick=3, snapshot_resolution=1, max_snapshots=None, additional_options={})
def test_disable_finished_events(self): eb = EventBuffer(disable_finished_events=True) self.assertListEqual([], eb.get_finished_events(), msg="finished pool should be empty") eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.insert_event(eb.gen_atom_event(1, 1, (1, 3))) eb.execute(1) # after dispatching, finish pool should still contains no object self.assertListEqual([], eb.get_finished_events(), msg="finished pool should be empty")
def setup_case(case_name: str, max_tick: int): config_path = os.path.join("tests/data/citi_bike", case_name) # enable binary exist # trips.bin trips_bin = os.path.join(config_path, "trips.bin") if not os.path.exists(trips_bin): converter = BinaryConverter( trips_bin, os.path.join("tests/data/citi_bike", "trips.meta.yml")) converter.add_csv(os.path.join(config_path, "trips.csv")) converter.flush() # weathers.bin weathers_bin = os.path.join("tests/data/citi_bike", "weathers.bin") if not os.path.exists(weathers_bin): converter = BinaryConverter( weathers_bin, os.path.join("tests/data/citi_bike", "weather.meta.yml")) converter.add_csv(os.path.join("tests/data/citi_bike", "weather.csv")) converter.flush() eb = EventBuffer() be = CitibikeBusinessEngine(event_buffer=eb, topology=config_path, start_tick=0, max_tick=max_tick, snapshot_resolution=1, max_snapshots=None, additional_options={}) return eb, be
def setUp(self): self.eb = EventBuffer()