vagas-orientdb4r 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +26 -0
- data/.travis.yml +18 -0
- data/Gemfile +9 -0
- data/LICENSE +202 -0
- data/README.rdoc +124 -0
- data/Rakefile +43 -0
- data/changelog.txt +60 -0
- data/ci/initialize-ci.sh +36 -0
- data/fstudy/design_v1.dia +0 -0
- data/fstudy/design_v1.png +0 -0
- data/fstudy/domain_model.dia +0 -0
- data/fstudy/domain_model.png +0 -0
- data/fstudy/flat_class_perf.rb +56 -0
- data/fstudy/sample1_object_diagram.dia +0 -0
- data/fstudy/sample1_object_diagram.png +0 -0
- data/fstudy/study_case.rb +87 -0
- data/fstudy/technical_feasibility.rb +256 -0
- data/lib/orientdb4r.rb +115 -0
- data/lib/orientdb4r/bin/client.rb +86 -0
- data/lib/orientdb4r/bin/connection.rb +29 -0
- data/lib/orientdb4r/bin/constants.rb +20 -0
- data/lib/orientdb4r/bin/io.rb +38 -0
- data/lib/orientdb4r/bin/protocol28.rb +101 -0
- data/lib/orientdb4r/bin/protocol_factory.rb +25 -0
- data/lib/orientdb4r/chained_error.rb +37 -0
- data/lib/orientdb4r/client.rb +364 -0
- data/lib/orientdb4r/load_balancing.rb +113 -0
- data/lib/orientdb4r/node.rb +42 -0
- data/lib/orientdb4r/rest/client.rb +517 -0
- data/lib/orientdb4r/rest/excon_node.rb +115 -0
- data/lib/orientdb4r/rest/model.rb +159 -0
- data/lib/orientdb4r/rest/node.rb +43 -0
- data/lib/orientdb4r/rest/restclient_node.rb +77 -0
- data/lib/orientdb4r/rid.rb +54 -0
- data/lib/orientdb4r/utils.rb +203 -0
- data/lib/orientdb4r/version.rb +39 -0
- data/orientdb4r.gemspec +37 -0
- data/test/bin/test_client.rb +21 -0
- data/test/readme_sample.rb +38 -0
- data/test/test_client.rb +93 -0
- data/test/test_database.rb +261 -0
- data/test/test_ddo.rb +237 -0
- data/test/test_dmo.rb +115 -0
- data/test/test_document_crud.rb +184 -0
- data/test/test_gremlin.rb +52 -0
- data/test/test_helper.rb +10 -0
- data/test/test_loadbalancing.rb +81 -0
- data/test/test_utils.rb +67 -0
- metadata +136 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
###
|
4
|
+
# This class tests Data Manipulation Operarions.
|
5
|
+
class TestGremlin < 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.gremlin("g.V.has('@class','#{CLASS}').remove()")
|
15
|
+
@client.drop_class(CLASS) # just to be sure if the previous test failed
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
# remove the testing class after each test
|
20
|
+
@client.gremlin("g.V.has('@class','#{CLASS}').remove()")
|
21
|
+
@client.drop_class(CLASS)
|
22
|
+
@client.disconnect
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_gremlin
|
26
|
+
|
27
|
+
1.upto(25) do |i|
|
28
|
+
result = @client.gremlin("g.addVertex('class:#{CLASS}', 'prop1', 1, 'prop2', 'string1')")
|
29
|
+
end
|
30
|
+
|
31
|
+
entries = @client.gremlin("g.V.has('@class','#{CLASS}')[0..<20]")
|
32
|
+
assert_not_nil entries
|
33
|
+
assert_instance_of Array, entries
|
34
|
+
assert_equal 20, entries.size # no limit20 is default limit
|
35
|
+
entries.each { |doc| assert doc.kind_of? Orientdb4r::DocumentMetadata }
|
36
|
+
entries.each { |doc| assert_instance_of Orientdb4r::Rid, doc.doc_rid }
|
37
|
+
# limit
|
38
|
+
assert_equal 5, @client.gremlin("g.V.has('@class', '#{CLASS}')[0..<5]").size
|
39
|
+
entries = @client.gremlin("g.V.has('@class', '#{CLASS}')[0..<100]")
|
40
|
+
assert_equal 25, entries.size
|
41
|
+
|
42
|
+
assert_equal 25, @client.gremlin("g.V.has('@class', '#{CLASS}').has('prop1', 1)").size
|
43
|
+
assert_equal 0, @client.gremlin("g.V.has('@class', '#{CLASS}').has('prop1', -1)").size
|
44
|
+
|
45
|
+
entries = @client.gremlin "g.v(0:1111)"
|
46
|
+
assert_not_nil entries
|
47
|
+
assert_instance_of Array, entries
|
48
|
+
|
49
|
+
assert entries.empty?
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
###
|
4
|
+
# This class tests communication with OrientDB cluster and load balancing.
|
5
|
+
class TestLoadBalancing < Test::Unit::TestCase
|
6
|
+
|
7
|
+
###
|
8
|
+
# Test default Sequence strategy.
|
9
|
+
def test_sequence_loadbalancing
|
10
|
+
client = Orientdb4r.client :nodes => [{}, {:port => 2481}], :instance => :new
|
11
|
+
assert_equal :sequence, client.load_balancing
|
12
|
+
lb_strategy = client.lb_strategy
|
13
|
+
assert_not_nil lb_strategy
|
14
|
+
assert_instance_of Orientdb4r::Sequence, lb_strategy
|
15
|
+
assert_equal 0, lb_strategy.node_index
|
16
|
+
assert_equal 0, lb_strategy.node_index
|
17
|
+
assert_equal client.nodes[0], client.nodes[client.lb_strategy.node_index]
|
18
|
+
assert_equal client.nodes[0], client.nodes[client.lb_strategy.node_index]
|
19
|
+
end
|
20
|
+
|
21
|
+
###
|
22
|
+
# Test RoundRobin strategy.
|
23
|
+
def test_roundrobin_loadbalancing
|
24
|
+
client = Orientdb4r.client :nodes => [{}, {:port => 2481}], :load_balancing => :round_robin, :instance => :new
|
25
|
+
assert_equal :round_robin, client.load_balancing
|
26
|
+
lb_strategy = client.lb_strategy
|
27
|
+
assert_not_nil lb_strategy
|
28
|
+
assert_instance_of Orientdb4r::RoundRobin, lb_strategy
|
29
|
+
assert_equal 0, lb_strategy.node_index
|
30
|
+
assert_equal 1, lb_strategy.node_index
|
31
|
+
assert_equal 0, lb_strategy.node_index
|
32
|
+
assert_equal client.nodes[1], client.nodes[client.lb_strategy.node_index]
|
33
|
+
assert_equal client.nodes[0], client.nodes[client.lb_strategy.node_index]
|
34
|
+
assert_equal client.nodes[1], client.nodes[client.lb_strategy.node_index]
|
35
|
+
end
|
36
|
+
|
37
|
+
###
|
38
|
+
# Tests variant reasons for LB failure.
|
39
|
+
def test_load_balancing_in_problems
|
40
|
+
# invalid port
|
41
|
+
client = Orientdb4r.client :port => 9999, :instance => :new
|
42
|
+
assert_raise Orientdb4r::ConnectionError do
|
43
|
+
client.connect :database => 'temp', :user => 'admin', :password => 'admin'
|
44
|
+
end
|
45
|
+
# opened port, but not REST
|
46
|
+
client = Orientdb4r.client :port => 2424, :instance => :new
|
47
|
+
assert_raise Orientdb4r::ConnectionError do
|
48
|
+
client.connect :database => 'temp', :user => 'admin', :password => 'admin'
|
49
|
+
end
|
50
|
+
|
51
|
+
# invalid ports - both
|
52
|
+
client = Orientdb4r.client :nodes => [{:port => 9998}, {:port => 9999}], :instance => :new
|
53
|
+
begin
|
54
|
+
client.connect :database => 'temp', :user => 'admin', :password => 'admin'
|
55
|
+
assert_equal 0, 1, "Orientdb4r::ConnectionError EXPECTED"
|
56
|
+
rescue Orientdb4r::ConnectionError => e
|
57
|
+
assert_equal 'all nodes failed to communicate with server!', e.message
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# more nodes
|
62
|
+
|
63
|
+
# first node bad, second must work (sequence)
|
64
|
+
client = Orientdb4r.client :nodes => [{:port => 2481}, {}], :instance => :new
|
65
|
+
assert_nothing_thrown do # there has to be ERROR in log
|
66
|
+
client.connect :database => 'temp', :user => 'admin', :password => 'admin'
|
67
|
+
end
|
68
|
+
assert_equal 1, client.lb_strategy.bad_nodes.size
|
69
|
+
assert client.lb_strategy.bad_nodes.include? 0
|
70
|
+
|
71
|
+
# second node bad => second call has to be realized by first one (round robin)
|
72
|
+
client = Orientdb4r.client :nodes => [{}, {:port => 2481}], :load_balancing => :round_robin, :instance => :new
|
73
|
+
assert client.lb_strategy.bad_nodes.empty?
|
74
|
+
client.connect :database => 'temp', :user => 'admin', :password => 'admin'
|
75
|
+
assert client.lb_strategy.bad_nodes.empty?
|
76
|
+
client.query 'SELECT FROM OUser'
|
77
|
+
assert_equal 1, client.lb_strategy.bad_nodes.size
|
78
|
+
assert client.lb_strategy.bad_nodes.include? 1
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
data/test/test_utils.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
###
|
4
|
+
# This class tests Utils methods.
|
5
|
+
class TestUtils < Test::Unit::TestCase
|
6
|
+
include Orientdb4r::Utils
|
7
|
+
|
8
|
+
def test_verify_options
|
9
|
+
opt_pattern = {:a => :mandatory, :b => :optional, :c => 'predefined', :d => [1, false]}
|
10
|
+
assert_nothing_thrown do verify_options({:a => 'A', :b => 'B', :c => 'C', :d => 1}, opt_pattern); end
|
11
|
+
|
12
|
+
# missing mandatory
|
13
|
+
assert_raise ArgumentError do verify_options({}, opt_pattern); end
|
14
|
+
# unknown key
|
15
|
+
assert_raise ArgumentError do verify_options({:a => 1, :z => 2}, opt_pattern); end
|
16
|
+
# value not in predefined set
|
17
|
+
assert_raise ArgumentError do verify_options({:a => 1, :d => 3}, opt_pattern); end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_verify_and_sanitize_options
|
21
|
+
opt_pattern = {:a => 'A', :b => 'B'}
|
22
|
+
options = {:a => 'X'}
|
23
|
+
verify_and_sanitize_options(options, opt_pattern)
|
24
|
+
assert_equal 2, options.size
|
25
|
+
assert_equal 'X', options[:a]
|
26
|
+
assert_equal 'B', options[:b]
|
27
|
+
|
28
|
+
# :optional cannot be set as default value
|
29
|
+
opt_pattern = {:a => :optional, :b => 'B'}
|
30
|
+
options = {}
|
31
|
+
verify_and_sanitize_options(options, opt_pattern)
|
32
|
+
assert_equal 1, options.size
|
33
|
+
assert !options.include?(:a)
|
34
|
+
assert_equal 'B', options[:b]
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_compare_versions
|
38
|
+
assert_raise ArgumentError do compare_versions 'foo', 'bar'; end
|
39
|
+
assert_raise ArgumentError do compare_versions nil, 'bar'; end
|
40
|
+
assert_raise ArgumentError do compare_versions 'foo', nil; end
|
41
|
+
assert_raise ArgumentError do compare_versions '1.0.0', 'bar'; end
|
42
|
+
assert_raise ArgumentError do compare_versions 'foo', '1.0.0'; end
|
43
|
+
assert_nothing_thrown do compare_versions '1.0.0', '1.1.0'; end
|
44
|
+
|
45
|
+
assert_equal 0, compare_versions('1.0.0', '1.0.0')
|
46
|
+
assert_equal 0, compare_versions('1.2.0', '1.2.0')
|
47
|
+
assert_equal 0, compare_versions('1.2.3', '1.2.3')
|
48
|
+
|
49
|
+
assert_equal 1, compare_versions('1.0.1', '1.0.0')
|
50
|
+
assert_equal 1, compare_versions('1.1.0', '1.0.0')
|
51
|
+
assert_equal 1, compare_versions('2.0.0', '1.0.0')
|
52
|
+
|
53
|
+
assert_equal -1, compare_versions('1.0.0', '1.0.1')
|
54
|
+
assert_equal -1, compare_versions('1.0.0', '1.1.0')
|
55
|
+
assert_equal -1, compare_versions('1.0.0', '2.0.0')
|
56
|
+
|
57
|
+
# test block
|
58
|
+
tmp = -100;
|
59
|
+
compare_versions('1.0.0', '1.0.0') { |comp| tmp = comp }
|
60
|
+
assert_equal 0, tmp
|
61
|
+
compare_versions('1.0.0', '2.0.0') { |comp| tmp = comp }
|
62
|
+
assert_equal -1, tmp
|
63
|
+
compare_versions('3.0.0', '2.0.0') { |comp| tmp = comp }
|
64
|
+
assert_equal 1, tmp
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagas-orientdb4r
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vaclav Sykora
|
8
|
+
- Ronie Uliana
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-09-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.3'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.3'
|
42
|
+
description: Orientdb4r provides a simple interface on top of OrientDB's RESTful HTTP
|
43
|
+
API (VAGAS.com version)
|
44
|
+
email: vaclav.sykora@gmail.com ronie.uliana@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files:
|
48
|
+
- LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
files:
|
51
|
+
- ".coveralls.yml"
|
52
|
+
- ".gitignore"
|
53
|
+
- ".travis.yml"
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.rdoc
|
57
|
+
- Rakefile
|
58
|
+
- changelog.txt
|
59
|
+
- ci/initialize-ci.sh
|
60
|
+
- fstudy/design_v1.dia
|
61
|
+
- fstudy/design_v1.png
|
62
|
+
- fstudy/domain_model.dia
|
63
|
+
- fstudy/domain_model.png
|
64
|
+
- fstudy/flat_class_perf.rb
|
65
|
+
- fstudy/sample1_object_diagram.dia
|
66
|
+
- fstudy/sample1_object_diagram.png
|
67
|
+
- fstudy/study_case.rb
|
68
|
+
- fstudy/technical_feasibility.rb
|
69
|
+
- lib/orientdb4r.rb
|
70
|
+
- lib/orientdb4r/bin/client.rb
|
71
|
+
- lib/orientdb4r/bin/connection.rb
|
72
|
+
- lib/orientdb4r/bin/constants.rb
|
73
|
+
- lib/orientdb4r/bin/io.rb
|
74
|
+
- lib/orientdb4r/bin/protocol28.rb
|
75
|
+
- lib/orientdb4r/bin/protocol_factory.rb
|
76
|
+
- lib/orientdb4r/chained_error.rb
|
77
|
+
- lib/orientdb4r/client.rb
|
78
|
+
- lib/orientdb4r/load_balancing.rb
|
79
|
+
- lib/orientdb4r/node.rb
|
80
|
+
- lib/orientdb4r/rest/client.rb
|
81
|
+
- lib/orientdb4r/rest/excon_node.rb
|
82
|
+
- lib/orientdb4r/rest/model.rb
|
83
|
+
- lib/orientdb4r/rest/node.rb
|
84
|
+
- lib/orientdb4r/rest/restclient_node.rb
|
85
|
+
- lib/orientdb4r/rid.rb
|
86
|
+
- lib/orientdb4r/utils.rb
|
87
|
+
- lib/orientdb4r/version.rb
|
88
|
+
- orientdb4r.gemspec
|
89
|
+
- test/bin/test_client.rb
|
90
|
+
- test/readme_sample.rb
|
91
|
+
- test/test_client.rb
|
92
|
+
- test/test_database.rb
|
93
|
+
- test/test_ddo.rb
|
94
|
+
- test/test_dmo.rb
|
95
|
+
- test/test_document_crud.rb
|
96
|
+
- test/test_gremlin.rb
|
97
|
+
- test/test_helper.rb
|
98
|
+
- test/test_loadbalancing.rb
|
99
|
+
- test/test_utils.rb
|
100
|
+
homepage: http://github.com/vagascom/orientdb4r
|
101
|
+
licenses:
|
102
|
+
- Apache License, v2.0
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options:
|
106
|
+
- "--charset=UTF-8"
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.3.1
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.5.1
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Ruby binding for Orient DB.
|
125
|
+
test_files:
|
126
|
+
- test/bin/test_client.rb
|
127
|
+
- test/readme_sample.rb
|
128
|
+
- test/test_client.rb
|
129
|
+
- test/test_database.rb
|
130
|
+
- test/test_ddo.rb
|
131
|
+
- test/test_dmo.rb
|
132
|
+
- test/test_document_crud.rb
|
133
|
+
- test/test_gremlin.rb
|
134
|
+
- test/test_helper.rb
|
135
|
+
- test/test_loadbalancing.rb
|
136
|
+
- test/test_utils.rb
|