]> git.saurik.com Git - redis.git/blob - client-libraries/scala/src/test/scala/com/redis/RedisClusterSpec.scala
redis-cli now accepts a -r (repeat) switch. Still there is a memory leaks to fix
[redis.git] / client-libraries / scala / src / test / scala / com / redis / RedisClusterSpec.scala
1 import org.specs._
2 import com.redis._
3
4 import org.specs.mock.Mockito
5 import org.mockito.Mock._
6 import org.mockito.Mockito._
7 import org.mockito.Mockito.doNothing
8
9 object RedisClusterSpec extends Specification with Mockito {
10
11 "Redis Cluster" should {
12 var cluster: RedisCluster = null
13 var mockedRedis: Redis = null
14
15 doBefore {
16 cluster = new RedisCluster("localhost:11221", "localhost:99991")
17 mockedRedis = mock[Redis]
18 }
19
20 "print formatted client status" in {
21 cluster.toString must be matching("localhost:11221 <connected:false>, localhost:99991 <connected:false>")
22 }
23
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)
27 }
28
29 "use the default number of replicas" in {
30 cluster.replicas mustEqual 160
31 }
32
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
38 }
39
40 "connect all the redis instances" in {
41 cluster.cluster(1) = mockedRedis
42
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
49 }
50 }
51 }