kyototycoon-client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,9 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
19
+ vendor/
20
+ *~
21
+ #*
22
+ .#*
23
+ *.swp
@@ -81,9 +81,9 @@ module Kyototycoon
81
81
  records.each do |r|
82
82
  request << [r.db_id, r.key.length].pack("nN") << r.key
83
83
  end
84
-
84
+
85
85
  @socket.write(request)
86
- response = @socket.read(5)
86
+ response = @socket.read(5)
87
87
  raise "no response" unless response
88
88
 
89
89
  magic, count = response.unpack("CN")
@@ -1,5 +1,5 @@
1
1
  module Kyototycoon
2
2
  class Client
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -35,10 +35,11 @@ module Kyototycoon
35
35
  end
36
36
 
37
37
  def script(method, key, value)
38
- script_bulk(method, { key => value } )
38
+ script_bulk(method, { key => value } )
39
39
  end
40
40
 
41
41
  def set_bulk(keyvalues, dbid = 0)
42
+ return 0 if keyvalues.empty?
42
43
  raise "connection closed" unless @connection.is_open
43
44
 
44
45
  records = []
@@ -53,6 +54,7 @@ module Kyototycoon
53
54
  end
54
55
 
55
56
  def get_bulk(keys, dbid=0)
57
+ return [] if keys.empty?
56
58
  raise "connection closed" unless @connection.is_open
57
59
 
58
60
  records = []
@@ -65,12 +67,13 @@ module Kyototycoon
65
67
  end
66
68
 
67
69
  def remove_bulk(keys, dbid=0)
70
+ return 0 if keys.empty?
68
71
  raise "connection closed" unless @connection.is_open
69
72
 
70
73
  records = []
71
74
  keys.each do |k|
72
75
  records.push(Record.new(k, nil, nil, dbid))
73
- end
76
+ end
74
77
  @connection.remove(records)
75
78
  end
76
79
 
@@ -1,9 +1,13 @@
1
1
  require "helper"
2
2
 
3
3
  class ClientTest < Test::Unit::TestCase
4
+
5
+ HOST = ENV["HOST"] || "localhost"
6
+ PORT = (ENV["PORT"] || 1978).to_i
7
+
4
8
  def setup
5
- raise "host and port of KyotoTycoon test server is required: rake test HOST=xxx PORT=xxx" if (!ENV["HOST"] || !ENV["PORT"])
6
- @client = Kyototycoon::Client.new(ENV["HOST"], ENV["PORT"].to_i)
9
+ raise "host and port of KyotoTycoon test server is required: rake test HOST=xxx PORT=xxx" if (!HOST || !PORT)
10
+ @client = Kyototycoon::Client.new(HOST, PORT)
7
11
  end
8
12
 
9
13
  def test_open
@@ -24,12 +28,14 @@ class ClientTest < Test::Unit::TestCase
24
28
 
25
29
  def test_clud_bulk
26
30
  @client.open
31
+ @client.remove_bulk(["key1", "key2", "key3", "key4"])
32
+
27
33
  assert_equal( @client.set_bulk( {"key1" => "valueA", "key2" => "valueB", "key3" => "valueC"} ), 3)
28
- assert_equal( @client.get_bulk( ["key1", "key2", "key3", "key4"] ),
29
- {"key1" => "valueA", "key2" => "valueB", "key3" => "valueC"} )
34
+ assert_equal( @client.get_bulk( ["key1", "key2", "key3", "key4"] ),
35
+ {"key1" => "valueA", "key2" => "valueB", "key3" => "valueC"} )
30
36
  assert_equal( @client.remove_bulk( ["key1", "key2"] ), 2 )
31
- assert_equal( @client.get_bulk( ["key1", "key2", "key3", "key4"] ),
32
- {"key3" => "valueC"} )
37
+ assert_equal( @client.get_bulk( ["key1", "key2", "key3", "key4"] ),
38
+ {"key3" => "valueC"} )
33
39
  @client.close
34
40
  end
35
41
 
@@ -61,6 +67,39 @@ class ClientTest < Test::Unit::TestCase
61
67
  @client.close
62
68
  end
63
69
 
70
+ def test_empty_records
71
+ client = Kyototycoon::Client.new(HOST, PORT)
72
+ client.instance_eval do |obj|
73
+ class << self
74
+ define_method :connection=, Proc.new { |connection|
75
+ @connection = connection
76
+ }
77
+ end
78
+ end
79
+
80
+ mock = MockConnection.new
81
+ client.connection = mock
82
+
83
+ client.get_bulk([])
84
+ assert_equal false, mock.called_get?
85
+
86
+ client.set_bulk([])
87
+ assert_equal false, mock.called_set?
88
+
89
+ client.remove_bulk([])
90
+ assert_equal false, mock.called_remove?
91
+
92
+ client.get(1)
93
+ assert_equal true, mock.called_get?
94
+
95
+ client.set(1, 1)
96
+ assert_equal true, mock.called_set?
97
+
98
+ client.remove(1)
99
+ assert_equal true, mock.called_remove?
100
+ end
101
+
102
+
64
103
  # def test_script
65
104
  # return unless @client
66
105
 
@@ -70,3 +109,42 @@ class ClientTest < Test::Unit::TestCase
70
109
  # @client.close
71
110
  # end
72
111
  end
112
+
113
+ class MockConnection
114
+ def initialize
115
+ @get = false
116
+ @set = false
117
+ @remove = false
118
+ end
119
+
120
+ def is_open
121
+ true
122
+ end
123
+
124
+ def get(records)
125
+ @get = true
126
+ []
127
+ end
128
+
129
+ def set(records)
130
+ @set = true
131
+ 0
132
+ end
133
+
134
+ def remove(records)
135
+ @remove = true
136
+ true
137
+ end
138
+
139
+ def called_get?
140
+ @get
141
+ end
142
+
143
+ def called_set?
144
+ @set
145
+ end
146
+
147
+ def called_remove?
148
+ @remove
149
+ end
150
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kyototycoon-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-17 00:00:00.000000000 Z
12
+ date: 2013-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler