[ruby-oci8-commit] [468] trunk/ruby-oci8: add some testcases.
nobody at rubyforge.org
nobody at rubyforge.org
Sun Nov 27 01:23:24 EST 2011
Revision: 468
Author: kubo
Date: 2011-11-27 01:23:24 -0500 (Sun, 27 Nov 2011)
Log Message:
-----------
add some testcases.
Modified Paths:
--------------
trunk/ruby-oci8/ChangeLog
trunk/ruby-oci8/test/test_all.rb
trunk/ruby-oci8/test/test_break.rb
trunk/ruby-oci8/test/test_oci8.rb
trunk/ruby-oci8/test/test_oranumber.rb
Added Paths:
-----------
trunk/ruby-oci8/test/test_connection_pool.rb
Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog 2011-11-26 06:59:12 UTC (rev 467)
+++ trunk/ruby-oci8/ChangeLog 2011-11-27 06:23:24 UTC (rev 468)
@@ -1,3 +1,11 @@
+2011-11-27 KUBO Takehiro <kubo at jiubao.org>
+ * test/test_break.rb: fix test_timeout test for an Oracle server
+ on Windows.
+ * test/test_all.rb, test/test_connection_pool.rb: add testcases
+ of OCI8::ConnectionPool.
+ * test/test_oci8.rb: add a testcase for OCI8#last_error.
+ * test/test_oranumber.rb: add a testcase for OCI8.properties[:float_conversion_type].
+
2011-11-26 KUBO Takehiro <kubo at jiubao.org>
* ext/oci8/object.c, test/test_object.rb: fix a bug that an array is
always bound as null. This bug was introduced in ruby-oci8 2.0.5.
Modified: trunk/ruby-oci8/test/test_all.rb
===================================================================
--- trunk/ruby-oci8/test/test_all.rb 2011-11-26 06:59:12 UTC (rev 467)
+++ trunk/ruby-oci8/test/test_all.rb 2011-11-27 06:23:24 UTC (rev 468)
@@ -22,6 +22,7 @@
require "#{srcdir}/test_appinfo"
require "#{srcdir}/test_oracle_version"
require "#{srcdir}/test_error"
+require "#{srcdir}/test_connection_pool"
if OCI8.respond_to? :encoding
require "#{srcdir}/test_encoding"
Modified: trunk/ruby-oci8/test/test_break.rb
===================================================================
--- trunk/ruby-oci8/test/test_break.rb 2011-11-26 06:59:12 UTC (rev 467)
+++ trunk/ruby-oci8/test/test_break.rb 2011-11-27 06:23:24 UTC (rev 468)
@@ -17,7 +17,18 @@
def report(str)
printf "%d: %s\n", (Time.now - $start_time), str
end
-
+
+ @@server_is_runing_on_windows = nil
+ def server_is_runing_on_windows?
+ if @@server_is_runing_on_windows.nil?
+ @@server_is_runing_on_windows = false
+ @conn.exec('select banner from v$version') do |row|
+ @@server_is_runing_on_windows = true if row[0].include? 'Windows'
+ end
+ end
+ @@server_is_runing_on_windows
+ end
+
PLSQL_DONE = 1
OCIBREAK = 2
SEND_BREAK = 3
@@ -56,15 +67,10 @@
end
def test_non_blocking_mode
- is_windows_server = false
- @conn.exec('select banner from v$version') do |row|
- is_windows_server = true if row[0].include? 'Windows'
- end
-
@conn.non_blocking = true
assert_equal(true, @conn.non_blocking?)
expect = []
- if is_windows_server
+ if server_is_runing_on_windows?
if $oracle_server_version >= OCI8::ORAVER_9_0
# raise after sleeping #{TIME_IN_PLSQL} seconds.
expect[PLSQL_DONE] = "Invalid status"
@@ -87,10 +93,16 @@
start_time = Time.now
assert_raise(Timeout::Error) do
Timeout.timeout(1) do
- @conn.exec("BEGIN DBMS_LOCK.SLEEP(10); END;")
+ @conn.exec("BEGIN DBMS_LOCK.SLEEP(5); END;")
end
end
+ if server_is_runing_on_windows?
+ end_time = start_time + 5
+ else
+ end_time = start_time + 1
+ end
+ assert_in_delta(Time.now, end_time, 1)
@conn.exec("BEGIN NULL; END;")
- assert_operator(Time.now, :<, start_time + 2)
+ assert_in_delta(Time.now, end_time, 1)
end
end
Added: trunk/ruby-oci8/test/test_connection_pool.rb
===================================================================
--- trunk/ruby-oci8/test/test_connection_pool.rb (rev 0)
+++ trunk/ruby-oci8/test/test_connection_pool.rb 2011-11-27 06:23:24 UTC (rev 468)
@@ -0,0 +1,114 @@
+require 'oci8'
+require 'test/unit'
+require File.dirname(__FILE__) + '/config'
+
+class TestConnectionPool < Test::Unit::TestCase
+
+ def create_pool(min, max, incr)
+ OCI8::ConnectionPool.new(min, max, incr, $dbuser, $dbpass, $dbname)
+ rescue OCIError
+ raise if $!.code != 12516 && $!.code != 12520
+ sleep(5)
+ OCI8::ConnectionPool.new(min, max, incr, $dbuser, $dbpass, $dbname)
+ end
+
+ def test_connect
+ pool = create_pool(1, 5, 3)
+ assert_equal(1, pool.min)
+ assert_equal(5, pool.max)
+ assert_equal(3, pool.incr)
+ end
+
+ def test_reinitialize
+ pool = create_pool(1, 5, 3)
+ pool.reinitialize(2, 6, 4)
+ assert_equal(2, pool.min)
+ assert_equal(6, pool.max)
+ assert_equal(4, pool.incr)
+ end
+
+ def test_busy_and_open_count
+ check_busy_and_open_count(1, 5, 3)
+ check_busy_and_open_count(2, 4, 1)
+ end
+
+ def check_busy_and_open_count(min_cnt, max_cnt, incr_cnt)
+ # Create a connection pool.
+ pool = create_pool(min_cnt, max_cnt, incr_cnt)
+ assert_equal(min_cnt, pool.open_count)
+ assert_equal(0, pool.busy_count)
+
+ # Create connections from the pool.
+ conns = []
+ max_cnt.times do
+ conns << OCI8.new($dbuser, $dbpass, pool)
+ end
+ assert_equal(min_cnt, pool.open_count)
+ assert_equal(0, pool.busy_count)
+
+ # Execute blocking SQL statements sequentially.
+ max_cnt.times do |n|
+ thread = Thread.start do
+ conns[n].exec "BEGIN DBMS_LOCK.SLEEP(1); END;"
+ end
+ sleep(0.5)
+ assert_equal(min_cnt, pool.open_count)
+ assert_equal(1, pool.busy_count)
+ thread.join
+ end
+ assert_equal(min_cnt, pool.open_count)
+ assert_equal(0, pool.busy_count)
+
+ # Execute blocking SQL statements parallel to increment open_count.
+ threads = []
+ (min_cnt + 1).times do |n|
+ threads << Thread.start do
+ conns[n].exec "BEGIN DBMS_LOCK.SLEEP(2); END;"
+ end
+ end
+ sleep(0.5)
+ assert_equal(min_cnt + incr_cnt, pool.open_count)
+ assert_equal(min_cnt + 1, pool.busy_count)
+
+ # Execute blocking SQL statements parallel up to maximum.
+ (min_cnt + 1).upto(max_cnt - 1) do |n|
+ threads << Thread.start do
+ conns[n].exec "BEGIN DBMS_LOCK.SLEEP(1); END;"
+ end
+ end
+ sleep(0.5)
+ assert_equal(max_cnt, pool.open_count)
+ assert_equal(max_cnt, pool.busy_count)
+
+ #
+ threads.each do |thr|
+ thr.join
+ end
+ assert_equal(max_cnt, pool.open_count)
+ assert_equal(0, pool.busy_count)
+
+ # Set timeout
+ pool.timeout = 1
+ sleep(1.5)
+ assert_equal(max_cnt, pool.open_count) # open_count doesn't shrink.
+ assert_equal(0, pool.busy_count)
+ conns[0].ping # make a network roundtrip.
+ sleep(0.5)
+ expected_cnt = max_cnt
+ while expected_cnt - incr_cnt > min_cnt
+ expected_cnt -= incr_cnt
+ end
+ assert_equal(expected_cnt, pool.open_count) # open_count shrinks.
+ assert_equal(0, pool.busy_count)
+
+ # Close all conections.
+ conns.each do | conn |
+ conn.logoff
+ end
+ assert_equal(min_cnt, pool.open_count)
+ assert_equal(0, pool.busy_count)
+ end
+
+ def test_nowait
+ end
+end
Modified: trunk/ruby-oci8/test/test_oci8.rb
===================================================================
--- trunk/ruby-oci8/test/test_oci8.rb 2011-11-26 06:59:12 UTC (rev 467)
+++ trunk/ruby-oci8/test/test_oci8.rb 2011-11-27 06:23:24 UTC (rev 468)
@@ -431,4 +431,21 @@
end
end
+ def test_last_error
+ # OCI8#parse and OCI8#exec reset OCI8#last_error
+ @conn.last_error = 'dummy'
+ @conn.exec('begin null; end;')
+ assert_nil(@conn.last_error)
+ @conn.last_error = 'dummy'
+ cursor = @conn.parse('select col1, max(col2) from (select 1 as col1, null as col2 from dual) group by col1')
+ assert_nil(@conn.last_error)
+
+ # When an OCI function returns OCI_SUCCESS_WITH_INFO, OCI8#last_error is set.
+ @conn.last_error = 'dummy'
+ cursor.exec
+ assert_equal('dummy', @conn.last_error)
+ cursor.fetch
+ assert_kind_of(OCISuccessWithInfo, @conn.last_error)
+ assert_equal(24347, @conn.last_error.code)
+ end
end # TestOCI8
Modified: trunk/ruby-oci8/test/test_oranumber.rb
===================================================================
--- trunk/ruby-oci8/test/test_oranumber.rb 2011-11-26 06:59:12 UTC (rev 467)
+++ trunk/ruby-oci8/test/test_oranumber.rb 2011-11-27 06:23:24 UTC (rev 468)
@@ -743,4 +743,35 @@
assert_equal(false, OraNumber(10.0).has_decimal_part?)
assert_equal(true, OraNumber(10.1).has_decimal_part?)
end
+
+ def test_float_conversion_type_ruby
+ orig = OCI8.properties[:float_conversion_type]
+ conn = get_oci8_connection
+ begin
+ OCI8.properties[:float_conversion_type] = :ruby
+ # Oracle Number -> Ruby Float
+ cursor = conn.parse('begin :out := :in; end;')
+ cursor.bind_param(:in, nil, String, 50)
+ cursor.bind_param(:out, nil, Float)
+ LARGE_RANGE_VALUES.each do |n|
+ cursor[:in] = n
+ cursor.exec
+ assert_equal(n.to_f, cursor[:out])
+ end
+ cursor.close
+ # Ruby Float -> Oracle Number
+ cursor = conn.parse('begin :out := :in; end;')
+ cursor.bind_param(:in, nil, Float)
+ cursor.bind_param(:out, nil, String, 50)
+ LARGE_RANGE_VALUES.each do |n|
+ cursor[:in] = n.to_f
+ cursor.exec
+ assert_equal(n.to_f, cursor[:out].to_f)
+ end
+ cursor.close
+ ensure
+ OCI8.properties[:float_conversion_type] = orig
+ conn.logoff
+ end
+ end
end
More information about the ruby-oci8-commit
mailing list