Пример #1
0
    def setUp(self):
        self.a1 = Actor([5, 6])
        self.a2 = Actor([7, 8])
        self.a3 = ControllerActor(
            actors=[self.a1, self.a2],
            csp_solver_config=csp_solver_config,
        )

        self.a4 = Actor([-5, -6])
        self.a5 = Actor([-7, -8])
        self.a6 = ControllerActor(
            actors=[self.a4, self.a5],
            csp_solver_config=csp_solver_config,
        )
Пример #2
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()
Пример #3
0
 def test_get_value_range(self):
     a3 = ControllerActor(
         actors=[self.a1, self.a2],
         csp_solver_config=csp_solver_config,
     )
     a3_value_range = a3.get_value_range()
     assert a3_value_range == set([-9, -8, -7, -6, -5, -4]), \
         a3_value_range
Пример #4
0
    def test_set_value_failure_str(self):
        a7 = ControllerActor(
            actors=[self.a3, self.a6],
            csp_solver_config=csp_solver_config,
        )

        a7_vr = a7.get_value_range()
        assert a7_vr == [-2, -1, 0, 1, 2], a7_vr
Пример #5
0
 def setUp(self):
     uri, self._actor_server_process = start_actor_server(
         start_in_background_thread=True,
         actor=ControllerActor(
             actors=[Actor(value_range=[1, 2, 3])],
             csp_solver_config=csp_solver_config,
         ))
     self.a1 = RemoteActor(uri=uri)
     time.sleep(.8)
Пример #6
0
 def test_set_value_int_out_of_range(self):
     a3 = ControllerActor(
         actors=[self.a1, self.a2],
         csp_solver_config=csp_solver_config,
     )
     self.failUnlessRaises(
         NotSolvable,
         a3.set_value,
         0
     )
Пример #7
0
 def test_set_value_string_invalid(self):
     a3 = ControllerActor(
         actors=[self.a1, self.a2],
         csp_solver_config=csp_solver_config,
     )
     self.failUnlessRaises(
         NotSolvable,
         a3.set_value,
         "null"
     )
Пример #8
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
Пример #9
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
Пример #10
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
Пример #11
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()
Пример #12
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
        )
Пример #13
0
 def test_init(self):
     a3 = ControllerActor(
         actors=[self.a1, self.a2],
         csp_solver_config=csp_solver_config,
     )
     assert a3.id