orient_db_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/README.md +71 -0
  4. data/Rakefile +23 -0
  5. data/lib/orient_db_client/connection.rb +141 -0
  6. data/lib/orient_db_client/database_session.rb +107 -0
  7. data/lib/orient_db_client/deserializers/deserializer7.rb +166 -0
  8. data/lib/orient_db_client/exceptions.rb +25 -0
  9. data/lib/orient_db_client/network_message.rb +42 -0
  10. data/lib/orient_db_client/protocol_factory.rb +16 -0
  11. data/lib/orient_db_client/protocols/.DS_Store +0 -0
  12. data/lib/orient_db_client/protocols/protocol7.rb +571 -0
  13. data/lib/orient_db_client/protocols/protocol9.rb +79 -0
  14. data/lib/orient_db_client/rid.rb +39 -0
  15. data/lib/orient_db_client/serializers/serializer7.rb +208 -0
  16. data/lib/orient_db_client/server_session.rb +17 -0
  17. data/lib/orient_db_client/session.rb +10 -0
  18. data/lib/orient_db_client/types.rb +22 -0
  19. data/lib/orient_db_client/version.rb +3 -0
  20. data/lib/orient_db_client.rb +18 -0
  21. data/orient_db_client.gemspec +24 -0
  22. data/test/integration/connection_test.rb +18 -0
  23. data/test/integration/database_session_9_test.rb +82 -0
  24. data/test/integration/database_session_test.rb +222 -0
  25. data/test/integration/open_database_test.rb +28 -0
  26. data/test/integration/open_server_test.rb +24 -0
  27. data/test/integration/server_session_test.rb +37 -0
  28. data/test/support/connection_helper.rb +25 -0
  29. data/test/support/create_database.sql +33 -0
  30. data/test/support/databases.yml +8 -0
  31. data/test/support/expectation_helper.rb +13 -0
  32. data/test/support/protocol_helper.rb +25 -0
  33. data/test/support/server_config.rb +6 -0
  34. data/test/support/servers-template.yml +5 -0
  35. data/test/test_helper.rb +9 -0
  36. data/test/unit/connection_test.rb +84 -0
  37. data/test/unit/deserializers/deserializer7_test.rb +141 -0
  38. data/test/unit/network_message_test.rb +24 -0
  39. data/test/unit/orient_db_client_test.rb +16 -0
  40. data/test/unit/protocol_factory_test.rb +14 -0
  41. data/test/unit/protocols/protocol7_test.rb +658 -0
  42. data/test/unit/protocols/protocol9_test.rb +149 -0
  43. data/test/unit/rid_test.rb +32 -0
  44. data/test/unit/serializers/serializer7_test.rb +72 -0
  45. metadata +167 -0
@@ -0,0 +1,149 @@
1
+ require File.join File.dirname(__FILE__), '..', '..', 'test_helper'
2
+
3
+ class TestProtocol9 < 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::Protocol9
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_command
56
+ command_string = 'SELECT FROM OUser'
57
+
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
64
+
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)
73
+
74
+ chain = [
75
+ pack_byte(@protocol::Statuses::OK),
76
+ pack_integer(@session),
77
+ pack_byte(@protocol::PayloadStatuses::NULL),
78
+ pack_byte(@protocol::PayloadStatuses::NO_RECORDS)
79
+ ].map! &SOCKET_RECV_EXPECTATION
80
+
81
+ expect_sequence @socket, chain, 'response'
82
+
83
+ result = @protocol.command(@socket, @session, command_string)
84
+
85
+ assert_equal @session, result[:session]
86
+
87
+ assert result[:message_content].is_a?(Array)
88
+ assert_equal 1, result[:message_content].length
89
+ assert_nil result[:message_content][0]
90
+ end
91
+
92
+ def test_db_create
93
+ storage_type = 'local'
94
+ database_type = 'document'
95
+
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)
105
+
106
+ chain = [
107
+ pack_byte(@protocol::Statuses::OK),
108
+ pack_integer(@session)
109
+ ].map! &SOCKET_RECV_EXPECTATION
110
+
111
+ expect_sequence @socket, chain, 'response'
112
+
113
+ result = @protocol.db_create(@socket, @session, @database, {
114
+ :database_type => database_type,
115
+ :storage_type => storage_type
116
+ })
117
+
118
+ assert_equal @session, result[:session]
119
+ end
120
+
121
+ def test_record_load
122
+ cluster_id = 3
123
+ cluster_position = 6
124
+
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)
135
+
136
+ chain = [
137
+ pack_byte(@protocol::Statuses::OK),
138
+ pack_integer(@session),
139
+ pack_byte(@protocol::PayloadStatuses::NO_RECORDS)
140
+ ].map! &SOCKET_RECV_EXPECTATION
141
+
142
+ expect_sequence @socket, chain, 'response'
143
+
144
+ result = @protocol.record_load(@socket, @session, OrientDbClient::Rid.new(cluster_id, cluster_position))
145
+
146
+ assert_equal @session, result[:session]
147
+ end
148
+
149
+ end
@@ -0,0 +1,32 @@
1
+ require File.join File.dirname(__FILE__), '..', 'test_helper'
2
+
3
+ class TestRid < MiniTest::Unit::TestCase
4
+
5
+ def setup
6
+ @cluster_id = 3
7
+ @cluster_position = 5
8
+ @reference = "##{@cluster_id}:#{@cluster_position}"
9
+ end
10
+
11
+ def test_new_with_string
12
+ rid = OrientDbClient::Rid.new(@reference)
13
+
14
+ assert_equal @reference, rid.to_s
15
+ assert_equal @cluster_id, rid.cluster_id
16
+ assert_equal @cluster_position, rid.cluster_position
17
+ end
18
+
19
+ def test_new_with_components
20
+ rid = OrientDbClient::Rid.new(@cluster_id, @cluster_position)
21
+
22
+ assert_equal @reference, rid.to_s
23
+ assert_equal @cluster_id, rid.cluster_id
24
+ assert_equal @cluster_position, rid.cluster_position
25
+ end
26
+
27
+ def test_null
28
+ rid = OrientDbClient::Rid.new
29
+
30
+ assert_equal '#', rid.to_s
31
+ end
32
+ end
@@ -0,0 +1,72 @@
1
+ require File.join File.dirname(__FILE__), '..', '..', 'test_helper'
2
+
3
+ class TestSerializer7 < MiniTest::Unit::TestCase
4
+ def setup
5
+ @serializer = OrientDbClient::Protocols::Protocol7.serializer
6
+ end
7
+
8
+ def test_serialize
9
+ record = {
10
+ :class => 'OClass',
11
+ :structure => {
12
+ 'buffer' => :binary,
13
+ 'true' => :boolean,
14
+ 'false' => :boolean,
15
+ 'byte' => :byte,
16
+ 'array' => :collection,
17
+ 'date_from_time' => :date,
18
+ 'date_from_string' => :date,
19
+ 'bigdec' => :decimal,
20
+ 'doc' => :document,
21
+ 'double' => :double,
22
+ 'float' => :float,
23
+ 'bignum' => :long,
24
+ 'map' => :map,
25
+ 'rid' => :rid,
26
+ 'short' => :short,
27
+ 'string' => :string,
28
+ 'time' => :time
29
+ },
30
+ :document => {
31
+ 'implicit_binary' => "Binary data".encode("ASCII-8BIT"),
32
+ 'implicit_boolean_true' => true,
33
+ 'implicit_boolean_false' => false,
34
+ 'implicit_collection' => [ 3, 7, 14 ],
35
+ 'implicit_date' => Date.new(2012, 4, 3),
36
+ 'implicit_document' => { :document => { :sym_key => "embedded doc string" } },
37
+ 'implicit_double' => 6.6236,
38
+ 'implicit_integer' => 15,
39
+ 'implicit_long' => 7345723467317884556,
40
+ 'implicit_map' => { :key1 => 'value1', :key2 => 'value2' },
41
+ 'implicit_time' => Time.at(1296279468).utc,
42
+ 'implicit_string' => 'a string',
43
+ 'buffer' => "Explicit binary data",
44
+ 'true' => 1,
45
+ 'false' => nil,
46
+ 'byte' => 97,
47
+ 'array' => [ "Test", "Test3", 6, 2, OrientDbClient::Rid.new("#5:1") ],
48
+ 'date_from_time' => Time.at(1339560000).utc,
49
+ 'date_from_string' => "2012-6-13",
50
+ 'doc' => { 'integer' => 735 },
51
+ 'float' => 5.6234,
52
+ 'double' => 2.67234235,
53
+ 'bignum' => 1,
54
+ 'bigdec' => 6.2724522625234,
55
+ 'map' => { :key1 => "Value 1", "key_2" => "Value 2", "key_3" => 6234 },
56
+ 'rid' => "#3:2",
57
+ 'short' => 5,
58
+ 'time' => "2012-1-24 15:00:74",
59
+ 'implicit_embedded_documents' => [
60
+ { :structure => { 'null_rid' => :rid }, :document => { 'null_rid' => nil } },
61
+ { :structure => { 'short' => :short }, :document => { 'short' => 16134 } }
62
+ ]
63
+ }
64
+ }
65
+
66
+ expected_result = %Q{OClass@implicit_binary:_QmluYXJ5IGRhdGE=_,implicit_boolean_true:true,implicit_boolean_false:false,implicit_collection:[3,7,14],implicit_date:1333425600a,implicit_document:(sym_key:\"embedded doc string\"),implicit_double:6.6236d,implicit_integer:15,implicit_long:7345723467317884556l,implicit_map:{\"key1\":\"value1\",\"key2\":\"value2\"},implicit_time:1296279468t,implicit_string:\"a string\",buffer:_RXhwbGljaXQgYmluYXJ5IGRhdGE=_,true:true,false:false,byte:97b,array:[\"Test\",\"Test3\",6,2,#5:1],date_from_time:1339560000a,date_from_string:1339560000a,doc:(integer:735),float:5.6234f,double:2.67234235d,bignum:1l,bigdec:6.2724522625234c,map:{\"key1\":\"Value 1\",\"key_2\":\"Value 2\",\"key_3\":6234},rid:#3:2,short:5s,time:1327417259t,implicit_embedded_documents:[(null_rid:#),(short:16134s)]}
67
+
68
+ result = @serializer.serialize(record)
69
+
70
+ assert_equal expected_result, result
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orient_db_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Fields
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mocha
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: This gem uses the OrientDB Network Binary Protocol to provide connectivity
63
+ to an OrientDB Server
64
+ email:
65
+ - ryan.fields@twoleftbeats.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - README.md
73
+ - Rakefile
74
+ - lib/orient_db_client.rb
75
+ - lib/orient_db_client/connection.rb
76
+ - lib/orient_db_client/database_session.rb
77
+ - lib/orient_db_client/deserializers/deserializer7.rb
78
+ - lib/orient_db_client/exceptions.rb
79
+ - lib/orient_db_client/network_message.rb
80
+ - lib/orient_db_client/protocol_factory.rb
81
+ - lib/orient_db_client/protocols/.DS_Store
82
+ - lib/orient_db_client/protocols/protocol7.rb
83
+ - lib/orient_db_client/protocols/protocol9.rb
84
+ - lib/orient_db_client/rid.rb
85
+ - lib/orient_db_client/serializers/serializer7.rb
86
+ - lib/orient_db_client/server_session.rb
87
+ - lib/orient_db_client/session.rb
88
+ - lib/orient_db_client/types.rb
89
+ - lib/orient_db_client/version.rb
90
+ - orient_db_client.gemspec
91
+ - test/integration/connection_test.rb
92
+ - test/integration/database_session_9_test.rb
93
+ - test/integration/database_session_test.rb
94
+ - test/integration/open_database_test.rb
95
+ - test/integration/open_server_test.rb
96
+ - test/integration/server_session_test.rb
97
+ - test/support/connection_helper.rb
98
+ - test/support/create_database.sql
99
+ - test/support/databases.yml
100
+ - test/support/expectation_helper.rb
101
+ - test/support/protocol_helper.rb
102
+ - test/support/server_config.rb
103
+ - test/support/servers-template.yml
104
+ - test/test_helper.rb
105
+ - test/unit/connection_test.rb
106
+ - test/unit/deserializers/deserializer7_test.rb
107
+ - test/unit/network_message_test.rb
108
+ - test/unit/orient_db_client_test.rb
109
+ - test/unit/protocol_factory_test.rb
110
+ - test/unit/protocols/protocol7_test.rb
111
+ - test/unit/protocols/protocol9_test.rb
112
+ - test/unit/rid_test.rb
113
+ - test/unit/serializers/serializer7_test.rb
114
+ homepage: ''
115
+ licenses: []
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ segments:
127
+ - 0
128
+ hash: -4489046239481477100
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ segments:
136
+ - 0
137
+ hash: -4489046239481477100
138
+ requirements: []
139
+ rubyforge_project: orient_db_client
140
+ rubygems_version: 1.8.21
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: Network Binary Protocol client for OrientDB Server
144
+ test_files:
145
+ - test/integration/connection_test.rb
146
+ - test/integration/database_session_9_test.rb
147
+ - test/integration/database_session_test.rb
148
+ - test/integration/open_database_test.rb
149
+ - test/integration/open_server_test.rb
150
+ - test/integration/server_session_test.rb
151
+ - test/support/connection_helper.rb
152
+ - test/support/create_database.sql
153
+ - test/support/databases.yml
154
+ - test/support/expectation_helper.rb
155
+ - test/support/protocol_helper.rb
156
+ - test/support/server_config.rb
157
+ - test/support/servers-template.yml
158
+ - test/test_helper.rb
159
+ - test/unit/connection_test.rb
160
+ - test/unit/deserializers/deserializer7_test.rb
161
+ - test/unit/network_message_test.rb
162
+ - test/unit/orient_db_client_test.rb
163
+ - test/unit/protocol_factory_test.rb
164
+ - test/unit/protocols/protocol7_test.rb
165
+ - test/unit/protocols/protocol9_test.rb
166
+ - test/unit/rid_test.rb
167
+ - test/unit/serializers/serializer7_test.rb