4 import org.specs.mock.Mockito
5 import org.mockito.Mock._
6 import org.mockito.Mockito._
7 import org.mockito.Mockito.doNothing
9 object RedisClusterSpec extends Specification with Mockito {
11 "Redis Cluster" should {
12 var cluster: RedisCluster = null
13 var mockedRedis: Redis = null
16 cluster = new RedisCluster("localhost:11221", "localhost:99991")
17 mockedRedis = mock[Redis]
20 "print formatted client status" in {
21 cluster.toString must be matching("localhost:11221 <connected:false>, localhost:99991 <connected:false>")
24 "get the connection for the specified key" in {
25 cluster.getConnection("key") mustEqual Connection("localhost", 99991)
26 cluster.getConnection("anotherkey") mustEqual Connection("localhost", 11221)
29 "use the default number of replicas" in {
30 cluster.replicas mustEqual 160
33 "initialize cluster" in {
34 val initializedCluster = cluster.initialize_cluster
35 initializedCluster.size mustEqual 2
36 initializedCluster(0) mustEqual false
37 initializedCluster(1) mustEqual false
40 "connect all the redis instances" in {
41 cluster.cluster(1) = mockedRedis
43 cluster.cluster(1).connect returns true
44 val connectResult = cluster.connect
45 connectResult.size mustEqual 2
46 connectResult(0) mustEqual false
47 connectResult(1) mustEqual true
48 cluster.cluster(1).connect was called