def do_setup(_res): self.factory = RedisClientFactory() reactor.connectTCP(REDIS_HOST, REDIS_PORT, self.factory) d = self.factory.deferred def cannot_connect(_res): raise unittest.SkipTest('Cannot connect to Redis.') d.addErrback(cannot_connect) return d
class TestFactory(CommandsTestBase): def setUp(self): d = CommandsTestBase.setUp(self) def do_setup(_res): self.factory = RedisClientFactory() reactor.connectTCP(REDIS_HOST, REDIS_PORT, self.factory) d = self.factory.deferred def cannot_connect(_res): raise unittest.SkipTest('Cannot connect to Redis.') d.addErrback(cannot_connect) return d d.addCallback(do_setup) return d def tearDown(self): CommandsTestBase.tearDown(self) self.factory.continueTrying = 0 self.factory.stopTrying() if self.factory.client: self.factory.client.setTimeout(None) self.factory.client.transport.loseConnection() @defer.inlineCallbacks def test_reconnect(self): a = yield self.factory.client.info() self.assertTrue('uptime_in_days' in a) # teardown the connection self.factory.client.transport.loseConnection() # wait until reconnected a = yield self.factory.deferred a = yield self.factory.client.info() self.assertTrue('uptime_in_days' in a) timeout = 4
class TestFactory(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self.factory = RedisClientFactory() reactor.connectTCP(REDIS_HOST, REDIS_PORT, self.factory) yield self.factory.deferred def tearDown(self): self.factory.stopTrying() self.factory.client.transport.loseConnection() @defer.inlineCallbacks def test_reconnect(self): a = yield self.factory.client.info() self.assertTrue('uptime_in_days' in a) # teardown the connection self.factory.client.transport.loseConnection() # wait until reconnected a = yield self.factory.deferred a = yield self.factory.client.info() self.assertTrue('uptime_in_days' in a)
def setUp(self): self.factory = RedisClientFactory() reactor.connectTCP(REDIS_HOST, REDIS_PORT, self.factory) yield self.factory.deferred
def clientConnectionFailed(self, connector, reason): print "WARNING: Redis Command Connection Failed to Reconnect. Probably still dropping messages!" RedisClientFactory.clientConnectionFailed(self, connector, reason)
def clientConnectionLost(self, connector, reason): print "WARNING: Redis Command Connection Lost. Probably dropping messages!" RedisClientFactory.clientConnectionLost(self, connector, reason)
def buildProtocol(self, addr): print "Connected to redis (Command Connection)." protocol = RedisClientFactory.buildProtocol(self, addr) self.services.redis = protocol return protocol
def __init__(self, services, *args, **kwargs): RedisClientFactory.__init__(self, *args, **kwargs) self.services = services