class TestIntegrationCoreEvent(TestCase):
    def setUp(self):
        self.coreObj = Core()
        self.event = Event(eventCreator=self.coreObj)

    def tearDown(self):
        self.coreObj = None
        self.event = None

    def test_executeEvent_start_simulation_in_core(self):
        source_obj = Source(self.coreObj)
        self.coreObj.output_file = open('./TEST.txt', "w+")
        self.coreObj.sources.append(source_obj)
        self.event = Event(eventCreator=self.coreObj,
                           eventName=Constants.START_SIMULATION)
        self.coreObj.executeEvent(self.event)
        self.coreObj.output_file.close()
        self.assertEquals(
            self.coreObj.eventsList.qsize(), 2,
            "The length should be two: start simulation event + first event from source"
        )
        obj = self.coreObj.eventsList
        self.assertIsNotNone("The object is not none", obj)
        with open('./TEST.txt', "r") as read:
            self.assertNotEquals(len(read.read()), 0,
                                 "The file should not be empty")
Пример #2
0
    def test_updateState_Not_First_Shift(self):
        param = Parameters()
        param.num_processors = 2
        self.coreObj = Core(param)

        for mock_processor in self.coreObj.processors:
            mock_processor.isIdle = MagicMock(return_value=False)

        mock_event = Event()
        mock_event.executeEvent = MagicMock()
        mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 1 * 3600 + 1

        self.coreObj.updateState(mock_event)

        mock_event = Event()
        mock_event.executeEvent = MagicMock()
        mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 5 * 3600 + 1

        self.coreObj.updateState(mock_event)

        self.assertEqual(
            self.coreObj.currentTime,
            Constants.SIMULATION_INITIAL_TIME + 5 * 3600 + 1,
            "The current time should be updated to SIMULATION_INITIAL_TIME + 5*3600 + 1"
        )
        self.assertEqual(
            self.coreObj.serviceProcessors, (5 * 3600 + 1) * 2,
            "The service processors time should be (5*3600 + 1) * 2 (2 service processors)"
        )
        self.assertEqual(self.coreObj.idleProcessors, 0,
                         "The idle time should be 0")
 def test_run(self):
     param = Parameters()
     param.num_processors = 2
     self.coreObj = Core(param)
     self.coreObj.output_file = open('./TEST.txt', "w+")
     self.coreObj.parameters.output_file = "TEST"
     self.coreObj.run()
     self.coreObj.output_file.close()
     self.assertEquals(
         self.coreObj.eventsList.qsize(), 0,
         "The length should be 0 because the simulation ended")
     obj = self.coreObj.eventsList
     self.assertIsNotNone("The object is not none", obj)
     with open('./TEST.stats.csv', "r") as read:
         self.assertNotEquals(len(read.read()), 0,
                              "The file should not be empty")
Пример #4
0
 def setUpClass(cls):
     cls.setWithShifts(True)
     param = Parameters()
     param.num_processors = Constants.DEFAULT_PROCESSORS
     shift_duration = [5, 5, 2, 2]
     shift_type = [
         Constants.ENTREGA, Constants.ENTREGA, Constants.RECOGIDA,
         Constants.DUAL
     ]
     shift_factor = 3600  # hours
     param.setParameters(shift_duration, shift_type, shift_factor)
     cls.coreObj = Core(param)
     cls.coreObj.output_file = open('./TEST_System.txt', "w+")
     cls.coreObj.parameters.output_file = Constants.OUTPUT_PATH + "TEST_System"
     cls.coreObj.run()
     cls.coreObj.output_file.close()
     with open(Constants.OUTPUT_PATH + 'TEST_System.csv', "r") as read:
         header = read.readline().split(',')
         header = [tmp.split('\n')[0] for tmp in header]
         for i in range(len(header)):
             cls.cols[header[i]] = i
         line = read.readline()
         # [current_time, event_name, event_scheduled, event_time, idle_proc, service_proc, num_idle_proc, buff_len, queue_len, entities_system, shift]
         # Current_Time,Event_Name,Event_Scheduled,Event-Time,Idle_Processors,Service_Processors,Number_Idle_Processors,Buffer_Length,Queue_Length,Entities_System,Shift
         while line:
             row = TestSystemWithShifts.process_line(line)
             cls.static_big_matrix.append(row)
             line = read.readline()
Пример #5
0
    def test_updateState_With_2Idle_Processors(self):
        param = Parameters()
        param.num_processors = 2
        self.coreObj = Core(param)
        for mock_processor in self.coreObj.processors:
            mock_processor.isIdle = MagicMock(return_value=True)

        mock_event = Event()
        mock_event.executeEvent = MagicMock()
        mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 123

        self.coreObj.updateState(mock_event)

        self.assertEqual(
            self.coreObj.currentTime, Constants.SIMULATION_INITIAL_TIME + 123,
            "The current time should be updated to SIMULATION_INITIAL_TIME + 123"
        )
        self.assertEqual(
            self.coreObj.idleProcessors, 123 * 2,
            "The idle time should be 123 * 2 (2 idle processors)")
        self.assertEqual(self.coreObj.serviceProcessors, 0,
                         "The service processors time should be 0")
Пример #6
0
import logging

from src.Core import Core

logging.basicConfig(format='httpc: %(message)s', level=logging.DEBUG)

core = Core()
try:
    core.run()
except Exception as e:
    logging.error(e)
exit(0)
Пример #7
0
 def setUp(self):
     mock_core = Core()
     mock_core.canHostEntity = MagicMock(return_value=True)
     mock_core.nextArrival = MagicMock()
     mock_core.decreaseEntitiesSystem = MagicMock()
     self.processorObj = Processor(mock_core)
Пример #8
0
class TestCore(TestCase):
    def setUp(self):
        self.coreObj = Core()

    def tearDown(self):
        self.coreObj = None

    def test_increaseEntitiesSystem(self):
        self.assertEqual(self.coreObj.entitiesSystem, 0,
                         "The core should not have any entity")
        self.coreObj.increaseEntitiesSystem()
        self.assertEqual(self.coreObj.entitiesSystem, 1,
                         "The core should have 1 entity")

    def test_decreaseEntitiesSystem(self):
        self.coreObj.increaseEntitiesSystem()
        self.assertEqual(self.coreObj.entitiesSystem, 1,
                         "The core should have 1 entity")
        self.coreObj.decreaseEntitiesSystem()
        self.assertEqual(self.coreObj.entitiesSystem, 0,
                         "The core should not have any entity")

    def test_run(self):
        mock_event = Event()
        mock_event.executeEvent = MagicMock()
        mock_event.eventName = MagicMock(return_value="Test")
        mock_event.eventScheduled = MagicMock(
            return_value=Constants.SIMULATION_INITIAL_TIME)
        mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 123

        # eventsList is a Priority Queue
        self.coreObj.logEvent = MagicMock()
        self.coreObj.eventsList.put(mock_event)
        self.coreObj.updateState(mock_event)

        self.assertEqual(
            self.coreObj.currentTime, Constants.SIMULATION_INITIAL_TIME + 123,
            "The current time should be updated to SIMULATION_INITIAL_TIME + 123"
        )

    def test_updateState_No_Processors(self):
        mock_event = Event()
        mock_event.executeEvent = MagicMock()
        mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 123

        self.coreObj.updateState(mock_event)

        self.assertEqual(
            self.coreObj.currentTime, Constants.SIMULATION_INITIAL_TIME + 123,
            "The current time should be updated to SIMULATION_INITIAL_TIME + 123"
        )

    def test_updateState_With_2Idle_Processors(self):
        param = Parameters()
        param.num_processors = 2
        self.coreObj = Core(param)
        for mock_processor in self.coreObj.processors:
            mock_processor.isIdle = MagicMock(return_value=True)

        mock_event = Event()
        mock_event.executeEvent = MagicMock()
        mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 123

        self.coreObj.updateState(mock_event)

        self.assertEqual(
            self.coreObj.currentTime, Constants.SIMULATION_INITIAL_TIME + 123,
            "The current time should be updated to SIMULATION_INITIAL_TIME + 123"
        )
        self.assertEqual(
            self.coreObj.idleProcessors, 123 * 2,
            "The idle time should be 123 * 2 (2 idle processors)")
        self.assertEqual(self.coreObj.serviceProcessors, 0,
                         "The service processors time should be 0")

    def test_updateState_With_2Service_Processors(self):
        param = Parameters()
        param.num_processors = 2
        self.coreObj = Core(param)

        for mock_processor in self.coreObj.processors:
            mock_processor.isIdle = MagicMock(return_value=False)

        mock_event = Event()
        mock_event.executeEvent = MagicMock()
        mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 123

        self.coreObj.updateState(mock_event)

        self.assertEqual(
            self.coreObj.currentTime, Constants.SIMULATION_INITIAL_TIME + 123,
            "The current time should be updated to SIMULATION_INITIAL_TIME + 123"
        )
        self.assertEqual(
            self.coreObj.serviceProcessors, 123 * 2,
            "The service processors time should be 123 * 2 (2 service processors)"
        )
        self.assertEqual(self.coreObj.idleProcessors, 0,
                         "The idle time should be 0")

    def test_updateState_Not_First_Shift(self):
        param = Parameters()
        param.num_processors = 2
        self.coreObj = Core(param)

        for mock_processor in self.coreObj.processors:
            mock_processor.isIdle = MagicMock(return_value=False)

        mock_event = Event()
        mock_event.executeEvent = MagicMock()
        mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 1 * 3600 + 1

        self.coreObj.updateState(mock_event)

        mock_event = Event()
        mock_event.executeEvent = MagicMock()
        mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 5 * 3600 + 1

        self.coreObj.updateState(mock_event)

        self.assertEqual(
            self.coreObj.currentTime,
            Constants.SIMULATION_INITIAL_TIME + 5 * 3600 + 1,
            "The current time should be updated to SIMULATION_INITIAL_TIME + 5*3600 + 1"
        )
        self.assertEqual(
            self.coreObj.serviceProcessors, (5 * 3600 + 1) * 2,
            "The service processors time should be (5*3600 + 1) * 2 (2 service processors)"
        )
        self.assertEqual(self.coreObj.idleProcessors, 0,
                         "The idle time should be 0")
Пример #9
0
 def setUp(self):
     self.coreObj = Core()
 def setUp(self):
     param = Parameters()
     param.WITH_SHIFTS = True
     self.randObj = Random()
     self.randObj.initialization()
     self.coreObj = Core()
class TestIntegrationCoreOtherClasses(TestCase):
    def setUp(self):
        param = Parameters()
        param.WITH_SHIFTS = True
        self.randObj = Random()
        self.randObj.initialization()
        self.coreObj = Core()

    def tearDown(self):
        self.coreObj = None
        try:
            os.remove("./TEST.csv")
        except:
            pass
        try:
            os.remove("./TEST.stats.csv")
        except:
            pass
        try:
            os.remove("./TEST.txt")
        except:
            pass

    def test_startSimulation(self):
        source_obj = Source(self.coreObj)
        self.coreObj.output_file = open('./TEST.txt', "w+")
        self.coreObj.sources.append(source_obj)
        self.coreObj.startSimulation()
        self.coreObj.output_file.close()
        self.assertEquals(
            self.coreObj.eventsList.qsize(), 2,
            "The length should be two: start simulation event + first event from source"
        )
        obj = self.coreObj.eventsList
        self.assertIsNotNone(obj, "The object is not none")
        with open('./TEST.txt', "r") as read:
            self.assertNotEquals(len(read.read()), 0,
                                 "The file should not be empty")

    def test_executeEvent_Start_Simulation(self):
        source_obj = Source(self.coreObj)
        self.coreObj.output_file = open('./TEST.txt', "w+")
        self.coreObj.sources.append(source_obj)
        self.coreObj.executeEvent(Event(eventName=Constants.START_SIMULATION))
        self.coreObj.output_file.close()
        self.assertEquals(
            self.coreObj.eventsList.qsize(), 2,
            "The length should be two: start simulation event + first event from source"
        )
        obj = self.coreObj.eventsList
        self.assertIsNotNone("The object is not none", obj)
        with open('./TEST.txt', "r") as read:
            self.assertNotEquals(len(read.read()), 0,
                                 "The file should not be empty")

    def test_executeEvent_OtherEvent(self):
        source_obj = Source(self.coreObj)
        self.coreObj.output_file = open('./TEST.txt', "w+")
        self.coreObj.sources.append(source_obj)
        self.coreObj.executeEvent(Event(eventName=Constants.END_SIMULATION))
        self.coreObj.output_file.close()
        self.assertEquals(
            self.coreObj.eventsList.qsize(), 0,
            "The length should be 0 because the simulation did not start")
        obj = self.coreObj.eventsList
        self.assertIsNotNone("The object is not none", obj)
        with open('./TEST.txt', "r") as read:
            self.assertEquals(len(read.read()), 0, "The file should be empty")

    def test_endSimulation(self):
        self.coreObj.output_file = open('./TEST.txt', "w+")
        self.coreObj.endSimulation()
        self.coreObj.output_file.close()
        self.assertEquals(
            self.coreObj.eventsList.qsize(), 0,
            "The length should be 0 because the simulation ended")
        obj = self.coreObj.eventsList
        self.assertIsNotNone("The object is not none", obj)
        with open('./TEST.txt', "r") as read:
            self.assertNotEquals(len(read.read()), 0,
                                 "The file should not be empty")

    def test_run(self):
        param = Parameters()
        param.num_processors = 2
        self.coreObj = Core(param)
        self.coreObj.output_file = open('./TEST.txt', "w+")
        self.coreObj.parameters.output_file = "TEST"
        self.coreObj.run()
        self.coreObj.output_file.close()
        self.assertEquals(
            self.coreObj.eventsList.qsize(), 0,
            "The length should be 0 because the simulation ended")
        obj = self.coreObj.eventsList
        self.assertIsNotNone("The object is not none", obj)
        with open('./TEST.stats.csv', "r") as read:
            self.assertNotEquals(len(read.read()), 0,
                                 "The file should not be empty")

    def test_getCurrentShift(self):
        source_obj = Source(self.coreObj)
        self.coreObj.sources.append(source_obj)
        self.coreObj.output_file = open('./TEST.txt', "w+")
        self.coreObj.executeEvent(Event(eventName=Constants.START_SIMULATION))
        self.coreObj.output_file.close()
        self.assertEquals(self.coreObj.getCurrentShift(), Constants.ENTREGA,
                          "The first shift should be of type ENTREGA")
 def setUp(self):
     self.coreObj = Core()
     self.event = Event(eventCreator=self.coreObj)
Пример #13
0
def main():
    Core.init()

    review = '[UPDATE]\n v2.0-alpha\n\n[CHANGELOG]\n\n\nПо всем вопросам/предложениям пиши @big_black_hot_brother'
    start(review, silent=True)