vagas-orientdb4r 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +26 -0
  4. data/.travis.yml +18 -0
  5. data/Gemfile +9 -0
  6. data/LICENSE +202 -0
  7. data/README.rdoc +124 -0
  8. data/Rakefile +43 -0
  9. data/changelog.txt +60 -0
  10. data/ci/initialize-ci.sh +36 -0
  11. data/fstudy/design_v1.dia +0 -0
  12. data/fstudy/design_v1.png +0 -0
  13. data/fstudy/domain_model.dia +0 -0
  14. data/fstudy/domain_model.png +0 -0
  15. data/fstudy/flat_class_perf.rb +56 -0
  16. data/fstudy/sample1_object_diagram.dia +0 -0
  17. data/fstudy/sample1_object_diagram.png +0 -0
  18. data/fstudy/study_case.rb +87 -0
  19. data/fstudy/technical_feasibility.rb +256 -0
  20. data/lib/orientdb4r.rb +115 -0
  21. data/lib/orientdb4r/bin/client.rb +86 -0
  22. data/lib/orientdb4r/bin/connection.rb +29 -0
  23. data/lib/orientdb4r/bin/constants.rb +20 -0
  24. data/lib/orientdb4r/bin/io.rb +38 -0
  25. data/lib/orientdb4r/bin/protocol28.rb +101 -0
  26. data/lib/orientdb4r/bin/protocol_factory.rb +25 -0
  27. data/lib/orientdb4r/chained_error.rb +37 -0
  28. data/lib/orientdb4r/client.rb +364 -0
  29. data/lib/orientdb4r/load_balancing.rb +113 -0
  30. data/lib/orientdb4r/node.rb +42 -0
  31. data/lib/orientdb4r/rest/client.rb +517 -0
  32. data/lib/orientdb4r/rest/excon_node.rb +115 -0
  33. data/lib/orientdb4r/rest/model.rb +159 -0
  34. data/lib/orientdb4r/rest/node.rb +43 -0
  35. data/lib/orientdb4r/rest/restclient_node.rb +77 -0
  36. data/lib/orientdb4r/rid.rb +54 -0
  37. data/lib/orientdb4r/utils.rb +203 -0
  38. data/lib/orientdb4r/version.rb +39 -0
  39. data/orientdb4r.gemspec +37 -0
  40. data/test/bin/test_client.rb +21 -0
  41. data/test/readme_sample.rb +38 -0
  42. data/test/test_client.rb +93 -0
  43. data/test/test_database.rb +261 -0
  44. data/test/test_ddo.rb +237 -0
  45. data/test/test_dmo.rb +115 -0
  46. data/test/test_document_crud.rb +184 -0
  47. data/test/test_gremlin.rb +52 -0
  48. data/test/test_helper.rb +10 -0
  49. data/test/test_loadbalancing.rb +81 -0
  50. data/test/test_utils.rb +67 -0
  51. metadata +136 -0
@@ -0,0 +1,237 @@
1
+ require 'test_helper'
2
+
3
+ ###
4
+ # This class tests Data Definition Operarions.
5
+ class TestDdo < Test::Unit::TestCase
6
+
7
+ CLASS = 'testing'
8
+ DB = 'temp'
9
+
10
+ def initialize(params)
11
+ super params
12
+ @client = Orientdb4r.client
13
+ end
14
+
15
+ def setup
16
+ @client.connect :database => DB, :user => 'admin', :password => 'admin'
17
+ end
18
+
19
+ def teardown
20
+ # remove the testing class after each test
21
+ @client.drop_class(CLASS, :mode => :strict)
22
+ @client.disconnect
23
+ end
24
+
25
+
26
+ ###
27
+ # GET - Class
28
+ def test_get_class
29
+ assert_nothing_thrown do ouser = @client.get_class 'OUser'; end
30
+ # class does not exist
31
+ assert_raise Orientdb4r::NotFoundError do @client.get_class 'OUserXXX'; end
32
+
33
+ clazz = @client.get_class 'OUser'
34
+ # test OClass
35
+ assert_equal 'OUser', clazz.name
36
+ assert_nothing_thrown do clazz.properties; end
37
+ assert_instance_of Array, clazz.properties
38
+ assert !clazz.properties.empty?
39
+ assert_nothing_thrown do clazz.property(:password); end
40
+ assert_raise ArgumentError do clazz.property(:unknown_prop); end
41
+ assert_equal 'OIdentity', clazz.super_class
42
+ assert_instance_of Array, clazz.clusters
43
+ assert !clazz.clusters.empty?
44
+ assert_not_nil clazz.default_cluster
45
+ assert clazz.kind_of? Orientdb4r::OClass
46
+ assert !clazz.abstract?
47
+ # test Property
48
+ prop = clazz.property :password
49
+ assert_equal 'password', prop.name
50
+ assert_equal 'STRING', prop.type
51
+ assert prop.mandatory
52
+ assert prop.not_null
53
+ assert_nil prop.min
54
+ assert_nil prop.min
55
+ assert prop.kind_of? Orientdb4r::Property
56
+
57
+ assert @client.class_exists?('OUser')
58
+ assert !@client.class_exists?('UnknownClass')
59
+ end
60
+
61
+
62
+ ###
63
+ # CREATE CLASS
64
+ def test_create_class
65
+ assert !@client.class_exists?(CLASS)
66
+ assert_nothing_thrown do @client.create_class(CLASS); end
67
+ assert @client.class_exists?(CLASS)
68
+ assert_nothing_thrown do @client.get_class(CLASS); end # raises an Error if no class found
69
+ # already exist
70
+ assert_raise Orientdb4r::ServerError do @client.create_class(CLASS); end
71
+
72
+ # create with :force=>true
73
+ assert_nothing_thrown do @client.create_class(CLASS, :force => true); end
74
+ assert_nothing_thrown do @client.get_class(CLASS); end
75
+
76
+ # create ABSTRACT
77
+ ab_class = 'testingAbstr'
78
+ assert_nothing_thrown do @client.create_class(ab_class, :abstract => true); end
79
+ clazz = @client.get_class ab_class
80
+ assert clazz.abstract?
81
+ assert_raise Orientdb4r::ServerError do @client.create_document({ '@class' => ab_class, 'prop1' => 1 }); end
82
+ # clean up
83
+ @client.drop_class(ab_class, :mode => :strict)
84
+ end
85
+
86
+
87
+ ###
88
+ # CREATE CLASS ... EXTENDS
89
+ def test_create_class_extends
90
+ assert_nothing_thrown do @client.create_class(CLASS, :extends => 'OUser'); end
91
+ assert_nothing_thrown do @client.get_class(CLASS); end
92
+ clazz = @client.get_class(CLASS)
93
+ assert_equal 'OUser', clazz.super_class
94
+
95
+ # bad super class
96
+ assert_raise Orientdb4r::InvalidRequestError do @client.create_class(CLASS, :extends => 'nonExistingSuperClass'); end
97
+ end
98
+
99
+
100
+ ###
101
+ # DROP TABLE
102
+ def test_drop_class
103
+ super_clazz = "#{CLASS}Sup"
104
+ @client.drop_class(super_clazz); # just to be sure if previous test failed
105
+ @client.create_class(super_clazz);
106
+ @client.create_class(CLASS);
107
+ assert_nothing_thrown do @client.drop_class(CLASS); end
108
+ assert_raise Orientdb4r::NotFoundError do @client.get_class(CLASS); end # no info more
109
+ # the class is not visible in class list delivered by connect
110
+ db_info = @client.get_database
111
+ assert db_info['classes'].select { |i| i.name == CLASS }.empty?
112
+
113
+ # CLASS extends super_class
114
+ @client.create_class(CLASS, :extends => super_clazz);
115
+ assert_raise Orientdb4r::OrientdbError do @client.drop_class(super_clazz, :mode => :strict); end
116
+ assert_nothing_thrown do @client.get_class(super_clazz); end # still there
117
+ @client.drop_class(CLASS);
118
+ assert_nothing_thrown do @client.drop_class(super_clazz, :mode => :strict); end
119
+ end
120
+
121
+
122
+ ###
123
+ # CREATE PROPERTY
124
+ def test_create_property
125
+ @client.create_class(CLASS)
126
+ assert_nothing_thrown do @client.create_property(CLASS, 'prop1', :integer); end
127
+ clazz = @client.get_class(CLASS)
128
+ assert_equal 'INTEGER', clazz.property(:prop1).type
129
+ assert_nil clazz.property(:prop1).linked_class
130
+
131
+ # already exist
132
+ assert_raise Orientdb4r::ServerError do @client.create_property(CLASS, 'prop1', :integer); end
133
+ end
134
+
135
+
136
+ ###
137
+ # CREATE PROPERTY (linked-type)
138
+ def test_create_linkedtype
139
+ @client.create_class(CLASS)
140
+ assert_nothing_thrown do @client.create_property(CLASS, 'friends', :linkset, :linked_class => 'OUser'); end
141
+ clazz = @client.get_class(CLASS)
142
+ assert_equal 'LINKSET', clazz.property(:friends).type
143
+ assert_equal 'OUser', clazz.property(:friends).linked_class
144
+
145
+ # unknow linked-class
146
+ assert_raise Orientdb4r::ServerError do
147
+ @client.create_property(CLASS, 'friends2', :linkset, :linked_class => 'UnknownClass')
148
+ end
149
+
150
+ # already exist
151
+ assert_raise Orientdb4r::ServerError do
152
+ @client.create_property(CLASS, 'friends', :linkset, :linked_class => 'OUser');
153
+ end
154
+ end
155
+
156
+
157
+ ###
158
+ # CREATE CLASS + PROPERTY
159
+ def test_create_class_with_properties
160
+ assert_nothing_thrown do
161
+ @client.create_class(CLASS) do |c|
162
+ c.property 'prop1', :integer
163
+ c.property 'prop2', :string, :mandatory => true, :notnull => true, :readonly => true, :min => 1, :max => 99
164
+ c.link 'user', :linkset, 'OUser', :mandatory => true
165
+ end
166
+ end
167
+
168
+ clazz = @client.get_class(CLASS)
169
+ assert_equal 3, clazz.properties.size
170
+
171
+ prop1 = clazz.property(:prop1)
172
+ assert_equal 'INTEGER', prop1.type
173
+ assert !prop1.mandatory
174
+ assert !prop1.not_null
175
+ assert !prop1.read_only
176
+ assert_nil prop1.min
177
+ assert_nil prop1.max
178
+ assert_nil prop1.linked_class
179
+
180
+ prop2 = clazz.property(:prop2)
181
+ assert_equal 'STRING', prop2.type
182
+ assert prop2.mandatory
183
+ assert prop2.not_null
184
+ assert prop2.read_only
185
+ assert_equal '1', prop2.min
186
+ assert_equal '99', prop2.max
187
+ assert_nil prop2.linked_class
188
+
189
+ user = clazz.property(:user)
190
+ assert_equal 'LINKSET', user.type
191
+ assert user.mandatory
192
+ assert !user.not_null
193
+ assert !user.read_only
194
+ assert_nil user.min
195
+ assert_nil user.max
196
+ assert_equal 'OUser', user.linked_class
197
+
198
+
199
+ # properties direct as parametr
200
+ @client.drop_class CLASS
201
+ assert_nothing_thrown do
202
+ @client.create_class(CLASS, :properties => [
203
+ { :property => 'prop1_q', :type => :integer },
204
+ { :property => 'prop2_q', :type => :string, :mandatory => true, :notnull => true, :min => 1, :max => 99 },
205
+ { :property => 'user_q', :type => :linkset, :linked_class => 'OUser', :mandatory => true }
206
+ ])
207
+ end
208
+
209
+ clazz = @client.get_class(CLASS)
210
+ assert_equal 3, clazz.properties.size
211
+
212
+ prop1 = clazz.property(:prop1_q)
213
+ assert_equal 'INTEGER', prop1.type
214
+ assert !prop1.mandatory
215
+ assert !prop1.not_null
216
+ assert_nil prop1.min
217
+ assert_nil prop1.max
218
+ assert_nil prop1.linked_class
219
+
220
+ prop2 = clazz.property(:prop2_q)
221
+ assert_equal 'STRING', prop2.type
222
+ assert prop2.mandatory
223
+ assert prop2.not_null
224
+ assert_equal '1', prop2.min
225
+ assert_equal '99', prop2.max
226
+ assert_nil prop2.linked_class
227
+
228
+ user = clazz.property(:user_q)
229
+ assert_equal 'LINKSET', user.type
230
+ assert user.mandatory
231
+ assert !user.not_null
232
+ assert_nil user.min
233
+ assert_nil user.max
234
+ assert_equal 'OUser', user.linked_class
235
+ end
236
+
237
+ end
@@ -0,0 +1,115 @@
1
+ require 'test_helper'
2
+
3
+ ###
4
+ # This class tests Data Manipulation Operarions.
5
+ class TestDmo < Test::Unit::TestCase
6
+ include Orientdb4r::Utils
7
+
8
+ CLASS = 'testing'
9
+ DB = 'temp'
10
+
11
+ def setup
12
+ @client = Orientdb4r.client
13
+ @client.connect :database => DB, :user => 'admin', :password => 'admin'
14
+ @client.drop_class(CLASS) # just to be sure if the previous test failed
15
+ @client.create_class(CLASS) do |c|
16
+ c.property 'prop1', :integer
17
+ c.property 'prop2', :string, :mandatory => true, :notnull => :true, :min => 1, :max => 99
18
+ c.link 'friends', :linkset, 'OUser', :mandatory => true
19
+ end
20
+ @admin = @client.query("SELECT FROM OUser WHERE name = 'admin'")[0]
21
+ end
22
+
23
+ def teardown
24
+ # remove the testing class after each test
25
+ @client.drop_class(CLASS)
26
+ @client.disconnect
27
+ end
28
+
29
+
30
+ ###
31
+ # INSERT INTO
32
+ def test_insert
33
+ assert_nothing_thrown do
34
+ 1.upto(10) do |i|
35
+ @client.command "INSERT INTO #{CLASS} (prop1, prop2, friends) VALUES (#{i}, '#{random_string}', [#{@admin['@rid']}])"
36
+ end
37
+ end
38
+
39
+ entries = @client.query("SELECT FROM #{CLASS}")
40
+ assert_equal 10, entries.size
41
+ assert_equal 10, entries.select { |e| e if e['prop1'] <= 10 }.size
42
+ assert_equal 10, entries.select { |e| e if e['friends'].size == 1 }.size
43
+
44
+ # insert more users into LINKSET
45
+ urids = @client.query('SELECT FROM OUser').collect { |u| u['@rid'] }
46
+ assert_nothing_thrown do
47
+ @client.command "INSERT INTO #{CLASS} (prop1, prop2, friends) VALUES (1, 'linkset', [#{urids.join(',')}])"
48
+ end
49
+ assert_equal urids.size, @client.query("SELECT FROM #{CLASS} WHERE prop2 = 'linkset'")[0]['friends'].size
50
+
51
+ # table doesn't exist
52
+ assert_raise Orientdb4r::InvalidRequestError do
53
+ @client.command "INSERT INTO #{CLASS}x (prop1, prop2, friends) VALUES (1, 'linkset', [#{urids.join(',')}])"
54
+ end
55
+ # bad syntax
56
+ assert_raise Orientdb4r::ServerError do
57
+ @client.command 'xxx'
58
+ end
59
+
60
+ # used for SELECT
61
+ assert_equal @client.query('SELECT FROM OUser'), @client.command('SELECT FROM OUser')['result']
62
+ end
63
+
64
+
65
+ ###
66
+ # SELECT
67
+ def test_query
68
+ 1.upto(25) do |i|
69
+ @client.command "INSERT INTO #{CLASS} (prop1, prop2, friends) VALUES (#{i}, 'string#{i}', [#{@admin['@rid']}])"
70
+ end
71
+
72
+ entries = @client.query("SELECT FROM #{CLASS}")
73
+ assert_not_nil entries
74
+ assert_instance_of Array, entries
75
+ assert_equal 20, entries.size # 20 is default limit
76
+ entries.each { |doc| assert doc.kind_of? Orientdb4r::DocumentMetadata }
77
+ entries.each { |doc| assert_instance_of Orientdb4r::Rid, doc.doc_rid }
78
+ # limit
79
+ assert_equal 5, @client.query("SELECT FROM #{CLASS} LIMIT 5").size
80
+ entries = @client.query "SELECT FROM #{CLASS}", :limit => 100
81
+ assert_equal 25, entries.size
82
+ assert_raise ArgumentError do @client.query "SELECT FROM #{CLASS}", :unknown => 100; end
83
+
84
+ assert_equal 1, @client.query("SELECT FROM #{CLASS} WHERE prop1 = 1").size
85
+ assert_equal 0, @client.query("SELECT FROM #{CLASS} WHERE prop1 = -1").size
86
+ # graph
87
+ rid = @client.query("SELECT FROM #{CLASS} WHERE prop1 = 1")[0]['@rid']
88
+ gr = @client.query("SELECT FROM (TRAVERSE * FROM #{rid})")
89
+ assert_equal 3, gr.size # entries: testing, OUser, ORole
90
+ assert_equal 1, gr.select { |e| e if e['@class'] == CLASS }.size
91
+ assert_equal 1, gr.select { |e| e if e['@class'] == 'OUser' }.size
92
+ assert_equal 1, gr.select { |e| e if e['@class'] == 'ORole' }.size
93
+
94
+ # table doesn't exist
95
+ assert_raise Orientdb4r::InvalidRequestError do
96
+ @client.query 'SELECT FROM OUserX'
97
+ end
98
+ # bad syntax
99
+ assert_raise Orientdb4r::ServerError do
100
+ @client.query 'xxx'
101
+ end
102
+ # record not found in existing cluster
103
+ entries = @client.query 'SELECT FROM #0:1111'
104
+ assert_not_nil entries
105
+ assert_instance_of Array, entries
106
+ assert entries.empty?
107
+ # try to find entry in a non-existing cluster
108
+ assert_raise Orientdb4r::NotFoundError do @client.query 'SELECT FROM #111:1111'; end
109
+ # used for INSERT
110
+ assert_raise Orientdb4r::ServerError do
111
+ @client.query "INSERT INTO #{CLASS} (prop1, prop2, friends) VALUES (0, 'string0', [])"
112
+ end
113
+ end
114
+
115
+ end
@@ -0,0 +1,184 @@
1
+ require 'test_helper'
2
+
3
+ ###
4
+ # This class tests CRUD operarions on document.
5
+ class TestDocumentCrud < Test::Unit::TestCase
6
+ include Orientdb4r::Utils
7
+
8
+ CLASS = 'testing'
9
+ DB = 'temp'
10
+
11
+ def setup
12
+ @client = Orientdb4r.client
13
+ @client.connect :database => DB, :user => 'admin', :password => 'admin'
14
+ @client.create_class(CLASS) do |c|
15
+ c.property 'prop1', :integer, :notnull => :true, :min => 1, :max => 99
16
+ c.property 'prop2', :string, :mandatory => true
17
+ end
18
+ end
19
+
20
+ def teardown
21
+ # remove the testing class after each test
22
+ @client.drop_class(CLASS)
23
+ @client.disconnect
24
+ end
25
+
26
+
27
+ ###
28
+ # CREATE
29
+ def test_create_document
30
+ assert_nothing_thrown do @client.create_document( { '@class' => CLASS, 'prop1' => 99, 'prop2' => 'ipsum lorem' }); end
31
+ doc = @client.create_document({ '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
32
+ assert_instance_of Hash, doc
33
+ assert_not_nil doc.doc_rid
34
+ assert_instance_of Orientdb4r::Rid, doc.doc_rid
35
+ assert_equal CLASS, doc.doc_class
36
+ assert doc.doc_version >= 1 # https://github.com/orientechnologies/orientdb/issues/3656
37
+
38
+ # no effect if a define the version
39
+ # doc = @client.create_document({ '@class' => CLASS, '@version' => 2, 'prop1' => 1, 'prop2' => 'text' })
40
+ # OrientDB bug https://github.com/orientechnologies/orientdb/issues/3657
41
+ # assert_equal 0, doc.doc_version
42
+
43
+ # no effect if an unknown class
44
+ doc = @client.create_document({ '@class' => 'unknown_class', 'a' => 11, 'b' => 'text1' })
45
+ assert_equal 'unknown_class', doc.doc_class
46
+ assert_equal 11, doc['a']
47
+ assert_equal 'text1', doc['b']
48
+ # or missing class
49
+ assert_nothing_thrown do @client.create_document({ 'a' => 1, 'b' => 'text' }); end
50
+
51
+ # no mandatory property
52
+ assert_raise Orientdb4r::DataError do @client.create_document({ '@class' => CLASS, 'prop1' => 1 }); end
53
+ # notNull is null, or lesser/bigger
54
+ assert_raise Orientdb4r::DataError do
55
+ @client.create_document({ '@class' => CLASS, 'prop1' => nil, 'prop2' => 'text' })
56
+ end
57
+ assert_raise Orientdb4r::DataError do
58
+ @client.create_document({ '@class' => CLASS, 'prop1' => 0, 'prop2' => 'text' })
59
+ end
60
+ assert_raise Orientdb4r::DataError do
61
+ @client.create_document({ '@class' => CLASS, 'prop1' => 100, 'prop2' => 'text' })
62
+ end
63
+ end
64
+
65
+ ###
66
+ # GET
67
+ def test_get_document
68
+ created = @client.create_document( { '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
69
+
70
+ doc = @client.get_document created.doc_rid
71
+ assert_equal CLASS, doc.doc_class
72
+ assert_equal created.doc_rid, doc.doc_rid
73
+ assert doc.doc_version >= 1 # https://github.com/orientechnologies/orientdb/issues/3657
74
+ assert_equal 'd', doc.doc_type
75
+ assert_equal 1, doc['prop1']
76
+ assert_equal 'text', doc['prop2']
77
+ assert_nil doc['unknown_property']
78
+ assert doc.kind_of? Orientdb4r::DocumentMetadata
79
+
80
+ # not existing RID
81
+ rid1 = Orientdb4r::Rid.new("#{created.doc_rid.cluster_id}:#{created.doc_rid.document_id + 1}") # '#6:0' > '#6:1' or '#6:11' > '#6:12'
82
+ assert_raise Orientdb4r::NotFoundError do @client.get_document rid1; end
83
+ # bad RID format
84
+ assert_raise ArgumentError do @client.get_document('xx'); end
85
+ end
86
+
87
+ ###
88
+ # UPDATE
89
+ def test_update_document
90
+ created = @client.create_document( { '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
91
+ doc = @client.get_document created.doc_rid
92
+
93
+ doc['prop1'] = 2
94
+ doc['prop2'] = 'unit'
95
+ assert_nothing_thrown do @client.update_document doc; end
96
+ doc = @client.get_document created.doc_rid
97
+ assert_equal 2, doc['prop1']
98
+ assert_equal 'unit', doc['prop2']
99
+
100
+ # bad version
101
+ doc = @client.get_document created.doc_rid
102
+ doc['prop1'] = 222 # a property has to be changed to server engine sees a difference
103
+ doc['@version'] = 2
104
+ assert_raise Orientdb4r::DataError do @client.update_document doc; end
105
+
106
+ # class cannot be changed
107
+ doc = @client.get_document created.doc_rid
108
+ doc['@class'] = 'OUser'
109
+ assert_nothing_thrown do @client.update_document doc; end
110
+ assert_equal CLASS, @client.get_document(created.doc_rid).doc_class
111
+
112
+ # no mandatory property
113
+ doc = @client.get_document created.doc_rid
114
+ doc.delete 'prop2'
115
+ assert_raise Orientdb4r::DataError do @client.update_document doc; end
116
+ # notNull is null, or lesser/bigger
117
+ doc = @client.get_document created.doc_rid
118
+ doc['prop1'] = nil
119
+ assert_raise Orientdb4r::DataError do @client.update_document doc; end
120
+ end
121
+
122
+
123
+ ###
124
+ # DELETE
125
+ def test_delete_document
126
+ doc = @client.create_document( { '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
127
+ assert_not_nil doc
128
+
129
+ assert_nothing_thrown do @client.delete_document doc.doc_rid; end
130
+ assert_raise Orientdb4r::NotFoundError do @client.get_document doc.doc_rid; end
131
+
132
+ # already deleted
133
+ assert_raise Orientdb4r::NotFoundError do @client.delete_document doc.doc_rid; end
134
+
135
+ # not existing RID
136
+ assert_raise Orientdb4r::NotFoundError do @client.delete_document '#4:1111'; end
137
+ # bad RID format
138
+ assert_raise ArgumentError do @client.delete_document 'xx'; end
139
+ end
140
+
141
+
142
+ #######################
143
+ # BATCH
144
+ #######################
145
+
146
+ def test_batch_ok
147
+ doc = @client.create_document( { '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
148
+ rslt = @client.batch({:transaction => true, :operations => [
149
+ {:type => :c, :record => {'@class' => CLASS, :prop2 => 'foo'}},
150
+ {:type => :d, :record => {'@rid' => doc.doc_rid}}
151
+ ]})
152
+ assert_instance_of Hash, rslt
153
+ assert_equal 1, @client.query("SELECT count(*) FROM #{CLASS}")[0]['count']
154
+ end
155
+
156
+ def test_batch_bad_params
157
+ doc = @client.create_document( { '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
158
+ assert_raise Orientdb4r::ServerError do @client.batch(nil); end
159
+ assert_raise Orientdb4r::ServerError do @client.batch({:foo => :baz, :bar => :alfa}); end # bad structure
160
+ assert_raise Orientdb4r::NotFoundError do @client.batch({:operations => [{:type => :d, :record => {'@rid' => '#123:456'}}]}); end # bad cluster
161
+ assert_nothing_thrown do @client.batch({:operations => [{:type => :d, :record => {'@rid' => "##{doc.doc_rid.cluster_id}:678"}}]}); end # bad RID is not problem
162
+ end
163
+
164
+ def test_batch_transaction
165
+ doc = @client.create_document( { '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
166
+
167
+ assert_raise Orientdb4r::ServerError do # will fail on update => tx on => create must be rollbacked
168
+ rslt = @client.batch({:transaction => true, :operations => [
169
+ {:type => :c, :record => {'@class' => CLASS, :prop2 => 'foo'}},
170
+ {:type => :u, :record => {'@rid' => doc.doc_rid}},
171
+ ]})
172
+ end
173
+ assert_equal 1, @client.query("SELECT count(*) FROM #{CLASS}")[0]['count']
174
+
175
+ assert_raise Orientdb4r::ServerError do # will fail on update => tx off => create must be done
176
+ rslt = @client.batch({:transaction => false, :operations => [
177
+ {:type => :c, :record => {'@class' => CLASS, :prop2 => 'foo'}},
178
+ {:type => :u, :record => {'@rid' => doc.doc_rid}},
179
+ ]})
180
+ end
181
+ assert_equal 2, @client.query("SELECT count(*) FROM #{CLASS}")[0]['count']
182
+ end
183
+
184
+ end