Beispiel #1
0
    def makeCluster(self, rack_controller, *commands):
        """Make and add a new stub cluster connection with the `commands`.

        See `make_amp_protocol_factory` for details.

        Note that if the ``Authenticate`` call is not amongst `commands`,
        it will be added. In addition, its action is to call
        ``RegisterRackController`` so the connction is fully made and the
        connection wil be added to the RPC service's list of connections.

        :return: The protocol instance created.
        """
        if cluster.Authenticate not in commands:
            commands = commands + (cluster.Authenticate, )
        protocol_factory = make_amp_protocol_factory(*commands)
        protocol = protocol_factory()

        protocol.Authenticate.side_effect = (
            lambda _, message: authenticate_with_secret(self.secret, message))
        self.addCluster(protocol, rack_controller).wait(5)
        # The connection is now established, but there is a brief
        # handshake that takes place immediately upon connection.  We
        # wait for that to finish before returning.
        getClientFor(rack_controller.system_id, timeout=5)
        return protocol
Beispiel #2
0
    def makeCluster(self, controller, *commands):
        """Make and add a new stub cluster connection with the `commands`.

        See `make_amp_protocol_factory` for details.

        Note that if the ``Identify`` call is not amongst `commands`, it will
        be added. In addition, its return value is also set to return the
        system_id of `controller`. There's a good reason: the first thing that
        `RegionServer` does when a connection is made is call `Identify`. This
        has to succeed or the connection will never been added to the RPC
        service's list of connections.

        :return: A 2-tuple of the protocol instance created and the
            py:class:`twisted.test.iosim.IOPump` as returned by `addCluster`.
        """
        if cluster.Identify not in commands:
            commands = commands + (cluster.Identify, )
        if cluster.Authenticate not in commands:
            commands = commands + (cluster.Authenticate, )
        protocol_factory = make_amp_protocol_factory(*commands)
        protocol = protocol_factory()
        ident_response = {"ident": controller.system_id}
        protocol.Identify.side_effect = lambda _: defer.succeed(ident_response.
                                                                copy())
        protocol.Authenticate.side_effect = (
            lambda _, message: authenticate_with_secret(self.secret, message))
        return protocol, self.addCluster(protocol)