示例#1
0
    def test_endpointConnectingCancelled(self):
        """
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} is errbacked with an expected
        L{ConnectingCancelledError} exception.
        """
        mreactor = MemoryReactor()

        clientFactory = object()

        ep, ignoredArgs, address = self.createClientEndpoint(
            mreactor, clientFactory)

        d = ep.connect(clientFactory)

        receivedFailures = []

        def checkFailure(f):
            receivedFailures.append(f)

        d.addErrback(checkFailure)

        d.cancel()

        self.assertEquals(len(receivedFailures), 1)

        failure = receivedFailures[0]

        self.assertIsInstance(failure.value, error.ConnectingCancelledError)
        self.assertEquals(failure.value.address, address)
示例#2
0
    def test_endpointConnectSuccess(self):
        """
        A client endpoint can connect and returns a deferred who gets called
        back with a protocol instance.
        """
        proto = object()
        mreactor = MemoryReactor()

        clientFactory = object()

        ep, expectedArgs, ignoredDest = self.createClientEndpoint(
            mreactor, clientFactory)

        d = ep.connect(clientFactory)

        receivedProtos = []

        def checkProto(p):
            receivedProtos.append(p)

        d.addCallback(checkProto)

        factory = self.retrieveConnectedFactory(mreactor)
        factory._onConnection.callback(proto)
        self.assertEquals(receivedProtos, [proto])

        expectedClients = self.expectedClients(mreactor)

        self.assertEquals(len(expectedClients), 1)
        self.assertConnectArgs(expectedClients[0], expectedArgs)
示例#3
0
    def test_endpointListenNonDefaultArgs(self):
        """
        The endpoint should pass it's listenArgs parameter to the reactor's
        listen methods.
        """
        factory = object()

        mreactor = MemoryReactor()

        ep, expectedArgs, ignoredHost = self.createServerEndpoint(
            mreactor, factory, **self.listenArgs())

        ep.listen(factory)

        expectedServers = self.expectedServers(mreactor)

        self.assertEquals(expectedServers, [expectedArgs])
示例#4
0
    def test_endpointConnectNonDefaultArgs(self):
        """
        The endpoint should pass it's connectArgs parameter to the reactor's
        listen methods.
        """
        factory = object()

        mreactor = MemoryReactor()

        ep, expectedArgs, ignoredHost = self.createClientEndpoint(
            mreactor, factory, **self.connectArgs())

        ep.connect(factory)

        expectedClients = self.expectedClients(mreactor)

        self.assertEquals(len(expectedClients), 1)
        self.assertConnectArgs(expectedClients[0], expectedArgs)
示例#5
0
    def test_endpointListenSuccess(self):
        """
        An endpoint can listen and returns a deferred that gets called back
        with a port instance.
        """
        mreactor = MemoryReactor()

        factory = object()

        ep, expectedArgs, expectedHost = self.createServerEndpoint(
            mreactor, factory)

        d = ep.listen(factory)

        receivedHosts = []

        def checkPortAndServer(port):
            receivedHosts.append(port.getHost())

        d.addCallback(checkPortAndServer)

        self.assertEquals(receivedHosts, [expectedHost])
        self.assertEquals(self.expectedServers(mreactor), [expectedArgs])
示例#6
0
 def connectSSL(self, *a, **kw):
     MemoryReactor.connectSSL(self, *a, **kw)
     connector = MemoryConnector()
     self.connectors.append(connector)
     return connector
示例#7
0
 def __init__(self):
     MemoryReactor.__init__(self)
     Clock.__init__(self)
     self.connectors = []
示例#8
0
 def connectSSL(self, *a, **kw):
     MemoryReactor.connectSSL(self, *a, **kw)
     connector = MemoryConnector()
     self.connectors.append(connector)
     return connector
示例#9
0
 def __init__(self):
     MemoryReactor.__init__(self)
     Clock.__init__(self)
     self.connectors = []