orientdb4r 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78703fba706afeb8f80d874c8f5e32833a15839f
4
- data.tar.gz: 70276305878920f38e2c926e4e7d58e02fea36e4
3
+ metadata.gz: ef3c2e518a837fac1f341da1ffca84fd1ee7f877
4
+ data.tar.gz: 20ee3236031b5646d5d78c9e7b9f791c2fd6d87a
5
5
  SHA512:
6
- metadata.gz: 1731ef1553df6b55cab52710a09c1bde1cd429406715799175695bb9079c4cfd2d0786618c8eeaa00d10048569eb369fc5a85f85755b79d54513acdec72af0b2
7
- data.tar.gz: 945fc1b08151705c3b0020edcb93449d78fe0d94e965c4dd4a1592777b0997b06864116b44056aafede80f97e277ccdf73bcd19ed0cec3909eb6544da647f0ac
6
+ metadata.gz: 846e581d9549b7e4222defcb53927b4e18f3e2ae04167d512105c98a31ae5d5fdfdfb8f3c51c6e096d1b14457bf9f6436db335a62d653f4384e9a2a5b7b7d13d
7
+ data.tar.gz: ba76c836fbab42889d172f26ea380ff2977fb34cf51caff38e1893fb66e6628a2ea449e53f49b546aca41a27acac26e1d0787eab5f4421cdd105a0ec166b5509
@@ -0,0 +1 @@
1
+ repo_token: qXflXiEwfGyJ5xCCGo8z0xloVYmUCZoyM
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+
5
+ before_script:
6
+ - chmod +x ./ci/initialize-ci.sh
7
+ - ./ci/initialize-ci.sh $ORIENTDB_VERSION
8
+ - bundle exec rake db:setup4test
9
+
10
+ env:
11
+ - ORIENTDB_VERSION=2.0.4
12
+
13
+ notifications:
14
+ email:
15
+ recipients:
16
+ - vaclav.sykora@gmail.com
17
+ on_success: change
18
+ on_failure: change
data/Gemfile CHANGED
@@ -1,3 +1,9 @@
1
1
  source "https://rubygems.org"
2
-
3
2
  gemspec
3
+
4
+ gem 'bindata', '>=2.1'
5
+
6
+ group :test do
7
+ gem 'test-unit', '>=3.0'
8
+ gem 'coveralls', require: false
9
+ end
@@ -9,6 +9,10 @@
9
9
 
10
10
  A Ruby client for the NoSQL Graph/Document database Orient DB (http://orientdb.org).
11
11
 
12
+ {<img src="https://badge.fury.io/rb/orientdb4r.svg" alt="Gem Version" />}[http://badge.fury.io/rb/orientdb4r]
13
+ {<img src="https://secure.travis-ci.org/veny/orientdb4r.png" alt="Build Status" />}[http://travis-ci.org/veny/orientdb4r]
14
+ {<img src="https://coveralls.io/repos/veny/orientdb4r/badge.svg?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/veny/orientdb4r?branch=master]
15
+
12
16
  == USAGE
13
17
 
14
18
  see Wiki page for more sample at https://github.com/veny/orientdb4r/wiki
@@ -75,7 +79,7 @@ see Wiki page for more sample at https://github.com/veny/orientdb4r/wiki
75
79
 
76
80
  === Important Upgrade Notice
77
81
 
78
- * see changelog.txt
82
+ * see +changelog.txt+
79
83
 
80
84
 
81
85
  == FEATURES/PROBLEMS
@@ -98,7 +102,7 @@ see Wiki page for more sample at https://github.com/veny/orientdb4r/wiki
98
102
 
99
103
  Make sure before starting the tests:
100
104
  * database server is running on localhost:2480
101
- * there is a root account with username=root and password=root
105
+ * there is a root account with username=root and password=root; if your password is different, specify it with an `ORIENTDB_ROOT_PASS` environment variable
102
106
 
103
107
 
104
108
  == AUTHOR
@@ -110,3 +114,11 @@ Make sure before starting the tests:
110
114
 
111
115
  * Apache License, Version 2.0, http://www.apache.org/licenses/
112
116
  * see LICENSE file for more details...
117
+
118
+ == CONTRIBUTING
119
+
120
+ 1. Fork it ( https://github.com/veny/orientdb4r/fork )
121
+ 1. Create your feature branch ( <tt>git checkout -b my-new-feature</tt> )
122
+ 1. Commit your changes ( <tt>git commit -am 'Add some feature'</tt> )
123
+ 1. Push to the branch ( <tt>git push origin my-new-feature</tt> )
124
+ 1. Create a new Pull Request
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ namespace :db do
14
14
  DB_PORT = 2480
15
15
  DB_NAME = 'temp'
16
16
  DB_ROOT_USER = 'root'
17
- DB_ROOT_PASS = 'root'
17
+ DB_ROOT_PASS = ENV['ORIENTDB_ROOT_PASS'] || 'root'
18
18
 
19
19
  desc 'Check whether a test DB exists and create if not'
20
20
  task :setup4test do
@@ -1,6 +1,6 @@
1
1
  0.5.0 2015-03-02
2
2
  - Provides fixes to be fully compatible with OrientDb v2.x.
3
- - No more backward compatible with OrientDb v1.5.x and lesser.
3
+ - No more backward compatible with OrientDb v1.5.x and lesser
4
4
  - Pull Request #31 : rest-client 1.6.7 => 1.7.x
5
5
  - Pull Request #32 : Add Gemfile & rake as a dev dependency
6
6
  - Pull Request #33 : Fix content type header for rest-client
@@ -14,7 +14,7 @@
14
14
 
15
15
  0.4.0 2013-08-14
16
16
  - Closes gap between this driver and OrientDb v1.4.0+ which introduced some changes on REST API (connect & create_document).
17
- - No more backward compatible with OrientDb v1.3.x and lesser.
17
+ - No more backward compatible with OrientDb v1.3.x and lesser
18
18
  - Enhancement #20 : Method 'compare_versions' accepts a block now
19
19
  - Bug Fix #25
20
20
 
@@ -0,0 +1,36 @@
1
+ #!/bin/bash
2
+
3
+ PARENT_DIR=$(dirname $(cd "$(dirname "$0")"; pwd))
4
+ CI_DIR="$PARENT_DIR/ci/environment"
5
+ #CI_DIR=/tmp/travis
6
+
7
+ ODB_VERSION=${1:-"2.0.4"}
8
+ ODB_DIR="${CI_DIR}/orientdb-community-${ODB_VERSION}"
9
+ ODB_LAUNCHER="${ODB_DIR}/bin/server.sh"
10
+
11
+
12
+
13
+ echo "=== Initializing CI environment ==="
14
+ cd "$PARENT_DIR"
15
+ mkdir -p $CI_DIR
16
+
17
+ echo "--- Downloading OrientDB v${ODB_VERSION} ---"
18
+ wget -q -O "$CI_DIR/orientdb-community-${ODB_VERSION}.tar.gz" "http://www.orientechnologies.com/download.php?email=unknown@unknown.com&file=orientdb-community-${ODB_VERSION}.tar.gz&os=linux"
19
+
20
+ echo "--- Unpacking ---------------------"
21
+ tar xf $CI_DIR/orientdb-community-${ODB_VERSION}.tar.gz -C $CI_DIR
22
+
23
+ echo "--- Setting up --------------------"
24
+ chmod +x $ODB_LAUNCHER
25
+ chmod -R +rw "${ODB_DIR}/config/"
26
+ ODB_ADMIN="<users><user resources=\"*\" password=\"root\" name=\"root\"/></users>"
27
+ sed "s:^[ \t]*<users.*$: $ODB_ADMIN:" -i ${ODB_DIR}/config/orientdb-server-config.xml
28
+ sed "s:^[ \t]*<\/users.*$: <!-- \/users -->:" -i ${ODB_DIR}/config/orientdb-server-config.xml
29
+ sed "s:^handlers = .*$:handlers = java.util.logging.ConsoleHandler:" -i ${ODB_DIR}/config/orientdb-server-log.properties
30
+
31
+ echo "--- Starting server ---------------"
32
+ sh -c $ODB_LAUNCHER </dev/null &>/dev/null &
33
+
34
+ # Wait a bit for OrientDB to finish the initialization phase.
35
+ sleep 5
36
+ printf "=== The CI environment has been initialized ===\n"
@@ -31,14 +31,17 @@ module Orientdb4r
31
31
  # Gets a new database client or an existing for the current thread.
32
32
  # === options
33
33
  # * :instance => :new
34
+ # * :binary => true
35
+ # * :connection_library => :restclient | :excon
34
36
  def client options={}
35
37
  if :new == options[:instance]
36
38
  options.delete :instance
37
- return RestClient.new options
39
+ return options.delete(:binary) ? BinClient.new(options) : RestClient.new(options)
38
40
  end
39
41
 
40
42
  Thread.exclusive {
41
- Thread.current[:orientdb_client] ||= RestClient.new options
43
+ client = options.delete(:binary) ? BinClient.new(options) : RestClient.new(options)
44
+ Thread.current[:orientdb_client] ||= client
42
45
  #Thread.current[:orientdb_client] ||= BinClient.new options
43
46
  }
44
47
  end
@@ -1,12 +1,14 @@
1
1
  require 'socket'
2
2
  require 'bindata'
3
+ require 'orientdb4r/bin/constants'
4
+ require 'orientdb4r/bin/protocol_factory'
3
5
 
4
6
  module Orientdb4r
5
7
 
6
8
  ###
7
9
  # This client implements the binary protocol.
8
10
  class BinClient < Client
9
-
11
+ include BinConstants
10
12
 
11
13
  def initialize(options) #:nodoc:
12
14
  super()
@@ -30,19 +32,28 @@ module Orientdb4r
30
32
  @password = options[:password]
31
33
 
32
34
  socket = TCPSocket.open(@host, @port)
33
- protocol = BinData::Int16be.read(socket)
35
+ protocol_version = BinData::Int16be.read(socket).to_i
36
+
37
+ Orientdb4r::logger.info "Binary protocol version: #{protocol_version}"
34
38
 
35
- Orientdb4r::logger.info "Binary protocol number: #{protocol}"
39
+ # check minimal protocol version which is supported
40
+ #raise ConnectionError, "Protocols >= #{MINIMAL_PROTOCOL_VERSION} are supported. Please upgrade your OrientDb server." if protocol_version < MINIMAL_PROTOCOL_VERSION
41
+ protocol = ProtocolFactory.get_protocol(protocol_version)
36
42
 
37
- command = DbOpen.new
38
- command.version = protocol
39
- command.database = 'temp'
40
- command.user = 'admin'
41
- command.password = 'admin'
43
+ command = protocol::DbOpen.new
44
+ command.protocol_version = protocol_version
45
+ command.db_name = @database
46
+ command.user = @user
47
+ command.password = @password
42
48
  command.write(socket)
43
49
 
44
- resp = BinData::Int8.read(socket).to_i
45
- puts "EE #{resp}"
50
+ read_response(socket)
51
+
52
+ resp = { :session => read_integer(socket) }
53
+
54
+ # status = BinData::Int8.read(socket)
55
+ # session = BinData::Int32be.read(socket).to_i
56
+ puts "EE resp = #{resp.inspect}"
46
57
 
47
58
  socket.close
48
59
  end
@@ -56,42 +67,75 @@ module Orientdb4r
56
67
  raise NotImplementedError, 'this should be overridden by concrete client'
57
68
  end
58
69
 
59
- class ProtocolString < BinData::Primitive
60
- endian :big
61
70
 
62
- int32 :len, :value => lambda { data.length }
63
- string :data, :read_length => :len
71
+ # class Connect < BinData::Record
72
+ # endian :big
73
+
74
+ # int8 :operation, :value => 2
75
+ # int32 :session, :value => -1
76
+ # protocol_string :driver, :value => 'Orientdb4r Ruby Client'
77
+ # protocol_string :driver_version, :value => Orientdb4r::VERSION
78
+ # int16 :version
79
+ # protocol_string :client_id
80
+ # protocol_string :user
81
+ # protocol_string :password
82
+ # end
83
+ # class DbOpen < BinData::Record
84
+ # endian :big
85
+
86
+ # int8 :operation, :value => 3 #Orientdb4r::BinConstants::REQUEST_DB_OPEN
87
+ # int32 :session, :value => -1
88
+
89
+ # protocol_string :driver_name, :value => Orientdb4r::DRIVER_NAME
90
+ # protocol_string :driver_version, :value => Orientdb4r::VERSION
91
+ # int16 :protocol_version
92
+ # protocol_string :client_id
93
+ # protocol_string :serialization_impl, :value => 'ORecordDocument2csv'
94
+ # int8 :token_based, :value => 0
95
+ # protocol_string :db_name
96
+ # protocol_string :db_type, :value => 'document'
97
+ # protocol_string :user
98
+ # protocol_string :password
99
+ # end
100
+ # ------------------------------------------------------------------ Helpers
101
+
102
+ private
103
+
104
+ # Gets a hash of parameters.
105
+ def params(args = {})
106
+ args.merge({ session: connection.session })
107
+ end
64
108
 
65
- def get; self.data; end
66
- def set(v) self.data = v; end
109
+ def read_response(socket)
110
+ result = BinData::Int8.read(socket).to_i
111
+ raise_response_error(socket) unless result == Status::OK
67
112
  end
68
- class DbOpen < BinData::Record
69
- endian :big
70
-
71
- int8 :operation, :value => 3 #DB_OPEN
72
- int32 :session, :value => -1 #NEW_SESSION
73
-
74
- protocol_string :driver, :value => 'Orientdb4r Ruby Client'
75
- protocol_string :driver_version, :value => Orientdb4r::VERSION
76
- int16 :version
77
- protocol_string :client_id
78
- protocol_string :database
79
- protocol_string :user
80
- protocol_string :password
81
- end
82
- class Connect < BinData::Record
83
- endian :big
84
-
85
- int8 :operation, :value => 2
86
- int32 :session, :value => -1 #NEW_SESSION
87
- protocol_string :driver, :value => 'Orientdb4r Ruby Client'
88
- protocol_string :driver_version, :value => Orientdb4r::VERSION
89
- int16 :version
90
- protocol_string :client_id
91
- protocol_string :user
92
- protocol_string :password
113
+ def raise_response_error(socket)
114
+ session = read_integer(socket)
115
+ exceptions = []
116
+
117
+ while (result = read_byte(socket)) == Status::ERROR
118
+ exceptions << {
119
+ :exception_class => read_string(socket),
120
+ :exception_message => read_string(socket)
121
+ }
93
122
  end
94
123
 
124
+ Orientdb4r::logger.error "exception(s): #{exceptions}"
125
+
126
+ # if exceptions[0] && exceptions[0][:exception_class] == "com.orientechnologies.orient.core.exception.ORecordNotFoundException"
127
+ # raise RecordNotFound.new(session)
128
+ # else
129
+ # raise ServerError.new(session, *exceptions)
130
+ # end
131
+ end
132
+ def read_integer(socket)
133
+ BinData::Int32be.read(socket).to_i
134
+ end
135
+ def read_byte(socket)
136
+ BinData::Int8.read(socket).to_i
137
+ end
138
+
95
139
  end
96
140
 
97
141
  end
@@ -4,7 +4,7 @@ module Orientdb4r
4
4
  include Aop2
5
5
 
6
6
 
7
- before [:query, :command], :assert_connected
7
+ before [:query, :command, :gremlin, :batch], :assert_connected
8
8
  before [:create_class, :get_class, :class_exists?, :drop_class, :create_property], :assert_connected
9
9
  before [:create_document, :get_document, :update_document, :delete_document], :assert_connected
10
10
  around [:query, :command], :time_around
@@ -290,6 +290,20 @@ module Orientdb4r
290
290
  rslt
291
291
  end
292
292
 
293
+ ###
294
+ # Executes a Gremlin command against the database.
295
+ def gremlin(gremlin)
296
+ raise ArgumentError, 'gremlin query is blank' if blank? gremlin
297
+ response = call_server(:method => :post, :uri => "command/#{@database}/gremlin/#{CGI::escape(gremlin)}")
298
+ entries = process_response(response) do
299
+ raise NotFoundError, 'record not found' if response.body =~ /ORecordNotFoundException/
300
+ end
301
+
302
+ rslt = entries['result']
303
+ # mixin all document entries (they have '@class' attribute)
304
+ rslt.each { |doc| doc.extend Orientdb4r::DocumentMetadata unless doc['@class'].nil? }
305
+ rslt
306
+ end
293
307
 
294
308
  def command(sql) #:nodoc:
295
309
  raise ArgumentError, 'command is blank' if blank? sql
@@ -297,6 +311,14 @@ module Orientdb4r
297
311
  process_response(response)
298
312
  end
299
313
 
314
+ ###
315
+ # Executes a batch of operations in a single call.
316
+ def batch(operations)
317
+ response = call_server(:method => :post, :uri => "batch/#{@database}", \
318
+ :content_type => 'application/json', :data => operations.to_json)
319
+ process_response(response)
320
+ end
321
+
300
322
 
301
323
  # -------------------------------------------------------------------- CLASS
302
324
 
@@ -2,6 +2,7 @@ module Orientdb4r
2
2
 
3
3
  # Version history.
4
4
  VERSION_HISTORY = [
5
+ ['0.5.1', '2015-03-26', "Enh #39, PR #40"],
5
6
  ['0.5.0', '2015-03-03', "Compatible with OrientDB v2.x, PR #31, PR #32, PR #33"],
6
7
  ['0.4.1', '2013-09-03', "Enh #24, Enh #26, Enh #27"],
7
8
  ['0.4.0', '2013-08-14', "Closed gap between this driver and OrientDB v1.4.0+; Enh #20, BF #25"],
@@ -31,4 +32,7 @@ module Orientdb4r
31
32
  # Current version.
32
33
  VERSION = VERSION_HISTORY[0][0]
33
34
 
35
+ # Driver identification.
36
+ DRIVER_NAME = 'Orientdb4r Ruby Client'
37
+
34
38
  end
@@ -1,15 +1,19 @@
1
- require 'test/unit'
2
- $: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
- require 'orientdb4r'
1
+ require 'test_helper'
4
2
 
5
3
  ###
6
4
  # This class tests communication with OrientDB cluster and load balancing.
7
5
  class TestClient < Test::Unit::TestCase
8
6
 
9
- Orientdb4r::logger.level = Logger::DEBUG
10
-
11
7
  PROXY_URL = 'http://bad.domain.com'
12
8
 
9
+ ###
10
+ # Test inintialization of corresponding client type
11
+ def test_client_type
12
+ client = Orientdb4r.client :instance => :new
13
+ assert_instance_of Orientdb4r::RestClient, client
14
+ client = Orientdb4r.client :instance => :new, :binary => true
15
+ assert_instance_of Orientdb4r::BinClient, client
16
+ end
13
17
 
14
18
  ###
15
19
  # Test inintialization of single node.
@@ -1,18 +1,22 @@
1
- require 'test/unit'
2
- $: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
- require 'orientdb4r'
1
+ require 'test_helper'
4
2
 
5
3
  ###
6
4
  # This class tests DB management.
7
5
  class TestDatabase < Test::Unit::TestCase
8
6
 
9
7
  DB = 'temp'
10
- Orientdb4r::logger.level = Logger::DEBUG
11
8
 
12
9
  def setup
13
10
  @client = Orientdb4r.client
14
11
  end
15
12
 
13
+ def teardown
14
+ if @client.database_exists? :database => 'UniT', :user => 'root', :password => DB_ROOT_PASS
15
+ @client.delete_database :database => 'UniT', :user => 'root', :password => DB_ROOT_PASS
16
+ end
17
+ @client.disconnect
18
+ end
19
+
16
20
  ###
17
21
  # CONNECT
18
22
  def test_connect
@@ -43,9 +47,6 @@ class TestDatabase < Test::Unit::TestCase
43
47
  assert_raise Orientdb4r::UnauthorizedError do
44
48
  @client.connect :database => DB, :user => 'admin1', :password => 'admin'
45
49
  end
46
-
47
- # clean up
48
- @client.disconnect
49
50
  end
50
51
 
51
52
 
@@ -73,14 +74,14 @@ class TestDatabase < Test::Unit::TestCase
73
74
  assert_raise ArgumentError do @client.create_database(:database => 'UniT', :type => :foo); end
74
75
 
75
76
  assert_nothing_thrown do
76
- @client.create_database :database => 'UniT', :user => 'root', :password => 'root'
77
+ @client.create_database :database => 'UniT', :user => 'root', :password => DB_ROOT_PASS
77
78
  end
78
79
  assert_nothing_thrown do
79
80
  @client.get_database :database => 'UniT', :user => 'admin', :password => 'admin'
80
81
  end
81
82
  # creating an existing DB
82
83
  assert_raise Orientdb4r::ServerError do
83
- @client.create_database :database => 'UniT', :user => 'root', :password => 'root'
84
+ @client.create_database :database => 'UniT', :user => 'root', :password => DB_ROOT_PASS
84
85
  end
85
86
  # insufficient rights
86
87
  assert_raise Orientdb4r::UnauthorizedError do
@@ -92,12 +93,12 @@ class TestDatabase < Test::Unit::TestCase
92
93
  assert_nothing_thrown do
93
94
  @client.connect :database => 'UniT', :user => 'admin', :password => 'admin'
94
95
  end
95
- @client.delete_database({:database => 'UniT', :user => 'root', :password => 'root'})
96
+ @client.delete_database({:database => 'UniT', :user => 'root', :password => DB_ROOT_PASS})
96
97
 
97
98
  # create non-default DB: storage=local;type=graph
98
99
  assert_nothing_thrown do
99
- @client.create_database :database => 'UniT', :user => 'root', :password => 'root', :storage => :plocal, :type => :graph
100
- @client.delete_database :database => 'UniT', :user => 'root', :password => 'root'
100
+ @client.create_database :database => 'UniT', :user => 'root', :password => DB_ROOT_PASS, :storage => :plocal, :type => :graph
101
+ @client.delete_database :database => 'UniT', :user => 'root', :password => DB_ROOT_PASS
101
102
  end
102
103
  end
103
104
 
@@ -142,11 +143,11 @@ class TestDatabase < Test::Unit::TestCase
142
143
  ###
143
144
  # DELETE DATABASE
144
145
  def test_delete_database
145
- @client.create_database :database => 'UniT', :user => 'root', :password => 'root'
146
+ @client.create_database :database => 'UniT', :user => 'root', :password => DB_ROOT_PASS
146
147
 
147
148
  # deleting non-existing DB
148
149
  assert_raise Orientdb4r::ServerError do
149
- @client.delete_database :database => 'UniT1', :user => 'root', :password => 'root'
150
+ @client.delete_database :database => 'UniT1', :user => 'root', :password => DB_ROOT_PASS
150
151
  end
151
152
  # insufficient rights
152
153
  assert_raise Orientdb4r::UnauthorizedError do
@@ -154,7 +155,7 @@ class TestDatabase < Test::Unit::TestCase
154
155
  end
155
156
 
156
157
  assert_nothing_thrown do
157
- @client.delete_database({:database => 'UniT', :user => 'root', :password => 'root'})
158
+ @client.delete_database({:database => 'UniT', :user => 'root', :password => DB_ROOT_PASS})
158
159
  end
159
160
  end
160
161
 
@@ -165,8 +166,8 @@ class TestDatabase < Test::Unit::TestCase
165
166
  # admin/admin has not 'server.info' resource access in standard installation
166
167
  assert_raise Orientdb4r::OrientdbError do @client.server :user => 'admin', :password => 'admin'; end
167
168
 
168
- assert_nothing_thrown do @client.server :user => 'root', :password => 'root'; end
169
- rslt = @client.server :user => 'root', :password => 'root'
169
+ assert_nothing_thrown do @client.server :user => 'root', :password => DB_ROOT_PASS; end
170
+ rslt = @client.server :user => 'root', :password => DB_ROOT_PASS
170
171
  assert_instance_of Hash, rslt
171
172
  assert rslt.include? 'connections'
172
173
  assert_not_nil rslt['connections']
@@ -177,7 +178,7 @@ class TestDatabase < Test::Unit::TestCase
177
178
  # GET List Databases
178
179
  # Retrieves the available databases.
179
180
  def test_list_databases
180
- dbs = @client.list_databases :user => 'root', :password => 'root'
181
+ dbs = @client.list_databases :user => 'root', :password => DB_ROOT_PASS
181
182
  assert_not_nil dbs
182
183
  assert_instance_of Array, dbs
183
184
  assert !dbs.empty?
@@ -188,8 +189,11 @@ class TestDatabase < Test::Unit::TestCase
188
189
  ###
189
190
  # Test of :assert_connected before advice.
190
191
  def test_assert_connected
192
+ @client.disconnect if @client.connected? # to be sure it this method is called as first in this TestCase and thread local client is still connected
191
193
  assert_raise Orientdb4r::ConnectionError do @client.query 'SELECT FROM OUser'; end
192
- assert_raise Orientdb4r::ConnectionError do @client.query "INSERT INTO OUser(name) VALUES('x')"; end
194
+ assert_raise Orientdb4r::ConnectionError do @client.command "INSERT INTO OUser(name) VALUES('x')"; end
195
+ assert_raise Orientdb4r::ConnectionError do @client.gremlin("g.addVertex('class:X', 'prop1', 1, 'prop2', 'string1')"); end
196
+ assert_raise Orientdb4r::ConnectionError do @client.batch({:transaction => true, :operations => []}); end
193
197
  #BF #21 assert_raise Orientdb4r::ConnectionError do @client.create_class 'x'; end
194
198
  assert_raise Orientdb4r::ConnectionError do @client.create_property 'x', 'prop', :boolean; end
195
199
  assert_raise Orientdb4r::ConnectionError do @client.class_exists? 'x'; end
@@ -1,6 +1,4 @@
1
- require 'test/unit'
2
- $: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
- require 'orientdb4r'
1
+ require 'test_helper'
4
2
 
5
3
  ###
6
4
  # This class tests Data Definition Operarions.
@@ -8,7 +6,6 @@ class TestDdo < Test::Unit::TestCase
8
6
 
9
7
  CLASS = 'testing'
10
8
  DB = 'temp'
11
- Orientdb4r::logger.level = Logger::DEBUG
12
9
 
13
10
  def initialize(params)
14
11
  super params
@@ -1,6 +1,4 @@
1
- require 'test/unit'
2
- $: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
- require 'orientdb4r'
1
+ require 'test_helper'
4
2
 
5
3
  ###
6
4
  # This class tests Data Manipulation Operarions.
@@ -9,8 +7,6 @@ class TestDmo < Test::Unit::TestCase
9
7
 
10
8
  CLASS = 'testing'
11
9
  DB = 'temp'
12
- Orientdb4r::logger.level = Logger::DEBUG
13
-
14
10
 
15
11
  def setup
16
12
  @client = Orientdb4r.client
@@ -1,6 +1,4 @@
1
- require 'test/unit'
2
- $: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
- require 'orientdb4r'
1
+ require 'test_helper'
4
2
 
5
3
  ###
6
4
  # This class tests CRUD operarions on document.
@@ -9,8 +7,6 @@ class TestDocumentCrud < Test::Unit::TestCase
9
7
 
10
8
  CLASS = 'testing'
11
9
  DB = 'temp'
12
- Orientdb4r::logger.level = Logger::DEBUG
13
-
14
10
 
15
11
  def setup
16
12
  @client = Orientdb4r.client
@@ -142,4 +138,47 @@ class TestDocumentCrud < Test::Unit::TestCase
142
138
  assert_raise ArgumentError do @client.delete_document 'xx'; end
143
139
  end
144
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::ServerError do @client.batch({:operations => [{:type => :d, :record => {'@rid' => '#123:456'}}]}); end # bad cluster
161
+ assert_nothing_thrown do puts @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
+
145
184
  end
@@ -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
@@ -0,0 +1,10 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'test/unit'
5
+
6
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
7
+ require 'orientdb4r'
8
+
9
+ Orientdb4r::logger.level = Logger::FATAL
10
+ DB_ROOT_PASS = ENV['ORIENTDB_ROOT_PASS'] || 'root'
@@ -1,14 +1,9 @@
1
- require 'test/unit'
2
- $: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
- require 'orientdb4r'
1
+ require 'test_helper'
4
2
 
5
3
  ###
6
4
  # This class tests communication with OrientDB cluster and load balancing.
7
5
  class TestLoadBalancing < Test::Unit::TestCase
8
6
 
9
- Orientdb4r::logger.level = Logger::DEBUG
10
-
11
-
12
7
  ###
13
8
  # Test default Sequence strategy.
14
9
  def test_sequence_loadbalancing
@@ -1,6 +1,4 @@
1
- require 'test/unit'
2
- $: << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
- require 'orientdb4r'
1
+ require 'test_helper'
4
2
 
5
3
  ###
6
4
  # This class tests Utils methods.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orientdb4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vaclav Sykora
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-03 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -47,12 +47,15 @@ extra_rdoc_files:
47
47
  - LICENSE
48
48
  - README.rdoc
49
49
  files:
50
+ - ".coveralls.yml"
50
51
  - ".gitignore"
52
+ - ".travis.yml"
51
53
  - Gemfile
52
54
  - LICENSE
53
55
  - README.rdoc
54
56
  - Rakefile
55
57
  - changelog.txt
58
+ - ci/initialize-ci.sh
56
59
  - fstudy/design_v1.dia
57
60
  - fstudy/design_v1.png
58
61
  - fstudy/domain_model.dia
@@ -83,6 +86,8 @@ files:
83
86
  - test/test_ddo.rb
84
87
  - test/test_dmo.rb
85
88
  - test/test_document_crud.rb
89
+ - test/test_gremlin.rb
90
+ - test/test_helper.rb
86
91
  - test/test_loadbalancing.rb
87
92
  - test/test_utils.rb
88
93
  homepage: http://github.com/veny/orientdb4r
@@ -106,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
111
  version: 1.3.1
107
112
  requirements: []
108
113
  rubyforge_project:
109
- rubygems_version: 2.2.2
114
+ rubygems_version: 2.4.6
110
115
  signing_key:
111
116
  specification_version: 4
112
117
  summary: Ruby binding for Orient DB.
@@ -117,5 +122,7 @@ test_files:
117
122
  - test/test_ddo.rb
118
123
  - test/test_dmo.rb
119
124
  - test/test_document_crud.rb
125
+ - test/test_gremlin.rb
126
+ - test/test_helper.rb
120
127
  - test/test_loadbalancing.rb
121
128
  - test/test_utils.rb