def test_buildProtocol(self): f = MemCacheClientFactory() addy = IPv4Address('TCP', 'ahost', 1234) p = f.buildProtocol(addy, timeOut=123) self.assertIsInstance(p, ConnectingMemCacheProtocol) self.assertEqual(p.persistentTimeOut, 123) self.assertEqual(str(p), "memcache[%s]" % addy)
def makeTestConnections(client): client.factories = [] transports = [] for addr in client.hosts: factory = MemCacheClientFactory() client.factories.append(factory) proto = factory.buildProtocol(addr, timeOut=None) transport = StringTransportWithDisconnection() transport.protocol = proto proto.makeConnection(transport) transports.append(transport) return transports
def connect(self): self.factories = [] for hp in self.hosts: if isinstance(hp, tuple): host, port = hp elif isinstance(hp, str): host, port = hp, 11211 else: raise InvalidHostPortError( "Connection info should be either hostnames or host/port tuples" ) factory = MemCacheClientFactory() reactor.connectTCP(host, port, factory) self.factories.append(factory) # fire callback when all connections have been established yield DeferredList([factory.deferred for factory in self.factories]) returnValue(self)