Esempio n. 1
0
    def receive(self, context: AbstractContext) -> None:
        msg = context.message
        if isinstance(msg, RemoteTerminate):
            self.__watched.pop(msg.watcher.id, 'None')
            self.__watcher.pop(msg.watchee.id, 'None')
            t = Terminated(who=msg.watchee, address_terminated=True)
            msg.watcher.send_system_message(t)

            return None

        if isinstance(msg, EndpointTerminatedEvent):
            for id, pid in self.__watched.items():
                t = Terminated(who=pid, address_terminated=True)
                watcher = PID(ProcessRegistry().Address, id, None)
                watcher.send_system_message(t)

            return None

        if isinstance(msg, RemoteUnwatch):
            self.__watched[msg.watcher.id] = None
            self.__watcher[msg.watchee.id] = None

            w = Unwatch(msg.watcher)
            msg.watchee.send_system_message(w)

            return None

        if isinstance(msg, RemoteWatch):
            self.__watched[msg.watcher.id] = msg.watchee
            self.__watcher[msg.watchee.id] = msg.watcher

            w = Watch(msg.watcher)
            msg.watchee.send_system_message(w)

            return None

        return None
def test_get_deadletter():
    _pid = mock.Mock()
    _pid.address = 'other_host'
    _pid.pid = '9999'
    assert isinstance(ProcessRegistry().get(_pid), DeadLettersProcess) is True
def test_get_nonhost(nohost: ProcessRegistry, mock_process):
    _pid = ProcessRegistry().add('new_id', mock_process)
    assert ProcessRegistry().get(_pid) == mock_process
def test_remove(nohost: ProcessRegistry, mock_process):
    _pid = ProcessRegistry().add('new_id', mock_process)
    assert ProcessRegistry().get(_pid) == mock_process
    ProcessRegistry().remove(_pid)
    assert isinstance(ProcessRegistry().get(_pid), DeadLettersProcess) is True
def test_add(nohost: ProcessRegistry, mock_process):
    _pid = ProcessRegistry().add('new_id', mock_process)
    assert _pid.address == ProcessRegistry().address
    assert _pid.id == 'new_id'
    assert _pid.process == mock_process
def test_next_id(nohost: ProcessRegistry):
    assert nohost.next_id() == '1'
def test_set_address(nohost: ProcessRegistry):
    nohost.address = 'new_host'
    assert nohost.address == 'new_host'
def nohost():
    return ProcessRegistry()