orient_db_client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +71 -0
- data/Rakefile +23 -0
- data/lib/orient_db_client/connection.rb +141 -0
- data/lib/orient_db_client/database_session.rb +107 -0
- data/lib/orient_db_client/deserializers/deserializer7.rb +166 -0
- data/lib/orient_db_client/exceptions.rb +25 -0
- data/lib/orient_db_client/network_message.rb +42 -0
- data/lib/orient_db_client/protocol_factory.rb +16 -0
- data/lib/orient_db_client/protocols/.DS_Store +0 -0
- data/lib/orient_db_client/protocols/protocol7.rb +571 -0
- data/lib/orient_db_client/protocols/protocol9.rb +79 -0
- data/lib/orient_db_client/rid.rb +39 -0
- data/lib/orient_db_client/serializers/serializer7.rb +208 -0
- data/lib/orient_db_client/server_session.rb +17 -0
- data/lib/orient_db_client/session.rb +10 -0
- data/lib/orient_db_client/types.rb +22 -0
- data/lib/orient_db_client/version.rb +3 -0
- data/lib/orient_db_client.rb +18 -0
- data/orient_db_client.gemspec +24 -0
- data/test/integration/connection_test.rb +18 -0
- data/test/integration/database_session_9_test.rb +82 -0
- data/test/integration/database_session_test.rb +222 -0
- data/test/integration/open_database_test.rb +28 -0
- data/test/integration/open_server_test.rb +24 -0
- data/test/integration/server_session_test.rb +37 -0
- data/test/support/connection_helper.rb +25 -0
- data/test/support/create_database.sql +33 -0
- data/test/support/databases.yml +8 -0
- data/test/support/expectation_helper.rb +13 -0
- data/test/support/protocol_helper.rb +25 -0
- data/test/support/server_config.rb +6 -0
- data/test/support/servers-template.yml +5 -0
- data/test/test_helper.rb +9 -0
- data/test/unit/connection_test.rb +84 -0
- data/test/unit/deserializers/deserializer7_test.rb +141 -0
- data/test/unit/network_message_test.rb +24 -0
- data/test/unit/orient_db_client_test.rb +16 -0
- data/test/unit/protocol_factory_test.rb +14 -0
- data/test/unit/protocols/protocol7_test.rb +658 -0
- data/test/unit/protocols/protocol9_test.rb +149 -0
- data/test/unit/rid_test.rb +32 -0
- data/test/unit/serializers/serializer7_test.rb +72 -0
- metadata +167 -0
@@ -0,0 +1,658 @@
|
|
1
|
+
require File.join File.dirname(__FILE__), '..', '..', 'test_helper'
|
2
|
+
|
3
|
+
class TestProtocol7 < MiniTest::Unit::TestCase
|
4
|
+
include ConnectionHelper
|
5
|
+
include ExpectationHelper
|
6
|
+
include ProtocolHelper
|
7
|
+
|
8
|
+
SOCKET_RECV_EXPECTATION = lambda do |r|
|
9
|
+
expectation = { :method => :read }
|
10
|
+
|
11
|
+
if r.is_a?(Hash)
|
12
|
+
expectation[:param] = r[:param] if r[:param]
|
13
|
+
expectation[:return] = r[:return] if r[:return]
|
14
|
+
else
|
15
|
+
expectation[:return] = r
|
16
|
+
end
|
17
|
+
|
18
|
+
expectation
|
19
|
+
end
|
20
|
+
|
21
|
+
module Sizes
|
22
|
+
BYTE = 1
|
23
|
+
SHORT = 2
|
24
|
+
INTEGER = 4
|
25
|
+
LONG = 8
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup
|
29
|
+
@protocol = OrientDbClient::Protocols::Protocol7
|
30
|
+
@protocol_version = @protocol::VERSION
|
31
|
+
@session = 62346
|
32
|
+
@database = 'test_database'
|
33
|
+
@user = 'test_user'
|
34
|
+
@password = 'test_password'
|
35
|
+
|
36
|
+
@driver_name = @protocol::DRIVER_NAME
|
37
|
+
@driver_version = @protocol::DRIVER_VERSION
|
38
|
+
|
39
|
+
@clusters = [
|
40
|
+
{ :name => 'vertexes',
|
41
|
+
:id => 0,
|
42
|
+
:type => 'PHYSICAL' },
|
43
|
+
|
44
|
+
{ :name => "edges",
|
45
|
+
:id => 1,
|
46
|
+
:type => 'LOGICAL' } ]
|
47
|
+
|
48
|
+
@socket = mock()
|
49
|
+
end
|
50
|
+
|
51
|
+
def socket_receives(request)
|
52
|
+
@socket.expects(:write).with(request).returns(nil)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_connect
|
56
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
57
|
+
m.add :byte, @protocol::Operations::CONNECT
|
58
|
+
m.add :integer, @protocol::NEW_SESSION
|
59
|
+
m.add :string, @driver_name
|
60
|
+
m.add :string, @driver_version
|
61
|
+
m.add :short, @protocol_version
|
62
|
+
m.add :string, nil #client-id
|
63
|
+
m.add :string, @user
|
64
|
+
m.add :string, @password
|
65
|
+
}.pack
|
66
|
+
|
67
|
+
socket_receives(request)
|
68
|
+
|
69
|
+
chain = [
|
70
|
+
pack_byte(@protocol::Statuses::OK),
|
71
|
+
pack_integer(@protocol::NEW_SESSION),
|
72
|
+
pack_integer(@session)
|
73
|
+
].map! &SOCKET_RECV_EXPECTATION
|
74
|
+
|
75
|
+
expect_sequence @socket, chain, 'response'
|
76
|
+
|
77
|
+
result = @protocol.connect(@socket, {
|
78
|
+
:user => @user,
|
79
|
+
:password => @password
|
80
|
+
})
|
81
|
+
|
82
|
+
assert_equal @protocol::NEW_SESSION, result[:session]
|
83
|
+
assert_equal @session, result[:message_content][:session]
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_count
|
87
|
+
cluster_name = "vertexes"
|
88
|
+
record_count = 1564
|
89
|
+
|
90
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
91
|
+
m.add :byte, @protocol::Operations::COUNT
|
92
|
+
m.add :integer, @session
|
93
|
+
m.add :string, cluster_name
|
94
|
+
}.pack
|
95
|
+
|
96
|
+
socket_receives(request)
|
97
|
+
|
98
|
+
chain = [
|
99
|
+
pack_byte(@protocol::Statuses::OK),
|
100
|
+
pack_integer(@session),
|
101
|
+
pack_long(record_count)
|
102
|
+
].map! &SOCKET_RECV_EXPECTATION
|
103
|
+
|
104
|
+
expect_sequence @socket, chain, 'response'
|
105
|
+
|
106
|
+
result = @protocol.count(@socket, @session, cluster_name)
|
107
|
+
|
108
|
+
assert_equal record_count, result[:message_content][:record_count]
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_command
|
112
|
+
command_string = 'SELECT FROM OUser'
|
113
|
+
|
114
|
+
command = OrientDbClient::NetworkMessage.new { |m|
|
115
|
+
m.add :string, 'com.orientechnologies.orient.core.sql.query.OSQLSynchQuery'
|
116
|
+
m.add :string, command_string
|
117
|
+
m.add :integer, -1
|
118
|
+
m.add :integer, 0
|
119
|
+
}.pack
|
120
|
+
|
121
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
122
|
+
m.add :byte, @protocol::Operations::COMMAND
|
123
|
+
m.add :integer, @session
|
124
|
+
m.add :byte, 's'
|
125
|
+
m.add :string, command
|
126
|
+
}.pack
|
127
|
+
|
128
|
+
socket_receives(request)
|
129
|
+
|
130
|
+
chain = [
|
131
|
+
pack_byte(@protocol::Statuses::OK),
|
132
|
+
pack_integer(@session),
|
133
|
+
pack_byte(@protocol::PayloadStatuses::NULL),
|
134
|
+
pack_byte(@protocol::PayloadStatuses::NO_RECORDS)
|
135
|
+
].map! &SOCKET_RECV_EXPECTATION
|
136
|
+
|
137
|
+
expect_sequence @socket, chain, 'response'
|
138
|
+
|
139
|
+
result = @protocol.command(@socket, @session, command_string)
|
140
|
+
|
141
|
+
assert_equal @session, result[:session]
|
142
|
+
|
143
|
+
assert result[:message_content].is_a?(Array)
|
144
|
+
assert_equal 1, result[:message_content].length
|
145
|
+
assert_nil result[:message_content][0]
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_datacluster_add_logical
|
149
|
+
type = :logical # Use symbol here, please
|
150
|
+
container = 15
|
151
|
+
|
152
|
+
new_cluster_number = 20
|
153
|
+
|
154
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
155
|
+
m.add :byte, @protocol::Operations::DATACLUSTER_ADD
|
156
|
+
m.add :integer, @session
|
157
|
+
m.add :string, type.to_s.upcase
|
158
|
+
m.add :integer, container
|
159
|
+
}.pack
|
160
|
+
|
161
|
+
socket_receives(request)
|
162
|
+
|
163
|
+
chain = [
|
164
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
165
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) },
|
166
|
+
{ :param => Sizes::SHORT, :return => pack_short(new_cluster_number) }
|
167
|
+
].map! &SOCKET_RECV_EXPECTATION
|
168
|
+
|
169
|
+
expect_sequence @socket, chain, 'response'
|
170
|
+
|
171
|
+
result = @protocol.datacluster_add(@socket, @session, type, {
|
172
|
+
:physical_cluster_container_id => container
|
173
|
+
})
|
174
|
+
|
175
|
+
assert_equal @session, result[:session]
|
176
|
+
assert_equal new_cluster_number, result[:message_content][:new_cluster_number]
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_datacluster_add_memory
|
180
|
+
type = :memory
|
181
|
+
name = 'test_memory_cluster'
|
182
|
+
|
183
|
+
new_cluster_number = 6
|
184
|
+
|
185
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
186
|
+
m.add :byte, @protocol::Operations::DATACLUSTER_ADD
|
187
|
+
m.add :integer, @session
|
188
|
+
m.add :string, type.to_s.upcase
|
189
|
+
m.add :string, name
|
190
|
+
}.pack
|
191
|
+
|
192
|
+
socket_receives(request)
|
193
|
+
|
194
|
+
chain = [
|
195
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
196
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) },
|
197
|
+
{ :param => Sizes::SHORT, :return => pack_short(new_cluster_number) }
|
198
|
+
].map! &SOCKET_RECV_EXPECTATION
|
199
|
+
|
200
|
+
expect_sequence @socket, chain, 'response'
|
201
|
+
|
202
|
+
result = @protocol.datacluster_add(@socket, @session, type, {
|
203
|
+
:name => name
|
204
|
+
})
|
205
|
+
|
206
|
+
assert_equal @session, result[:session]
|
207
|
+
assert_equal new_cluster_number, result[:message_content][:new_cluster_number]
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_datacluster_add_physical
|
211
|
+
type = 'PHYSICAL' # Use string here, please
|
212
|
+
name = 'test_cluster'
|
213
|
+
file_name = 'test_cluster_file'
|
214
|
+
size = -1
|
215
|
+
|
216
|
+
new_cluster_number = 10
|
217
|
+
|
218
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
219
|
+
m.add :byte, @protocol::Operations::DATACLUSTER_ADD
|
220
|
+
m.add :integer, @session
|
221
|
+
m.add :string, type
|
222
|
+
m.add :string, name
|
223
|
+
m.add :string, file_name
|
224
|
+
m.add :integer, size
|
225
|
+
}.pack
|
226
|
+
|
227
|
+
socket_receives(request)
|
228
|
+
|
229
|
+
chain = [
|
230
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
231
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) },
|
232
|
+
{ :param => Sizes::SHORT, :return => pack_short(new_cluster_number) }
|
233
|
+
].map! &SOCKET_RECV_EXPECTATION
|
234
|
+
|
235
|
+
expect_sequence @socket, chain, 'response'
|
236
|
+
|
237
|
+
result = @protocol.datacluster_add(@socket, @session, type, {
|
238
|
+
:name => name,
|
239
|
+
:file_name => file_name,
|
240
|
+
:initial_size => size
|
241
|
+
})
|
242
|
+
|
243
|
+
assert_equal @session, result[:session]
|
244
|
+
assert_equal new_cluster_number, result[:message_content][:new_cluster_number]
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_datacluster_datarange
|
248
|
+
cluster_id = 1
|
249
|
+
range_begin = 0
|
250
|
+
range_end = 1000
|
251
|
+
|
252
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
253
|
+
m.add :byte, @protocol::Operations::DATACLUSTER_DATARANGE
|
254
|
+
m.add :integer, @session
|
255
|
+
m.add :short, cluster_id
|
256
|
+
}.pack
|
257
|
+
|
258
|
+
socket_receives(request)
|
259
|
+
|
260
|
+
chain = [
|
261
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
262
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) },
|
263
|
+
{ :param => Sizes::LONG, :return => pack_long(range_begin) },
|
264
|
+
{ :param => Sizes::LONG, :return => pack_long(range_end) }
|
265
|
+
].map! &SOCKET_RECV_EXPECTATION
|
266
|
+
|
267
|
+
expect_sequence @socket, chain, 'response'
|
268
|
+
|
269
|
+
result = @protocol.datacluster_datarange(@socket, @session, cluster_id)
|
270
|
+
|
271
|
+
assert_equal @session, result[:session]
|
272
|
+
assert_equal range_begin, result[:message_content][:begin]
|
273
|
+
assert_equal range_end, result[:message_content][:end]
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_datacluster_remove
|
277
|
+
id = 10
|
278
|
+
|
279
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
280
|
+
m.add :byte, @protocol::Operations::DATACLUSTER_REMOVE
|
281
|
+
m.add :integer, @session
|
282
|
+
m.add :short, id
|
283
|
+
}.pack
|
284
|
+
|
285
|
+
socket_receives(request)
|
286
|
+
|
287
|
+
chain = [
|
288
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
289
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) },
|
290
|
+
{ :param => Sizes::BYTE, :return => pack_byte(1) }
|
291
|
+
].map! &SOCKET_RECV_EXPECTATION
|
292
|
+
|
293
|
+
expect_sequence @socket, chain, 'response'
|
294
|
+
|
295
|
+
result = @protocol.datacluster_remove(@socket, @session, id)
|
296
|
+
|
297
|
+
assert_equal @session, result[:session]
|
298
|
+
assert_equal 1, result[:message_content][:result]
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_db_close
|
302
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
303
|
+
m.add :byte, @protocol::Operations::DB_CLOSE
|
304
|
+
m.add :integer, @session
|
305
|
+
}.pack
|
306
|
+
|
307
|
+
socket_receives(request)
|
308
|
+
@socket.expects(:closed?).returns(true)
|
309
|
+
|
310
|
+
result = @protocol.db_close(@socket, @session)
|
311
|
+
|
312
|
+
assert result
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_db_countrecords
|
316
|
+
count = 26345
|
317
|
+
|
318
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
319
|
+
m.add :byte, @protocol::Operations::DB_COUNTRECORDS
|
320
|
+
m.add :integer, @session
|
321
|
+
}.pack
|
322
|
+
|
323
|
+
socket_receives(request)
|
324
|
+
|
325
|
+
chain = [
|
326
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
327
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) },
|
328
|
+
{ :param => Sizes::LONG, :return => pack_long(count) }
|
329
|
+
].map! &SOCKET_RECV_EXPECTATION
|
330
|
+
|
331
|
+
expect_sequence @socket, chain, 'response'
|
332
|
+
|
333
|
+
result = @protocol.db_countrecords(@socket, @session)
|
334
|
+
|
335
|
+
assert_equal @session, result[:session]
|
336
|
+
assert_equal count, result[:message_content][:count]
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_db_create
|
340
|
+
storage_type = 'local'
|
341
|
+
|
342
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
343
|
+
m.add :byte, @protocol::Operations::DB_CREATE
|
344
|
+
m.add :integer, @session
|
345
|
+
m.add :string, @database
|
346
|
+
m.add :string, storage_type
|
347
|
+
}.pack
|
348
|
+
|
349
|
+
socket_receives(request)
|
350
|
+
|
351
|
+
chain = [
|
352
|
+
pack_byte(@protocol::Statuses::OK),
|
353
|
+
pack_integer(@session)
|
354
|
+
].map! &SOCKET_RECV_EXPECTATION
|
355
|
+
|
356
|
+
expect_sequence @socket, chain, 'response'
|
357
|
+
|
358
|
+
result = @protocol.db_create(@socket, @session, @database, storage_type)
|
359
|
+
|
360
|
+
assert_equal @session, result[:session]
|
361
|
+
end
|
362
|
+
|
363
|
+
def test_db_delete
|
364
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
365
|
+
m.add :byte, @protocol::Operations::DB_DELETE
|
366
|
+
m.add :integer, @session
|
367
|
+
m.add :string, @database
|
368
|
+
}.pack
|
369
|
+
|
370
|
+
socket_receives(request)
|
371
|
+
|
372
|
+
chain = [
|
373
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
374
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) }
|
375
|
+
].map! &SOCKET_RECV_EXPECTATION
|
376
|
+
|
377
|
+
expect_sequence @socket, chain, 'response'
|
378
|
+
|
379
|
+
result = @protocol.db_delete(@socket, @session, @database)
|
380
|
+
|
381
|
+
assert_equal @session, result[:session]
|
382
|
+
end
|
383
|
+
|
384
|
+
def test_db_exist
|
385
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
386
|
+
m.add :byte, @protocol::Operations::DB_EXIST
|
387
|
+
m.add :integer, @session
|
388
|
+
m.add :string, @database
|
389
|
+
}.pack
|
390
|
+
|
391
|
+
socket_receives(request)
|
392
|
+
|
393
|
+
chain = [
|
394
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
395
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) },
|
396
|
+
{ :param => Sizes::BYTE, :return => pack_byte(1) }
|
397
|
+
].map! &SOCKET_RECV_EXPECTATION
|
398
|
+
|
399
|
+
expect_sequence @socket, chain, 'response'
|
400
|
+
|
401
|
+
result = @protocol.db_exist(@socket, @session, @database)
|
402
|
+
|
403
|
+
assert_equal @session, result[:session]
|
404
|
+
assert_equal 1, result[:message_content][:result]
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_db_open
|
408
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
409
|
+
m.add :byte, @protocol::Operations::DB_OPEN
|
410
|
+
m.add :integer, @protocol::NEW_SESSION
|
411
|
+
m.add :string, @driver_name
|
412
|
+
m.add :string, @driver_version
|
413
|
+
m.add :short, @protocol_version
|
414
|
+
m.add :string, nil #client-id
|
415
|
+
m.add :string, @database
|
416
|
+
m.add :string, @user
|
417
|
+
m.add :string, @password
|
418
|
+
}.pack
|
419
|
+
|
420
|
+
socket_receives(request)
|
421
|
+
|
422
|
+
# recv chain
|
423
|
+
chain = [
|
424
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
425
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@protocol::NEW_SESSION) },
|
426
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) },
|
427
|
+
{ :param => Sizes::SHORT, :return => pack_short(@clusters.length) }
|
428
|
+
]
|
429
|
+
|
430
|
+
@clusters.each do |cluster|
|
431
|
+
chain.concat [
|
432
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(cluster[:name].length) },
|
433
|
+
{ :param => cluster[:name].length, :return => pack_string(cluster[:name]) },
|
434
|
+
{ :param => Sizes::SHORT, :return => pack_short(cluster[:id]) },
|
435
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(cluster[:type].length) },
|
436
|
+
{ :param => cluster[:type].length, :return => pack_string(cluster[:type]) }
|
437
|
+
]
|
438
|
+
end
|
439
|
+
|
440
|
+
chain << { :param => Sizes::INTEGER, :return => pack_integer(0) }
|
441
|
+
|
442
|
+
chain.map! &SOCKET_RECV_EXPECTATION
|
443
|
+
# End recv chain
|
444
|
+
|
445
|
+
expect_sequence @socket, chain, 'response'
|
446
|
+
|
447
|
+
result = @protocol.db_open(@socket, @database, {
|
448
|
+
:user => @user,
|
449
|
+
:password => @password
|
450
|
+
})
|
451
|
+
|
452
|
+
assert_equal @protocol::NEW_SESSION, result[:session]
|
453
|
+
assert_equal @session, result[:message_content][:session]
|
454
|
+
assert_equal @clusters.length, result[:message_content][:clusters].length
|
455
|
+
|
456
|
+
@clusters.each_with_index do |c, i|
|
457
|
+
assert_equal @clusters[i][:id], result[:message_content][:clusters][i][:id]
|
458
|
+
assert_equal @clusters[i][:name], result[:message_content][:clusters][i][:name]
|
459
|
+
assert_equal @clusters[i][:type], result[:message_content][:clusters][i][:type]
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
def test_record_create_document_synchronous
|
464
|
+
cluster_id = 35
|
465
|
+
cluster_position = 1726
|
466
|
+
|
467
|
+
record = {
|
468
|
+
:document => {
|
469
|
+
:key1 => 'value1',
|
470
|
+
:key2 => 'value2'
|
471
|
+
}
|
472
|
+
}
|
473
|
+
|
474
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
475
|
+
m.add :byte, @protocol::Operations::RECORD_CREATE
|
476
|
+
m.add :integer, @session
|
477
|
+
m.add :short, cluster_id
|
478
|
+
m.add :string, @protocol.serializer.serialize(record)
|
479
|
+
m.add :byte, 'd'.ord
|
480
|
+
m.add :byte, @protocol::SyncModes::SYNC
|
481
|
+
}.pack
|
482
|
+
|
483
|
+
socket_receives(request)
|
484
|
+
|
485
|
+
chain = [
|
486
|
+
pack_byte(@protocol::Statuses::OK),
|
487
|
+
pack_integer(@session),
|
488
|
+
pack_long(cluster_position)
|
489
|
+
].map! &SOCKET_RECV_EXPECTATION
|
490
|
+
|
491
|
+
expect_sequence @socket, chain, 'response'
|
492
|
+
|
493
|
+
result = @protocol.record_create(@socket, @session, cluster_id, record)
|
494
|
+
|
495
|
+
assert_equal cluster_id, result[:message_content][:cluster_id]
|
496
|
+
assert_equal cluster_position, result[:message_content][:cluster_position]
|
497
|
+
end
|
498
|
+
|
499
|
+
def test_record_delete_synchronous
|
500
|
+
cluster_id = 35
|
501
|
+
cluster_position = 1726
|
502
|
+
version = 0
|
503
|
+
|
504
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
505
|
+
m.add :byte, @protocol::Operations::RECORD_DELETE
|
506
|
+
m.add :integer, @session
|
507
|
+
m.add :short, cluster_id
|
508
|
+
m.add :long, cluster_position
|
509
|
+
m.add :integer, version
|
510
|
+
m.add :byte, @protocol::SyncModes::SYNC
|
511
|
+
}.pack
|
512
|
+
|
513
|
+
socket_receives(request)
|
514
|
+
|
515
|
+
chain = [
|
516
|
+
pack_byte(@protocol::Statuses::OK),
|
517
|
+
pack_integer(@session),
|
518
|
+
pack_byte(1)
|
519
|
+
].map! &SOCKET_RECV_EXPECTATION
|
520
|
+
|
521
|
+
expect_sequence @socket, chain, 'response'
|
522
|
+
|
523
|
+
result = @protocol.record_delete(@socket, @session, cluster_id, cluster_position, version)
|
524
|
+
|
525
|
+
assert_equal 1, result[:message_content][:result]
|
526
|
+
end
|
527
|
+
|
528
|
+
def test_record_load
|
529
|
+
cluster_id = 3
|
530
|
+
cluster_position = 6
|
531
|
+
|
532
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
533
|
+
m.add :byte, @protocol::Operations::RECORD_LOAD
|
534
|
+
m.add :integer, @session
|
535
|
+
m.add :short, cluster_id
|
536
|
+
m.add :long, cluster_position
|
537
|
+
m.add :string, ""
|
538
|
+
}.pack
|
539
|
+
|
540
|
+
socket_receives(request)
|
541
|
+
|
542
|
+
chain = [
|
543
|
+
pack_byte(@protocol::Statuses::OK),
|
544
|
+
pack_integer(@session),
|
545
|
+
pack_byte(@protocol::PayloadStatuses::NO_RECORDS)
|
546
|
+
].map! &SOCKET_RECV_EXPECTATION
|
547
|
+
|
548
|
+
expect_sequence @socket, chain, 'response'
|
549
|
+
|
550
|
+
result = @protocol.record_load(@socket, @session, OrientDbClient::Rid.new(cluster_id, cluster_position))
|
551
|
+
|
552
|
+
assert_equal @session, result[:session]
|
553
|
+
end
|
554
|
+
|
555
|
+
def test_record_update_document_synchronous
|
556
|
+
cluster_id = 35
|
557
|
+
cluster_position = 1726
|
558
|
+
record_version_policy = -2
|
559
|
+
record_version = 0
|
560
|
+
|
561
|
+
record = {
|
562
|
+
:document => {
|
563
|
+
:key1 => 'value1',
|
564
|
+
:key2 => 'value2',
|
565
|
+
:key3 => 'value3'
|
566
|
+
}
|
567
|
+
}
|
568
|
+
|
569
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
570
|
+
m.add :byte, @protocol::Operations::RECORD_UPDATE
|
571
|
+
m.add :integer, @session
|
572
|
+
m.add :short, cluster_id
|
573
|
+
m.add :long, cluster_position
|
574
|
+
m.add :string, @protocol.serializer.serialize(record)
|
575
|
+
m.add :integer, record_version_policy
|
576
|
+
m.add :byte, 'd'.ord
|
577
|
+
m.add :byte, @protocol::SyncModes::SYNC
|
578
|
+
}.pack
|
579
|
+
|
580
|
+
socket_receives(request)
|
581
|
+
|
582
|
+
chain = [
|
583
|
+
pack_byte(@protocol::Statuses::OK),
|
584
|
+
pack_integer(@session),
|
585
|
+
pack_integer(record_version)
|
586
|
+
].map! &SOCKET_RECV_EXPECTATION
|
587
|
+
|
588
|
+
expect_sequence @socket, chain, 'response'
|
589
|
+
|
590
|
+
result = @protocol.record_update(@socket, @session, cluster_id, cluster_position, record)
|
591
|
+
|
592
|
+
assert_equal record_version, result[:message_content][:record_version]
|
593
|
+
end
|
594
|
+
|
595
|
+
def test_db_reload
|
596
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
597
|
+
m.add :byte, @protocol::Operations::DB_RELOAD
|
598
|
+
m.add :integer, @session
|
599
|
+
}.pack
|
600
|
+
|
601
|
+
socket_receives(request)
|
602
|
+
|
603
|
+
# recv chain
|
604
|
+
chain = [
|
605
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
606
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) },
|
607
|
+
{ :param => Sizes::SHORT, :return => pack_short(@clusters.length) }
|
608
|
+
]
|
609
|
+
|
610
|
+
@clusters.each do |cluster|
|
611
|
+
chain.concat [
|
612
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(cluster[:name].length) },
|
613
|
+
{ :param => cluster[:name].length, :return => pack_string(cluster[:name]) },
|
614
|
+
{ :param => Sizes::SHORT, :return => pack_short(cluster[:id]) },
|
615
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(cluster[:type].length) },
|
616
|
+
{ :param => cluster[:type].length, :return => pack_string(cluster[:type]) }
|
617
|
+
]
|
618
|
+
end
|
619
|
+
|
620
|
+
chain.map! &SOCKET_RECV_EXPECTATION
|
621
|
+
# End recv chain
|
622
|
+
|
623
|
+
expect_sequence @socket, chain, 'response'
|
624
|
+
|
625
|
+
result = @protocol.db_reload(@socket, @session)
|
626
|
+
assert_equal @session, result[:session]
|
627
|
+
assert_equal @clusters.length, result[:message_content][:clusters].length
|
628
|
+
|
629
|
+
@clusters.each_with_index do |c, i|
|
630
|
+
assert_equal @clusters[i][:id], result[:message_content][:clusters][i][:id]
|
631
|
+
assert_equal @clusters[i][:name], result[:message_content][:clusters][i][:name]
|
632
|
+
assert_equal @clusters[i][:type], result[:message_content][:clusters][i][:type]
|
633
|
+
end
|
634
|
+
end
|
635
|
+
|
636
|
+
def test_db_size
|
637
|
+
size = 1563467
|
638
|
+
|
639
|
+
request = OrientDbClient::NetworkMessage.new { |m|
|
640
|
+
m.add :byte, @protocol::Operations::DB_SIZE
|
641
|
+
m.add :integer, @session
|
642
|
+
}.pack
|
643
|
+
|
644
|
+
socket_receives(request)
|
645
|
+
|
646
|
+
chain = [
|
647
|
+
{ :param => Sizes::BYTE, :return => pack_byte(@protocol::Statuses::OK) },
|
648
|
+
{ :param => Sizes::INTEGER, :return => pack_integer(@session) },
|
649
|
+
{ :param => Sizes::LONG, :return => pack_long(size) }
|
650
|
+
].map! &SOCKET_RECV_EXPECTATION
|
651
|
+
|
652
|
+
expect_sequence @socket, chain, 'response'
|
653
|
+
|
654
|
+
result = @protocol.db_size(@socket, @session)
|
655
|
+
assert_equal @session, result[:session]
|
656
|
+
assert_equal size, result[:message_content][:size]
|
657
|
+
end
|
658
|
+
end
|