]> git.saurik.com Git - redis.git/blob - client-libraries/scala/src/test/scala/com/redis/operations/NodeOperationsSpec.scala
629c46353134ce57cae58712eae9df5f7780a4c4
[redis.git] / client-libraries / scala / src / test / scala / com / redis / operations / NodeOperationsSpec.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 NodeOperationsSpec extends Specification with Mockito {
10
11 "Redis Client Node Operations" should {
12 var client: RedisTestClient = null
13 var connection: Connection = null
14
15 doBefore{
16 connection = mock[Connection]
17 client = new RedisTestClient(connection)
18 }
19
20 "save the db to disk" in {
21 connection.readBoolean returns true
22 client.save must beTrue
23 connection.write("SAVE\r\n") was called
24 }
25
26 "return the last time saved data to the db" in {
27 connection.readInt returns 1250421891
28 client.lastSave mustEqual 1250421891
29 connection.write("LASTSAVE\r\n") was called
30 }
31
32 "return all specified keys" in {
33 connection.readList returns List[String]("hola", null, null)
34 client.mget("a", "b", "c") mustEqual List[String]("hola", null, null)
35 connection.write("MGET a b c\r\n") was called
36 }
37
38 "return server info" in {
39 val sampleInfo = "res0: Any = \nredis_version:0.091\nconnected_clients:2\nconnected_slaves:0\nused_memory:3036\nchanges_since_last_save:0\nlast_save_time:1250440893\ntotal_connections_received:2\ntotal_commands_processed:0\nuptime_in_seconds:7\nuptime_in_days:0\n"
40 connection.readResponse returns sampleInfo
41 client.info mustEqual sampleInfo
42 connection.write("INFO\r\n") was called
43 }
44
45 "start monitor debug on the server" in {
46 connection.readBoolean returns true
47 client.monitor mustEqual true
48 connection.write("MONITOR\r\n") was called
49 }
50
51 "set a server as slave of a remote master" in {
52 connection.readBoolean returns true
53 client.slaveOf("localhost", 9999) mustEqual true
54 connection.write("SLAVEOF localhost 9999\r\n") was called
55 }
56
57 "set a server as master if no params sent" in {
58 connection.readBoolean returns true
59 client.slaveOf() mustEqual true
60 connection.write("SLAVEOF NO ONE\r\n") was called
61 }
62
63 "set a server as master" in {
64 connection.readBoolean returns true
65 client.setAsMaster mustEqual true
66 connection.write("SLAVEOF NO ONE\r\n") was called
67 }
68
69 "select the current db" in {
70 connection.readBoolean returns true
71 client.selectDb(3) mustEqual true
72 client.db mustEqual 3
73 connection.write("SELECT 3\r\n") was called
74 }
75
76 "flush the db" in {
77 connection.readBoolean returns true
78 client.flushDb mustEqual true
79 connection.write("FLUSHDB\r\n") was called
80 }
81
82 "flush all the dbs" in {
83 connection.readBoolean returns true
84 client.flushAll mustEqual true
85 connection.write("FLUSHALL\r\n") was called
86 }
87
88 "shutdown the db" in {
89 connection.readBoolean returns true
90 client.shutdown mustEqual true
91 connection.write("SHUTDOWN\r\n") was called
92 }
93
94 "move keys from one db to another" in {
95 connection.readBoolean returns true
96 client.move("a", 2) mustEqual true
97 connection.write("MOVE a 2\r\n") was called
98 }
99
100 "quit" in {
101 connection.disconnect returns true
102 client.quit mustEqual true
103 connection.write("QUIT\r\n") was called
104 connection.disconnect was called
105 }
106
107 "auth with the server" in {
108 connection.readBoolean returns true
109 client.auth("secret") mustEqual true
110 connection.write("AUTH secret\r\n") was called
111 }
112 }
113 }