Permalink
Browse files

fix test case for single redis server in cluster

  • Loading branch information...
1 parent 04e7a7f commit 73dbef1d39ab2335d7c8f6f68118eecf82710350 @salimane committed Oct 5, 2012
Showing with 23 additions and 13 deletions.
  1. +6 −5 rediscluster/cluster_client.py
  2. +17 −8 tests/cluster_commands.py
@@ -93,15 +93,15 @@ def __init__(self, cluster={}, db=0):
for alias, server in iteritems(cluster['nodes']):
try:
self.__redis = redis.StrictRedis(db=db, **server)
- info = self.__redis.info()
- if alias in slaves and info['role'] == 'master':
+ info = self.__redis.info()
+ if alias in slaves and info['role'] == 'master':
raise redis.DataError(
"rediscluster: server %s is not a slave." % (server,))
except Exception as e:
#if node is slave and is down, replace its connection with its master's
try:
ms = [k for k, v in iteritems(cluster['master_of'])
- if v == alias and (info['role'] == 'slave' or cluster['nodes'][k] == cluster['nodes'][v])][0]
+ if v == alias and (info['role'] == 'slave' or cluster['nodes'][k] == cluster['nodes'][v])][0]
except IndexError:
ms = None
@@ -170,7 +170,7 @@ def function(*args, **kwargs):
return result
return function
-
+
def _getnodenamefor(self, name):
"Return the node name where the ``name`` would land to"
return 'node_' + str(
@@ -201,7 +201,8 @@ def __delitem__(self, *names):
def object(self, infotype, key):
"Return the encoding, idletime, or refcount about the key"
- redisent = self.redises[self.cluster['master_of'][self._getnodenamefor(key)]]
+ redisent = self.redises[self.cluster['master_of'][
+ self._getnodenamefor(key)]]
return getattr(redisent, 'object')(infotype, key)
def _rc_brpoplpush(self, src, dst, timeout=0):
@@ -43,9 +43,13 @@ def test_dbsize(self):
self.client['a'] = 'foo'
self.client['b'] = 'foo'
sizeno = 0
- for size in dictvalues(self.client.dbsize()):
- sizeno += size
- self.assertEquals(sizeno, 2 * self.client.no_servers)
+ sizehash = {}
+ for node, size in iteritems(self.client.dbsize()):
+ if size and ((self.client.cluster['nodes'][node]['host'] + str(self.client.cluster['nodes'][node]['port'])) not in sizehash):
+ sizeno += size
+ sizehash[self.client.cluster['nodes'][node]['host']
+ + str(self.client.cluster['nodes'][node]['port'])] = size
+ self.assertEquals(sizeno, 2 * len(sizehash))
def test_getnodefor(self):
self.client['bar'] = 'foo'
@@ -120,13 +124,18 @@ def test_info(self):
self.client['a'] = 'foo'
self.client.set('b', 'foo')
kno = 0
- for info in dictvalues(self.client.info()):
+ knohash = {}
+ for node, info in iteritems(self.client.info()):
self.assert_(isinstance(info, dict))
try:
- kno += info['db4']['keys']
+ k = info['db4']['keys']
+ if k and ((self.client.cluster['nodes'][node]['host'] + str(self.client.cluster['nodes'][node]['port'])) not in knohash):
+ kno += k
+ knohash[self.client.cluster['nodes'][node]['host']
+ + str(self.client.cluster['nodes'][node]['port'])] = k
except KeyError:
pass
- self.assertEquals(kno, 2 * self.client.no_servers)
+ self.assertEquals(kno, 2 * len(knohash))
def test_lastsave(self):
for data in dictvalues(self.client.lastsave()):
@@ -145,7 +154,7 @@ def test_ping(self):
def test_time(self):
for info in dictvalues(self.client.info()):
version = info['redis_version']
- if StrictVersion(version) < StrictVersion('2.6.0'):
+ if StrictVersion(version) < StrictVersion('2.5.0'):
try:
raise unittest.SkipTest()
except AttributeError:
@@ -222,7 +231,7 @@ def test_get_set_bit(self):
def test_bitcount(self):
for info in dictvalues(self.client.info()):
version = info['redis_version']
- if StrictVersion(version) < StrictVersion('2.6.0'):
+ if StrictVersion(version) < StrictVersion('2.5.0'):
try:
raise unittest.SkipTest()
except AttributeError:

0 comments on commit 73dbef1

Please sign in to comment.