예제 #1
0
 def test_broadcast_sends_message_to_all_actors_of_given_class_name(self):
     ActorRegistry.broadcast({'command': 'foo'}, target_class='AnActor')
     for actor_ref in ActorRegistry.get_by_class(self.AnActor):
         received_messages = actor_ref.proxy().received_messages.get()
         self.assertTrue({'command': 'foo'} in received_messages)
     for actor_ref in ActorRegistry.get_by_class(self.BeeActor):
         received_messages = actor_ref.proxy().received_messages.get()
         self.assertTrue({'command': 'foo'} not in received_messages)
예제 #2
0
 def test_broadcast_sends_message_to_all_actors_of_given_class(self):
     ActorRegistry.broadcast({'command': 'foo'}, target_class=self.AnActor)
     for actor_ref in ActorRegistry.get_by_class(self.AnActor):
         received_messages = actor_ref.proxy().received_messages.get()
         self.assert_({'command': 'foo'} in received_messages)
     for actor_ref in ActorRegistry.get_by_class(self.BeeActor):
         received_messages = actor_ref.proxy().received_messages.get()
         self.assert_({'command': 'foo'} not in received_messages)
예제 #3
0
def test_broadcast_sends_message_to_all_actors_of_given_class_name(
        actor_a_class, actor_b_class):
    ActorRegistry.broadcast({'command': 'foo'}, target_class='ActorA')

    for actor_ref in ActorRegistry.get_by_class(actor_a_class):
        received_messages = actor_ref.proxy().received_messages.get()
        assert {'command': 'foo'} in received_messages

    for actor_ref in ActorRegistry.get_by_class(actor_b_class):
        received_messages = actor_ref.proxy().received_messages.get()
        assert {'command': 'foo'} not in received_messages
예제 #4
0
def test_broadcast_sends_message_to_all_actors_of_given_class_name(
    actor_a_class, actor_b_class
):
    ActorRegistry.broadcast({'command': 'foo'}, target_class='ActorA')

    for actor_ref in ActorRegistry.get_by_class(actor_a_class):
        received_messages = actor_ref.proxy().received_messages.get()
        assert {'command': 'foo'} in received_messages

    for actor_ref in ActorRegistry.get_by_class(actor_b_class):
        received_messages = actor_ref.proxy().received_messages.get()
        assert {'command': 'foo'} not in received_messages
예제 #5
0
 def send_event(self, event_name, data, player=None, client=None):
     if player:
         data['player'].update(player.get_stats_data())
     if client:
         c = data.get('client', {})
         c['device_type'] = client.device_type
         c['conn_type'] = client.conn_type
         c['client_timestamp'] = client.client_timestamp
         c['client_version'] = client.client_version
         c['device_os'] = client.device_os
         c['device_os_version'] = client.device_os_version
         c['openudid'] = client.openudid
         c['odin'] = client.odin
         c['mac_address'] = client.mac_address
         c['ios_ifa'] = client.ios_ifa
         c['android_id'] = client.android_id
         c['imei'] = client.imei
         c['android_ifa'] = client.android_ifa
         data['client'] = c
     msg = {"event_name": event_name,
            "timestamp": time.time(),
            "data": data}
     actor = ActorRegistry.get_by_class(StatsActor)
     actor = actor and actor[0] or StatsActor.start()
     actor.tell(msg)
예제 #6
0
def test_actors_may_be_looked_up_by_superclass(actor_a_class, a_actor_refs,
                                               b_actor_refs):
    result = ActorRegistry.get_by_class(actor_a_class)

    for a_actor in a_actor_refs:
        assert a_actor in result
    for b_actor in b_actor_refs:
        assert b_actor not in result
예제 #7
0
def test_actors_may_be_looked_up_by_superclass(
    actor_a_class, a_actor_refs, b_actor_refs
):
    result = ActorRegistry.get_by_class(actor_a_class)

    for a_actor in a_actor_refs:
        assert a_actor in result
    for b_actor in b_actor_refs:
        assert b_actor not in result
예제 #8
0
def test_register_get_by_filter(actor_class):
    actor_ref = actor_class().start()
    # 已经完成注册啦了.
    # step1 测试 urn查询
    assert ActorRegistry.get_by_urn(actor_ref.actor_urn) == actor_ref
    # step2 测试类名查询
    assert ActorRegistry.get_by_class(actor_ref.actor_class)[0] == actor_ref
    # # step3 测试类名字符查询
    assert ActorRegistry.get_by_class_name(
        'CustomThreadingActor')[0] == actor_ref
    ActorRegistry.stop_all()
예제 #9
0
 def test_actors_may_be_looked_up_by_superclass(self):
     result = ActorRegistry.get_by_class(AnActor)
     for a_actor in self.a_actors:
         self.assert_(a_actor in result)
     for b_actor in self.b_actors:
         self.assert_(b_actor not in result)
예제 #10
0
 def test_actors_may_be_looked_up_by_superclass(self):
     result = ActorRegistry.get_by_class(AnActor)
     for a_actor in self.a_actors:
         self.assertTrue(a_actor in result)
     for b_actor in self.b_actors:
         self.assertTrue(b_actor not in result)
예제 #11
0
def get_account():
    account = ActorRegistry.get_by_class(Account)
    return account and account[0] or Account.start()