Exemple #1
0
    def test_set_value_string(self):
        a3 = ControllerActor(
            actors=[self.a1, self.a2],
            csp_solver_config=csp_solver_config,
        )
        assert self.a1.get_value() == 1, self.a1.get_value()
        assert self.a2.get_value() == -10, self.a2.get_value()
        assert a3.get_value() == -9, a3.get_value()

        a3.set_value("-4")

        assert self.a1.get_value() == 3, self.a1.get_value()
        assert self.a2.get_value() == -7, self.a2.get_value()
        assert a3.get_value() == -4, a3.get_value()
        assert type(a3.get_value()) == int
Exemple #2
0
    def test_set_value_int(self):
        a3 = ControllerActor(
            actors=[self.a1, self.a2],
            csp_solver_config=csp_solver_config,
        )
        assert self.a1.get_value() == 1, self.a1.get_value()
        assert self.a2.get_value() == -10, self.a2.get_value()
        assert a3.get_value() == -9, a3.get_value()

        ret_val = a3.set_value(-4)

        assert ret_val == -4

        assert self.a1.get_value() == 3, self.a1.get_value()
        assert self.a2.get_value() == -7, self.a2.get_value()
        assert a3.get_value() == -4, a3.get_value()
Exemple #3
0
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()
    def test_set_value_failure_str(self):
        a7 = ControllerActor(
            actors=[self.a3, self.a6],
            csp_solver_config=csp_solver_config,
        )

        a7.set_value(0)

        a7_value = a7.get_value()
        assert a7_value == 0, a7_value
Exemple #5
0
    def test_set_value_failure_str(self):
        a7 = ControllerActor(
            actors=[self.a3, self.a6],
            csp_solver_config=csp_solver_config,
        )

        a7.set_value(0)

        a7_value = a7.get_value()
        assert a7_value == 0, a7_value
Exemple #6
0
    def test_get_value(self):
        a3 = ControllerActor(
            actors=[self.a1, self.a2],
            csp_solver_config=csp_solver_config,
        )

        assert self.a1.get_value() == 1, self.a1.get_value()
        assert self.a2.get_value() == -10, self.a2.get_value()

        a3_value = a3.get_value()
        assert type(a3_value) == int
        assert a3_value == -9
Exemple #7
0
    def test_set_value_float(self):
        a3 = ControllerActor(
            actors=[self.a1, self.a2],
            csp_solver_config=csp_solver_config,
        )
        assert self.a1.get_value() == 1, self.a1.get_value()
        assert self.a2.get_value() == -10, self.a2.get_value()
        assert a3.get_value() == -9, a3.get_value()

        ret_val = a3.set_value(-4.5)

        self.assertEqual(ret_val, -4)

        self.assertEqual(
            a3.get_value(), -4
        )

        self.assertEqual(
            self.a1.get_value(), 3
        )
        self.assertEqual(
            self.a1.get_value(), 3
        )
Exemple #8
0
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()