예제 #1
0
    def _init_maniplate_db(self):
        logger.debug(f"{self}._init_maniplate_db()")
        simulation_db = sql.SQL(db_path=self.simulation_db_path,
                                schema_path=SCHEMA_PATH)
        self.simulation_db = simulation_db
        self.simulation_db.access_db()
        simulation_db.total_nodes = \
            self.simulation_db.select_one('simulation', 'total_nodes')
        column_name = 'simulation_ms'
        self.simulation_ms = \
            self.simulation_db.select('simulation', \
                             column_name)[0][column_name]

        logger.debug(
            f"{self}._init_maniplate_db(), {self}.simulation_ms={self.simulation_ms}"
        )
        self._memory_db = sql.SQL(':memory:',
                                  schema_path=self.simulation_db.schema_path)
        logger.debug(
            f"{self}._init_maniplate_db(), {self}._memory_db={self._memory_db}"
        )
        self._memory_db.create_db()
        self._memory_db.create_table('simulation')
        init_nodes_table2(self._memory_db, simulation_db.total_nodes)
        self.manipulated.set()
예제 #2
0
    def test_darkness__leave_here(self):
        darkness = self.darkness
        darkness._exhale_queue.start()  # for ExhaleQueue object
        darkness._spawn_nodes()

        client_db = sql.SQL(db_path=darkness.client_db_path,
                            schema_path=SCHEMA_PATH)
        client_db.create_db()
        client_db.create_table('growings')
        client_db.close()

        self.assertFalse(darkness.byebye_nodes.is_set())
        self.assertFalse(darkness.all_nodes_inactive.is_set())
        self.assertEqual(len(darkness.nodes), darkness.num_nodes)
        for node in darkness.nodes:
            self.assertTrue(node.is_alive())
        self.assertTrue(darkness._exhale_queue.is_alive())

        darkness._leave_here()

        self.assertTrue(darkness.byebye_nodes.is_set())
        self.assertTrue(darkness.all_nodes_inactive.is_set())
        self.assertEqual(len(darkness.nodes), darkness.num_nodes)
        for node in darkness.nodes:
            self.assertFalse(node.is_alive())
        self.assertFalse(darkness._exhale_queue.is_alive())
예제 #3
0
    def __init__(self, **kwargs):
        '''\
        Darkness process 内で 多数の node thread を作成する。
        Client が leave_there を signal 状態にしたら終了処理を行う。
        '''
        st_barrier = set([
            'id',
            'client_id',
            'first_node_id',
            'dir_name',
            'num_nodes',
            'log_level',
            'start_up_orig',
            'made_nodes',  # share with client and darknesses
            'leave_there',  # share with client and another darknesses
            'num_darkness',
        ])
        validate_kwargs(st_barrier, kwargs)

        for attr, value in kwargs.items():
            logger.debug(f"setattr(attr={attr}, value={value})")
            setattr(self, attr, value)

        logger.info(('{} initilized, '
                     'num_nodes={}.').format(self, self.num_nodes))
        logger.debug('{} debug log test.'.format(self))

        self.client_db_path = os.path.join(
            self.dir_name, 'client.{}.db'.format(self.client_id))
        self.schema_path = SCHEMA_PATH
        self.client_db = sql.SQL(db_path=self.client_db_path,
                                 schema_path=self.schema_path)

        self._queue_darkness = queue.Queue()
        self.all_nodes_inactive = threading.Event()
        self.im_sleeping = threading.Event()
        self._exhale_queue = ExhaleQueue(self.POLLING_EXHALEQUEUE, self)

        self.byebye_nodes = threading.Event()

        self.nodes = []
예제 #4
0
    def test_darkess_start(self):
        darkness_d_config = self.darkness_d_config
        darkness = self.darkness

        leave_there = darkness_d_config['leave_there']
        dir_name = darkness_d_config['dir_name']
        client_id = darkness_d_config['client_id']

        self.assertFalse(darkness.byebye_nodes.is_set())
        self.assertEqual(darkness.leave_there, leave_there)
        self.assertEqual(darkness.client_db.db_path,
                         os.path.join(dir_name, f"client.{client_id}.db"))
        self.assertListEqual(darkness.nodes, [])
        self.assertEqual(darkness._queue_darkness.qsize(), 0)
        self.assertFalse(darkness.all_nodes_inactive.is_set())
        self.assertFalse(darkness.im_sleeping.is_set())

        client_db = sql.SQL(db_path=darkness.client_db_path,
                            schema_path=SCHEMA_PATH)
        client_db.create_db()
        client_db.create_table('growings')
        client_db.close()

        self.assertEqual(threading.active_count(), 1)
        # "1" means of course a main thread.
        self.assertFalse(darkness.byebye_nodes.is_set())

        ######################################################################
        # Originally client set darkness.leave_there event. ##################
        # But there is no client. Therefore darkness must play client role. ##
        ######################################################################
        darkness_as_client = DarknessAsClient(self, darkness)
        darkness_as_client.start()

        darkness.start()

        self.assertTrue(darkness.all_nodes_inactive.is_set())
        self.assertTrue(darkness.byebye_nodes.is_set())
        self.assertEqual(threading.active_count(), 1)
예제 #5
0
    # Client will get start_up_time attribute in build_up_attrs()
    # after _hello_watson().
    client_process = multiprocessing.Process(target=make_client,
                                             args=(watson_office_addr,
                                                   args.num_nodes))

    # 本当は client_process を、ここで作らなくてもいい。
    # module の独立から考えると、むしろ作らない方が望ましいのだけど、
    # terminal 上で、別 process を起動させる手間を考えると楽なので、
    # ここで作ってしまう。 Makefile とか作りたくない。。。
    client_process.start()
    logger.info(f"client_process.pid={client_process.pid}")
    client_process.join()

    # 終了処理
    watson.join()

    logger.info("simulation end !")
    shutdown_time = tell_shutdown_time()
    logger.info(f"shutdown_time={shutdown_time}")

    logger.info(f"shutdown_time={shutdown_time}")

    logger.info(f"watson_make_simulation_db() start.")
    simulation_db = sql.SQL(db_path=watson.simulation_db_path,
                            schema_path=watson.schema_path)
    simulation_db.simulation_db_path = watson.simulation_db_path
    watson_make_simulation_db(simulation_db)
    logger.info(f"watson_make_simulation_db() done.")
예제 #6
0
 def _has_a_lot_on_mind(self):
     logger.info(f"{self}._makes_growings_table()")
     self.client_db = sql.SQL(db_path=self.client_db_path,
                              schema_path=self.schema_path)
     self.client_db.create_db()
     self.client_db.create_table('growings')