예제 #1
0
파일: threads.py 프로젝트: japaks/pulsar
 def test_pool(self):
     pool = self.get_pool(threads=2)
     self.assertEqual(pool._state, 0)
     self.assertEqual(pool.status, 'running')
     self.assertEqual(pool.event_loop, get_event_loop())
     self.assertNotEqual(pool.event_loop, get_request_loop())
     #give a chance to start the pool
     yield async_while(3, lambda: not pool.num_threads)
     self.assertEqual(pool.num_threads, 2)
     pool.close()
     self.assertEqual(pool._state, 1)
     self.assertEqual(pool.status, 'closed')
     pool.join()
     yield async_while(3, lambda: pool.num_threads)
     self.assertFalse(pool.num_threads)
예제 #2
0
 def test_pool(self):
     pool = self.get_pool(threads=2)
     self.assertEqual(pool._state, 0)
     self.assertEqual(pool.status, 'running')
     self.assertEqual(pool.event_loop, get_event_loop())
     self.assertNotEqual(pool.event_loop, get_request_loop())
     #give a chance to start the pool
     yield async_while(3, lambda: not pool.num_threads)
     self.assertEqual(pool.num_threads, 2)
     pool.close()
     self.assertEqual(pool._state, 1)
     self.assertEqual(pool.status, 'closed')
     pool.join()
     yield async_while(3, lambda: pool.num_threads)
     self.assertFalse(pool.num_threads)
     
     
예제 #3
0
 def testTimeout(self):
     '''Test a bogus actor for timeout.'''
     arbiter = pulsar.get_actor()
     self.assertTrue(arbiter.is_arbiter())
     name = 'bogus-timeout-%s' % self.concurrency
     proxy = yield self.spawn(name=name, timeout=1)
     self.assertEqual(proxy.name, name)
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     proxy = arbiter.managed_actors[proxy.aid]
     yield send(proxy, 'run', cause_timeout)
     # The arbiter should soon start to stop the actor
     interval = 2 * MONITOR_TASK_PERIOD
     yield pulsar.async_while(interval, lambda: not proxy.stopping_start)
     self.assertTrue(proxy.stopping_start)
     #
     yield pulsar.async_while(interval,
                              lambda: proxy.aid in arbiter.managed_actors)
     self.assertFalse(proxy.aid in arbiter.managed_actors)
예제 #4
0
 def testTimeout(self):
     '''Test a bogus actor for timeout.'''
     arbiter = pulsar.get_actor()
     self.assertTrue(arbiter.is_arbiter())
     name = 'bogus-timeout-%s' % self.concurrency
     proxy = yield self.spawn_actor(name=name, timeout=1)
     self.assertEqual(proxy.name, name)
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     proxy = arbiter.managed_actors[proxy.aid]
     yield send(proxy, 'run', cause_timeout)
     # The arbiter should soon start to stop the actor
     interval = 2*MONITOR_TASK_PERIOD
     yield pulsar.async_while(interval,
                              lambda: not proxy.stopping_start)
     self.assertTrue(proxy.stopping_start)
     #
     yield pulsar.async_while(interval,
                              lambda: proxy.aid in arbiter.managed_actors)
     self.assertFalse(proxy.aid in arbiter.managed_actors)
예제 #5
0
 def test_terminate(self):
     arbiter = pulsar.get_actor()
     self.assertTrue(arbiter.is_arbiter())
     name = 'bogus-term-%s' % self.concurrency
     proxy = yield self.spawn(name=name, timeout=1)
     self.assertEqual(proxy.name, name)
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     proxy = arbiter.managed_actors[proxy.aid]
     #
     result = yield send(proxy, 'run', cause_terminate)
     #
     # The arbiter should soon start stop the actor
     interval = 3 * MONITOR_TASK_PERIOD
     yield pulsar.async_while(2 * MONITOR_TASK_PERIOD,
                              lambda: not proxy.stopping_start)
     self.assertTrue(proxy.stopping_start)
     #
     yield pulsar.async_while(1.5 * ACTOR_ACTION_TIMEOUT,
                              lambda: proxy.aid in arbiter.managed_actors)
     self.assertTrue(proxy in arbiter.terminated_actors)
     self.assertFalse(proxy.aid in arbiter.managed_actors)
예제 #6
0
 def test_terminate(self):
     arbiter = pulsar.get_actor()
     self.assertTrue(arbiter.is_arbiter())
     name = 'bogus-term-%s' % self.concurrency
     proxy = yield self.spawn_actor(name=name, timeout=1)
     self.assertEqual(proxy.name, name)
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     proxy = arbiter.managed_actors[proxy.aid]
     #
     result = yield send(proxy, 'run', cause_terminate)
     #
     # The arbiter should soon start stop the actor
     interval = 3*MONITOR_TASK_PERIOD
     yield pulsar.async_while(2*MONITOR_TASK_PERIOD,
                              lambda: not proxy.stopping_start)
     self.assertTrue(proxy.stopping_start)
     #
     yield pulsar.async_while(1.5*ACTOR_ACTION_TIMEOUT,
                              lambda: proxy.aid in arbiter.managed_actors)
     self.assertTrue(proxy in arbiter.terminated_actors)
     self.assertFalse(proxy.aid in arbiter.managed_actors)
예제 #7
0
 def test_spawn_from_actor(self):
     proxy = yield from self.spawn_actor(name="spawning-actor-%s" % self.concurrency)
     arbiter = pulsar.get_actor()
     self.assertTrue(repr(proxy).startswith("spawning-actor-"))
     self.assertEqual(proxy, proxy.proxy)
     proxy_monitor = arbiter.get_actor(proxy.aid)
     self.assertFalse(proxy != proxy_monitor)
     #
     # do the spawning
     name = "spawned-actor-%s-from-actor" % self.concurrency
     aid = yield from send(proxy, "run", spawn_actor_from_actor, name)
     self.assertTrue(aid)
     proxy_monitor2 = arbiter.get_actor(aid)
     self.assertEqual(proxy_monitor2.name, name)
     self.assertNotEquals(proxy_monitor, proxy_monitor2)
     #
     # stop them
     yield from self.stop_actors(proxy, proxy_monitor2)
     is_alive = yield from async_while(3, proxy_monitor.is_alive)
     self.assertFalse(is_alive)
     is_alive = yield from async_while(3, proxy_monitor2.is_alive)
     self.assertFalse(is_alive)
예제 #8
0
 def test_simple_spawn(self):
     """Test start and stop for a standard actor on the arbiter domain."""
     proxy = yield from self.spawn_actor(name="simple-actor-on-%s" % self.concurrency)
     arbiter = pulsar.get_actor()
     proxy_monitor = arbiter.get_actor(proxy.aid)
     self.assertEqual(proxy_monitor, proxy)
     yield from self.wait.assertEqual(send(proxy, "ping"), "pong")
     yield from self.wait.assertEqual(send(proxy.proxy, "echo", "Hello!"), "Hello!")
     # We call the ActorTestMixin.stop_actors method here, since the
     # ActorTestMixin.tearDown method is invoked on the test-worker domain
     # (here we are in the arbiter domain)
     yield from self.stop_actors(proxy)
     is_alive = yield from async_while(3, proxy_monitor.is_alive)
     self.assertFalse(is_alive)
예제 #9
0
 def test_spawn_from_actor(self):
     proxy = yield from self.spawn_actor(
         name='spawning-actor-%s' % self.concurrency)
     arbiter = pulsar.get_actor()
     self.assertTrue(repr(proxy).startswith('spawning-actor-'))
     self.assertEqual(proxy, proxy.proxy)
     proxy_monitor = arbiter.get_actor(proxy.aid)
     self.assertFalse(proxy != proxy_monitor)
     #
     # do the spawning
     name = 'spawned-actor-%s-from-actor' % self.concurrency
     aid = yield from send(proxy, 'run', spawn_actor_from_actor, name)
     self.assertTrue(aid)
     proxy_monitor2 = arbiter.get_actor(aid)
     self.assertEqual(proxy_monitor2.name, name)
     self.assertNotEquals(proxy_monitor, proxy_monitor2)
     #
     # stop them
     yield from self.stop_actors(proxy, proxy_monitor2)
     is_alive = yield from async_while(3, proxy_monitor.is_alive)
     self.assertFalse(is_alive)
     is_alive = yield from async_while(3, proxy_monitor2.is_alive)
     self.assertFalse(is_alive)
예제 #10
0
 def testSimpleSpawn(self):
     '''Test start and stop for a standard actor on the arbiter domain.'''
     proxy = yield self.spawn(name='simple-actor-on-%s' % self.concurrency)
     arbiter = pulsar.get_actor()
     proxy_monitor = arbiter.get_actor(proxy.aid)
     self.assertEqual(proxy_monitor, proxy)
     yield self. async .assertEqual(send(proxy, 'ping'), 'pong')
     yield self. async .assertEqual(send(proxy.proxy, 'echo', 'Hello!'),
                                    'Hello!')
     # We call the ActorTestMixin.stop_actors method here, since the
     # ActorTestMixin.tearDown method is invoked on the test-worker domain
     # (here we are in the arbiter domain)
     yield self.stop_actors(proxy)
     is_alive = yield async_while(3, proxy_monitor.is_alive)
     self.assertFalse(is_alive)
예제 #11
0
파일: actor.py 프로젝트: BazookaShao/pulsar
 def testSimpleSpawn(self):
     '''Test start and stop for a standard actor on the arbiter domain.'''
     proxy = yield self.spawn(name='simple-actor-on-%s' % self.concurrency)
     arbiter = pulsar.get_actor()
     proxy_monitor = arbiter.get_actor(proxy.aid)
     self.assertEqual(proxy_monitor, proxy)
     yield self.async.assertEqual(send(proxy, 'ping'), 'pong')
     yield self.async.assertEqual(send(proxy.proxy, 'echo', 'Hello!'),
                                  'Hello!')
     # We call the ActorTestMixin.stop_actors method here, since the
     # ActorTestMixin.tearDown method is invoked on the test-worker domain
     # (here we are in the arbiter domain)
     yield self.stop_actors(proxy)
     is_alive = yield async_while(3, proxy_monitor.is_alive)
     self.assertFalse(is_alive)
예제 #12
0
파일: eventloop.py 프로젝트: japaks/pulsar
 def test_echo_serve(self):
     loop = get_event_loop()
     server = TcpServer(loop, '127.0.0.1', 0, EchoServerProtocol)
     yield server.start_serving()
     sock = server.sock
     fn = sock.fileno()
     self.assertFalse(is_socket_closed(sock))
     client = Echo()
     address = sock.getsockname()
     result = yield client.request(address, b'Hello!')
     self.assertEqual(result, b'Hello!')
     self.assertEqual(server.concurrent_connections, 1)
     result = yield client.request(address, b'ciao')
     self.assertEqual(result, b'ciao')
     self.assertEqual(server.concurrent_connections, 1)
     yield server.stop_serving()
     yield async_while(3, lambda: not is_socket_closed(sock))
     self.assertTrue(is_socket_closed(sock))
예제 #13
0
 def test_actor_termination(self):
     '''Terminate the remote actor via the concurreny terminate method.'''
     arbiter = pulsar.get_actor()
     self.assertTrue(arbiter.is_arbiter())
     name = 'actor-term-%s' % self.concurrency
     proxy = yield self.spawn(name=name)
     self.assertEqual(proxy.name, name)
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     proxy = arbiter.managed_actors[proxy.aid]
     #
     # terminate the actor and see what appens
     proxy.terminate()
     #
     # The arbiter should soon start stop the actor
     interval = 3 * MONITOR_TASK_PERIOD
     #
     yield pulsar.async_while(interval,
                              lambda: proxy.aid in arbiter.managed_actors)
     self.assertFalse(proxy in arbiter.terminated_actors)
     self.assertFalse(proxy.aid in arbiter.managed_actors)
예제 #14
0
 def __test_actor_termination(self):
     '''Terminate the remote actor via the concurreny terminate method.'''
     arbiter = pulsar.get_actor()
     self.assertTrue(arbiter.is_arbiter())
     name = 'actor-term-%s' % self.concurrency
     proxy = yield self.spawn_actor(name=name)
     self.assertEqual(proxy.name, name)
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     proxy = arbiter.managed_actors[proxy.aid]
     #
     # terminate the actor and see what appens
     proxy.terminate()
     #
     # The arbiter should soon start stop the actor
     interval = 3*MONITOR_TASK_PERIOD
     #
     yield pulsar.async_while(interval,
                              lambda: proxy.aid in arbiter.managed_actors)
     self.assertFalse(proxy in arbiter.terminated_actors)
     self.assertFalse(proxy.aid in arbiter.managed_actors)
예제 #15
0
 def test_config_command(self):
     proxy = yield from self.spawn_actor(name="actor-test-config-%s" % self.concurrency)
     arbiter = pulsar.get_actor()
     proxy_monitor = arbiter.get_actor(proxy.aid)
     result = yield from send(proxy, "config", "khjkh", "name")
     self.assertEqual(result, None)
     result = yield from send(proxy, "config", "get", "concurrency")
     self.assertEqual(result, self.concurrency)
     result = yield from send(proxy, "config", "get", "concurrency", "foo")
     self.assertEqual(result, None)
     #
     result = yield from send(proxy, "config", "set", "max_requests", 1000, 1000)
     self.assertEqual(result, None)
     result = yield from send(proxy, "config", "set", "max_requests", 1000)
     self.assertEqual(result, True)
     result = yield from send(proxy, "config", "get", "max_requests")
     self.assertEqual(result, 1000)
     #
     yield from self.stop_actors(proxy)
     is_alive = yield from async_while(3, proxy_monitor.is_alive)
     self.assertFalse(is_alive)
예제 #16
0
 def test_config_command(self):
     proxy = yield from self.spawn_actor(name='actor-test-config-%s' %
                                         self.concurrency)
     arbiter = pulsar.get_actor()
     proxy_monitor = arbiter.get_actor(proxy.aid)
     result = yield from send(proxy, 'config', 'khjkh', 'name')
     self.assertEqual(result, None)
     result = yield from send(proxy, 'config', 'get', 'concurrency')
     self.assertEqual(result, self.concurrency)
     result = yield from send(proxy, 'config', 'get', 'concurrency', 'foo')
     self.assertEqual(result, None)
     #
     result = yield from send(proxy, 'config', 'set', 'max_requests', 1000,
                              1000)
     self.assertEqual(result, None)
     result = yield from send(proxy, 'config', 'set', 'max_requests', 1000)
     self.assertEqual(result, True)
     result = yield from send(proxy, 'config', 'get', 'max_requests')
     self.assertEqual(result, 1000)
     #
     yield from self.stop_actors(proxy)
     is_alive = yield from async_while(3, proxy_monitor.is_alive)
     self.assertFalse(is_alive)
예제 #17
0
파일: actor.py 프로젝트: Danzeer/pulsar
 def test_config_command(self):
     proxy = yield from self.spawn_actor(
         name='actor-test-config-%s' % self.concurrency)
     arbiter = pulsar.get_actor()
     proxy_monitor = arbiter.get_actor(proxy.aid)
     result = yield from send(proxy, 'config', 'khjkh', 'name')
     self.assertEqual(result, None)
     result = yield from send(proxy, 'config', 'get', 'concurrency')
     self.assertEqual(result, self.concurrency)
     result = yield from send(proxy, 'config', 'get', 'concurrency', 'foo')
     self.assertEqual(result, None)
     #
     result = yield from send(proxy, 'config', 'set', 'max_requests',
                              1000, 1000)
     self.assertEqual(result, None)
     result = yield from send(proxy, 'config', 'set', 'max_requests',
                              1000)
     self.assertEqual(result, True)
     result = yield from send(proxy, 'config', 'get', 'max_requests')
     self.assertEqual(result, 1000)
     #
     yield from self.stop_actors(proxy)
     is_alive = yield from async_while(3, proxy_monitor.is_alive)
     self.assertFalse(is_alive)
예제 #18
0
파일: tests.py 프로젝트: BazookaShao/pulsar
 def testTestWorker(self):
     arbiter = pulsar.get_actor()
     monitor = arbiter.get_actor('shell')
     yield async_while(5, lambda: not monitor.managed_actors)
     self.assertEqual(len(monitor.managed_actors), 1)
예제 #19
0
 def testTestWorker(self):
     arbiter = pulsar.get_actor()
     monitor = arbiter.get_actor('shell')
     yield async_while(5, lambda: not monitor.managed_actors)
     self.assertEqual(len(monitor.managed_actors), 1)
예제 #20
0
파일: tests.py 프로젝트: robgil/pulsar
 def test_test_worker(self):
     arbiter = get_actor()
     monitor = arbiter.get_actor('shell')
     yield async_while(2, lambda: not monitor.managed_actors)
     self.assertEqual(len(monitor.managed_actors), 0)
예제 #21
0
파일: tests.py 프로젝트: JinsongBian/pulsar
 def test_test_worker(self):
     arbiter = get_actor()
     monitor = arbiter.get_actor('shell')
     yield async_while(2, lambda: not monitor.managed_actors)
     self.assertEqual(len(monitor.managed_actors), 0)