def start_controller_actor( host_name, port, minisat, sugar_jar, tmp_folder, actor_uris, log_requests, skip_actor_response_test, worker_count=None, dry_run=False, ): csp_solver_config = csp_solver.get_valid_csp_solver_config( minisat_path=minisat, sugarjar_path=sugar_jar, tmp_folder=tmp_folder) actors = [RemoteActor(actor_uri) for actor_uri in actor_uris] pool_kwargs = {} if worker_count: pool_kwargs['processes'] = worker_count import multiprocessing pool = multiprocessing.Pool(**pool_kwargs) actor = ControllerActor(actors=actors, csp_solver_config=csp_solver_config, multiprocessing_pool=pool) if not skip_actor_response_test: # test is actors of a ControllerActor exist # to prevent errors later for actor in actor._actors: import urllib2 try: value = actor.get_value() assert type(value) == int except urllib2.URLError as exc: print("Error while checking {0}: {1}".format( actor, exc.reason)) import sys sys.exit(1) print("All actors exist and respond as expected") kw = dict(host_port_tuple=(host_name, port), actor=actor, log_requests=log_requests) if dry_run: print("Would start an actor controller on {0} " "but this is a test run".format(kw)) return kw try: start_actor_server(**kw) except KeyboardInterrupt: pool.terminate() except Exception: pool.terminate() finally: pool.join()
get_parser, weighted_sum_to_csp, get_valid_csp_solver_config, solve_csp, main ) sugarjar_path = os.path.abspath( os.path.join( os.path.dirname(__file__), 'sugar-v1-15-0.jar' ) ) csp_solver_config = get_valid_csp_solver_config( sugarjar_path=sugarjar_path ) sample_csp_file_solvable = os.path.abspath(os.path.join( os.path.dirname(__file__), 'simple_example_solvable.csp') ) sample_csp_file_not_solvable = os.path.abspath(os.path.join( os.path.dirname(__file__), 'simple_example_not_solvable.csp') ) class TestBasicScenarios(unittest.TestCase): def test_not_satisfiable(self): result = do_solve( variables=[[1,2], [1,2]],
def start_controller_actor( host_name, port, minisat, sugar_jar, tmp_folder, actor_uris, log_requests, skip_actor_response_test, worker_count=None, dry_run=False, ): csp_solver_config = csp_solver.get_valid_csp_solver_config( minisat_path=minisat, sugarjar_path=sugar_jar, tmp_folder=tmp_folder ) actors=[RemoteActor(actor_uri) for actor_uri in actor_uris] pool_kwargs = {} if worker_count: pool_kwargs['processes'] = worker_count import multiprocessing pool = multiprocessing.Pool(**pool_kwargs) actor = ControllerActor( actors=actors, csp_solver_config=csp_solver_config, multiprocessing_pool=pool ) if not skip_actor_response_test: # test is actors of a ControllerActor exist # to prevent errors later for actor in actor._actors: import urllib2 try: value = actor.get_value() assert type(value) == int except urllib2.URLError as exc: print("Error while checking {0}: {1}".format(actor, exc.reason)) import sys sys.exit(1) print("All actors exist and respond as expected") kw = dict( host_port_tuple=(host_name, port), actor=actor, log_requests=log_requests ) if dry_run: print("Would start an actor controller on {0} " "but this is a test run".format(kw)) return kw try: start_actor_server(**kw) except KeyboardInterrupt: pool.terminate() except Exception: pool.terminate() finally: pool.join()
import os import csp_solver sugarjar_path = os.path.abspath( os.path.join(os.path.dirname(__file__), 'sugar-v1-15-0.jar')) csp_solver_config = csp_solver.get_valid_csp_solver_config( sugarjar_path=sugarjar_path)