orient_db_client 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,6 +46,9 @@ class TestProtocol9 < MiniTest::Unit::TestCase
46
46
  :type => 'LOGICAL' } ]
47
47
 
48
48
  @socket = mock()
49
+ @socket.stubs(:pos)
50
+ @socket.stubs(:write)
51
+ @socket.stubs(:read).with(0).returns('')
49
52
  end
50
53
 
51
54
  def socket_receives(request)
@@ -55,21 +58,14 @@ class TestProtocol9 < MiniTest::Unit::TestCase
55
58
  def test_command
56
59
  command_string = 'SELECT FROM OUser'
57
60
 
58
- command = OrientDbClient::NetworkMessage.new { |m|
59
- m.add :string, 'q'
60
- m.add :string, command_string
61
- m.add :integer, -1
62
- m.add :integer, 0
63
- }.pack
61
+ command = @protocol::QueryMessage.new :query_class_name => 'q',
62
+ :text => command_string
64
63
 
65
- request = OrientDbClient::NetworkMessage.new { |m|
66
- m.add :byte, @protocol::Operations::COMMAND
67
- m.add :integer, @session
68
- m.add :byte, 's'
69
- m.add :string, command
70
- }.pack
71
-
72
- socket_receives(request)
64
+ inputs = sequence('inputs')
65
+ @socket.expects(:write).with(pack_byte(@protocol::Operations::COMMAND)).in_sequence(inputs)
66
+ @socket.expects(:write).with(pack_integer(@session)).in_sequence(inputs)
67
+ @socket.expects(:write).with(pack_byte('s'.ord)).in_sequence(inputs)
68
+ @socket.expects(:write).with(pack_string(command.to_binary_s)).in_sequence(inputs)
73
69
 
74
70
  chain = [
75
71
  pack_byte(@protocol::Statuses::OK),
@@ -93,15 +89,12 @@ class TestProtocol9 < MiniTest::Unit::TestCase
93
89
  storage_type = 'local'
94
90
  database_type = 'document'
95
91
 
96
- request = OrientDbClient::NetworkMessage.new { |m|
97
- m.add :byte, @protocol::Operations::DB_CREATE
98
- m.add :integer, @session
99
- m.add :string, @database
100
- m.add :string, database_type
101
- m.add :string, storage_type
102
- }.pack
103
-
104
- socket_receives(request)
92
+ inputs = sequence('inputs')
93
+ @socket.expects(:write).with(pack_byte(@protocol::Operations::DB_CREATE)).in_sequence(inputs)
94
+ @socket.expects(:write).with(pack_integer(@session)).in_sequence(inputs)
95
+ @socket.expects(:write).with(pack_string(@database)).in_sequence(inputs)
96
+ @socket.expects(:write).with(pack_string(database_type)).in_sequence(inputs)
97
+ @socket.expects(:write).with(pack_string(storage_type)).in_sequence(inputs)
105
98
 
106
99
  chain = [
107
100
  pack_byte(@protocol::Statuses::OK),
@@ -118,20 +111,70 @@ class TestProtocol9 < MiniTest::Unit::TestCase
118
111
  assert_equal @session, result[:session]
119
112
  end
120
113
 
114
+ def test_db_open
115
+ inputs = sequence('inputs')
116
+ @socket.expects(:write).with(pack_byte(@protocol::Operations::DB_OPEN)).in_sequence(inputs)
117
+ @socket.expects(:write).with(pack_integer(@protocol::NEW_SESSION)).in_sequence(inputs)
118
+ @socket.expects(:write).with(pack_string(@driver_name)).in_sequence(inputs)
119
+ @socket.expects(:write).with(pack_string(@driver_version)).in_sequence(inputs)
120
+ @socket.expects(:write).with(pack_short(@protocol_version)).in_sequence(inputs)
121
+ @socket.expects(:write).with(pack_string(@database)).in_sequence(inputs)
122
+ @socket.expects(:write).with(pack_string('document')).in_sequence(inputs)
123
+ @socket.expects(:write).with(pack_string(@user)).in_sequence(inputs)
124
+ @socket.expects(:write).with(pack_string(@password)).in_sequence(inputs)
125
+
126
+ # recv chain
127
+ chain = [
128
+ { :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
129
+ { :param => Sizes::INTEGER, :return => pack_integer(@protocol::NEW_SESSION) },
130
+ { :param => Sizes::INTEGER, :return => pack_integer(@session) },
131
+ { :param => Sizes::SHORT, :return => pack_short(@clusters.length) }
132
+ ]
133
+
134
+ @clusters.each do |cluster|
135
+ chain.concat [
136
+ { :param => Sizes::INTEGER, :return => pack_integer(cluster[:name].length) },
137
+ { :param => cluster[:name].length, :return => pack_string(cluster[:name]) },
138
+ { :param => Sizes::SHORT, :return => pack_short(cluster[:id]) },
139
+ { :param => Sizes::INTEGER, :return => pack_integer(cluster[:type].length) },
140
+ { :param => cluster[:type].length, :return => pack_string(cluster[:type]) }
141
+ ]
142
+ end
143
+
144
+ chain << { :param => Sizes::INTEGER, :return => pack_integer(0) }
145
+
146
+ chain.map! &SOCKET_RECV_EXPECTATION
147
+ # End recv chain
148
+
149
+ expect_sequence @socket, chain, 'response'
150
+
151
+ result = @protocol.db_open(@socket, @database, {
152
+ :user => @user,
153
+ :password => @password
154
+ })
155
+
156
+ assert_equal @protocol::NEW_SESSION, result[:session]
157
+ assert_equal @session, result[:message_content][:session]
158
+ assert_equal @clusters.length, result[:message_content][:clusters].length
159
+
160
+ @clusters.each_with_index do |c, i|
161
+ assert_equal @clusters[i][:id], result[:message_content][:clusters][i][:id]
162
+ assert_equal @clusters[i][:name], result[:message_content][:clusters][i][:name]
163
+ assert_equal @clusters[i][:type], result[:message_content][:clusters][i][:type]
164
+ end
165
+ end
166
+
121
167
  def test_record_load
122
168
  cluster_id = 3
123
169
  cluster_position = 6
124
170
 
125
- request = OrientDbClient::NetworkMessage.new { |m|
126
- m.add :byte, @protocol::Operations::RECORD_LOAD
127
- m.add :integer, @session
128
- m.add :short, cluster_id
129
- m.add :long, cluster_position
130
- m.add :string, ""
131
- m.add :byte, 0
132
- }.pack
133
-
134
- socket_receives(request)
171
+ inputs = sequence('inputs')
172
+ @socket.expects(:write).with(pack_byte(@protocol::Operations::RECORD_LOAD)).in_sequence(inputs)
173
+ @socket.expects(:write).with(pack_integer(@session)).in_sequence(inputs)
174
+ @socket.expects(:write).with(pack_short(cluster_id)).in_sequence(inputs)
175
+ @socket.expects(:write).with(pack_long(cluster_position)).in_sequence(inputs)
176
+ @socket.expects(:write).with(pack_integer(0)).in_sequence(inputs)
177
+ @socket.expects(:write).with(pack_byte(0)).in_sequence(inputs)
135
178
 
136
179
  chain = [
137
180
  pack_byte(@protocol::Statuses::OK),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orient_db_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-06 00:00:00.000000000 Z
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bindata
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: minitest
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +94,6 @@ files:
78
94
  - lib/orient_db_client/exceptions.rb
79
95
  - lib/orient_db_client/network_message.rb
80
96
  - lib/orient_db_client/protocol_factory.rb
81
- - lib/orient_db_client/protocols/.DS_Store
82
97
  - lib/orient_db_client/protocols/protocol7.rb
83
98
  - lib/orient_db_client/protocols/protocol9.rb
84
99
  - lib/orient_db_client/rid.rb
@@ -125,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
140
  version: '0'
126
141
  segments:
127
142
  - 0
128
- hash: 2784375670515319189
143
+ hash: 4049052301386901195
129
144
  required_rubygems_version: !ruby/object:Gem::Requirement
130
145
  none: false
131
146
  requirements:
@@ -134,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
149
  version: '0'
135
150
  segments:
136
151
  - 0
137
- hash: 2784375670515319189
152
+ hash: 4049052301386901195
138
153
  requirements: []
139
154
  rubyforge_project: orient_db_client
140
155
  rubygems_version: 1.8.21