ruby-oci8 2.2.10-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +14 -0
- data/COPYING +30 -0
- data/COPYING_old +64 -0
- data/ChangeLog +3826 -0
- data/Makefile +92 -0
- data/NEWS +1209 -0
- data/README.md +66 -0
- data/dist-files +112 -0
- data/docs/bind-array-to-in_cond.md +38 -0
- data/docs/conflicts-local-connections-and-processes.md +98 -0
- data/docs/hanging-after-inactivity.md +63 -0
- data/docs/install-binary-package.md +44 -0
- data/docs/install-full-client.md +111 -0
- data/docs/install-instant-client.md +194 -0
- data/docs/install-on-osx.md +46 -0
- data/docs/ldap-auth-and-function-interposition.md +123 -0
- data/docs/number-type-mapping.md +79 -0
- data/docs/platform-specific-issues.md +164 -0
- data/docs/report-installation-issue.md +50 -0
- data/docs/timeout-parameters.md +94 -0
- data/lib/.document +1 -0
- data/lib/dbd/OCI8.rb +591 -0
- data/lib/oci8/.document +8 -0
- data/lib/oci8/bindtype.rb +333 -0
- data/lib/oci8/check_load_error.rb +146 -0
- data/lib/oci8/compat.rb +117 -0
- data/lib/oci8/connection_pool.rb +179 -0
- data/lib/oci8/cursor.rb +605 -0
- data/lib/oci8/datetime.rb +605 -0
- data/lib/oci8/encoding-init.rb +45 -0
- data/lib/oci8/encoding.yml +537 -0
- data/lib/oci8/metadata.rb +2148 -0
- data/lib/oci8/object.rb +641 -0
- data/lib/oci8/oci8.rb +756 -0
- data/lib/oci8/ocihandle.rb +591 -0
- data/lib/oci8/oracle_version.rb +153 -0
- data/lib/oci8/properties.rb +196 -0
- data/lib/oci8/version.rb +3 -0
- data/lib/oci8.rb +190 -0
- data/lib/oci8lib_310.so +0 -0
- data/lib/ruby-oci8.rb +1 -0
- data/metaconfig +142 -0
- data/pre-distclean.rb +7 -0
- data/ruby-oci8.gemspec +85 -0
- data/setup.rb +1342 -0
- data/test/README.md +37 -0
- data/test/config.rb +201 -0
- data/test/setup_test_object.sql +199 -0
- data/test/setup_test_package.sql +59 -0
- data/test/test_all.rb +56 -0
- data/test/test_appinfo.rb +62 -0
- data/test/test_array_dml.rb +332 -0
- data/test/test_bind_array.rb +70 -0
- data/test/test_bind_boolean.rb +99 -0
- data/test/test_bind_integer.rb +47 -0
- data/test/test_bind_raw.rb +45 -0
- data/test/test_bind_string.rb +105 -0
- data/test/test_bind_time.rb +177 -0
- data/test/test_break.rb +125 -0
- data/test/test_clob.rb +85 -0
- data/test/test_connection_pool.rb +124 -0
- data/test/test_connstr.rb +220 -0
- data/test/test_datetime.rb +585 -0
- data/test/test_dbi.rb +365 -0
- data/test/test_dbi_clob.rb +53 -0
- data/test/test_encoding.rb +103 -0
- data/test/test_error.rb +87 -0
- data/test/test_metadata.rb +2674 -0
- data/test/test_object.rb +546 -0
- data/test/test_oci8.rb +624 -0
- data/test/test_oracle_version.rb +68 -0
- data/test/test_oradate.rb +255 -0
- data/test/test_oranumber.rb +792 -0
- data/test/test_package_type.rb +981 -0
- data/test/test_properties.rb +17 -0
- data/test/test_rowid.rb +32 -0
- metadata +123 -0
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require File.dirname(__FILE__) + '/config'
|
3
|
+
|
4
|
+
class TestBindTime < Minitest::Test
|
5
|
+
|
6
|
+
YEAR_CHECK_TARGET = [1971, 1989, 2002, 2037]
|
7
|
+
MON_CHECK_TARGET = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
8
|
+
DAY_CHECK_TARGET = [1, 10, 20, 31] # days of January.
|
9
|
+
HOUR_CHECK_TARGET = [0, 6, 12, 18, 23]
|
10
|
+
MIN_CHECK_TARGET = [0, 15, 30, 45, 59]
|
11
|
+
SEC_CHECK_TARGET = [0, 15, 30, 45, 59]
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@conn = get_oci8_connection
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_set_year
|
18
|
+
cursor = @conn.parse("BEGIN :year := TO_NUMBER(TO_CHAR(:time, 'SYYYY'), '9999'); END;")
|
19
|
+
cursor.bind_param(:time, Time)
|
20
|
+
cursor.bind_param(:year, Fixnum)
|
21
|
+
|
22
|
+
YEAR_CHECK_TARGET.each do |i|
|
23
|
+
# set year
|
24
|
+
cursor[:time] = Time.local(i, 1)
|
25
|
+
# check result
|
26
|
+
cursor.exec
|
27
|
+
assert_equal(i, cursor[:year])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_get_year
|
32
|
+
cursor = @conn.parse("BEGIN :time := TO_DATE(TO_CHAR(:year, '0999'), 'SYYYY'); END;")
|
33
|
+
cursor.bind_param(:year, Fixnum)
|
34
|
+
cursor.bind_param(:time, Time)
|
35
|
+
YEAR_CHECK_TARGET.each do |i|
|
36
|
+
# set time via oracle.
|
37
|
+
cursor[:year] = i
|
38
|
+
cursor.exec
|
39
|
+
# check Time#year
|
40
|
+
assert_equal(i, cursor[:time].year)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_set_mon
|
45
|
+
cursor = @conn.parse("BEGIN :mon := TO_NUMBER(TO_CHAR(:time, 'MM'), '99'); END;")
|
46
|
+
cursor.bind_param(:time, Time)
|
47
|
+
cursor.bind_param(:mon, Fixnum)
|
48
|
+
MON_CHECK_TARGET.each do |i|
|
49
|
+
# set mon
|
50
|
+
cursor[:time] = Time.local(2001, i)
|
51
|
+
# check result via oracle.
|
52
|
+
cursor.exec
|
53
|
+
assert_equal(i, cursor[:mon])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_get_mon
|
58
|
+
cursor = @conn.parse("BEGIN :time := TO_DATE(TO_CHAR(:mon, '99'), 'MM'); END;")
|
59
|
+
cursor.bind_param(:mon, Fixnum)
|
60
|
+
cursor.bind_param(:time, Time)
|
61
|
+
MON_CHECK_TARGET.each do |i|
|
62
|
+
# set time via oracle.
|
63
|
+
cursor[:mon] = i;
|
64
|
+
cursor.exec
|
65
|
+
# check Time#mon
|
66
|
+
assert_equal(i, cursor[:time].mon)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_set_day
|
71
|
+
cursor = @conn.parse("BEGIN :day := TO_NUMBER(TO_CHAR(:time, 'DD'), '99'); END;")
|
72
|
+
cursor.bind_param(:time, Time)
|
73
|
+
cursor.bind_param(:day, Fixnum)
|
74
|
+
DAY_CHECK_TARGET.each do |i|
|
75
|
+
# set day
|
76
|
+
cursor[:time] = Time.local(2001, 1, i)
|
77
|
+
# check result via oracle.
|
78
|
+
cursor.exec
|
79
|
+
assert_equal(i, cursor[:day])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_get_day
|
84
|
+
cursor = @conn.parse("BEGIN :time := TO_DATE('200101' || TO_CHAR(:day, 'FM00'), 'YYYYMMDD'); END;")
|
85
|
+
cursor.bind_param(:day, Fixnum)
|
86
|
+
cursor.bind_param(:time, Time)
|
87
|
+
DAY_CHECK_TARGET.each do |i|
|
88
|
+
# set time via oracle.
|
89
|
+
cursor[:day] = i;
|
90
|
+
cursor.exec
|
91
|
+
# check Time#day
|
92
|
+
assert_equal(i, cursor[:time].day)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_set_hour
|
97
|
+
cursor = @conn.parse("BEGIN :hour := TO_NUMBER(TO_CHAR(:time, 'HH24'), '99'); END;")
|
98
|
+
cursor.bind_param(:time, Time)
|
99
|
+
cursor.bind_param(:hour, Fixnum)
|
100
|
+
HOUR_CHECK_TARGET.each do |i|
|
101
|
+
# set hour
|
102
|
+
cursor[:time] = Time.local(2001, 1, 1, i)
|
103
|
+
# check result via oracle.
|
104
|
+
cursor.exec
|
105
|
+
assert_equal(i, cursor[:hour])
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_get_hour
|
110
|
+
cursor = @conn.parse("BEGIN :time := TO_DATE(TO_CHAR(:hour, '99'), 'HH24'); END;")
|
111
|
+
cursor.bind_param(:hour, Fixnum)
|
112
|
+
cursor.bind_param(:time, Time)
|
113
|
+
HOUR_CHECK_TARGET.each do |i|
|
114
|
+
# set time via oracle.
|
115
|
+
cursor[:hour] = i
|
116
|
+
cursor.exec
|
117
|
+
# check Time#hour
|
118
|
+
assert_equal(i, cursor[:time].hour)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_set_min
|
123
|
+
cursor = @conn.parse("BEGIN :min := TO_NUMBER(TO_CHAR(:time, 'MI'), '99'); END;")
|
124
|
+
cursor.bind_param(:time, Time)
|
125
|
+
cursor.bind_param(:min, Fixnum)
|
126
|
+
MIN_CHECK_TARGET.each do |i|
|
127
|
+
# set min
|
128
|
+
cursor[:time] = Time.local(2001, 1, 1, 0, i)
|
129
|
+
# check result via oracle.
|
130
|
+
cursor.exec
|
131
|
+
assert_equal(i, cursor[:min])
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_get_min
|
136
|
+
cursor = @conn.parse("BEGIN :time := TO_DATE(TO_CHAR(:min, '99'), 'MI'); END;")
|
137
|
+
cursor.bind_param(:min, Fixnum)
|
138
|
+
cursor.bind_param(:time, Time)
|
139
|
+
MIN_CHECK_TARGET.each do |i|
|
140
|
+
# set time via oracle.
|
141
|
+
cursor[:min] = i;
|
142
|
+
cursor.exec
|
143
|
+
# check Time#min
|
144
|
+
assert_equal(i, cursor[:time].min)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_set_sec
|
149
|
+
cursor = @conn.parse("BEGIN :sec := TO_NUMBER(TO_CHAR(:time, 'SS'), '99'); END;")
|
150
|
+
cursor.bind_param(:time, Time)
|
151
|
+
cursor.bind_param(:sec, Fixnum)
|
152
|
+
SEC_CHECK_TARGET.each do |i|
|
153
|
+
# set sec
|
154
|
+
cursor[:time] = Time.local(2001, 1, 1, 0, 0, i)
|
155
|
+
# check result via oracle.
|
156
|
+
cursor.exec
|
157
|
+
assert_equal(i, cursor[:sec])
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_get_sec
|
162
|
+
cursor = @conn.parse("BEGIN :time := TO_DATE(TO_CHAR(:sec, '99'), 'SS'); END;")
|
163
|
+
cursor.bind_param(:sec, Fixnum)
|
164
|
+
cursor.bind_param(:time, Time)
|
165
|
+
SEC_CHECK_TARGET.each do |i|
|
166
|
+
# set time via oracle.
|
167
|
+
cursor[:sec] = i
|
168
|
+
cursor.exec
|
169
|
+
# check Time#sec
|
170
|
+
assert_equal(i, cursor[:time].sec)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def teardown
|
175
|
+
@conn.logoff
|
176
|
+
end
|
177
|
+
end
|
data/test/test_break.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# High-level API
|
2
|
+
require 'oci8'
|
3
|
+
require 'timeout'
|
4
|
+
require File.dirname(__FILE__) + '/config'
|
5
|
+
|
6
|
+
class TestBreak < Minitest::Test
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@conn = get_oci8_connection
|
10
|
+
Thread.report_on_exception, @original_report_on_exception = false, Thread.report_on_exception if Thread.respond_to?(:report_on_exception)
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
@conn.logoff
|
15
|
+
Thread.report_on_exception = @original_report_on_exception if Thread.respond_to?(:report_on_exception)
|
16
|
+
end
|
17
|
+
|
18
|
+
def report(str)
|
19
|
+
printf "%d: %s\n", (Time.now - $start_time), str
|
20
|
+
end
|
21
|
+
|
22
|
+
@@server_is_runing_on_windows = nil
|
23
|
+
def server_is_runing_on_windows?
|
24
|
+
if @@server_is_runing_on_windows.nil?
|
25
|
+
@conn.exec('select dbms_utility.port_string from dual') do |row|
|
26
|
+
@@server_is_runing_on_windows = row[0].include? '/WIN'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
@@server_is_runing_on_windows
|
30
|
+
end
|
31
|
+
|
32
|
+
PLSQL_DONE = 1
|
33
|
+
OCIBREAK = 2
|
34
|
+
SEND_BREAK = 3
|
35
|
+
|
36
|
+
TIME_IN_PLSQL = 5
|
37
|
+
TIME_TO_BREAK = 2
|
38
|
+
|
39
|
+
def do_test_ocibreak(conn, expect)
|
40
|
+
$start_time = Time.now
|
41
|
+
|
42
|
+
th = Thread.start do
|
43
|
+
begin
|
44
|
+
conn.exec("BEGIN DBMS_LOCK.SLEEP(#{TIME_IN_PLSQL}); END;")
|
45
|
+
assert_equal(expect[PLSQL_DONE], (Time.now - $start_time).round, 'PLSQL_DONE')
|
46
|
+
rescue OCIBreak
|
47
|
+
assert_equal(expect[OCIBREAK], (Time.now - $start_time).round, 'OCIBREAK')
|
48
|
+
assert_equal('Canceled by user request.', $!.to_s)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
sleep(0.3) # Wait until DBMS_LOCK.SLEEP is running.
|
53
|
+
sleep(TIME_TO_BREAK - 0.3)
|
54
|
+
assert_equal(expect[SEND_BREAK], (Time.now - $start_time).round, 'SEND_BREAK')
|
55
|
+
conn.break()
|
56
|
+
th.join
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_blocking_mode
|
60
|
+
@conn.non_blocking = false
|
61
|
+
assert_equal(false, @conn.non_blocking?)
|
62
|
+
expect = []
|
63
|
+
expect[PLSQL_DONE] = TIME_IN_PLSQL
|
64
|
+
expect[OCIBREAK] = "Invalid status"
|
65
|
+
if (defined? Rubinius and Rubinius::VERSION >= "2.0") || (defined? RUBY_ENGINE and RUBY_ENGINE == "truffleruby")
|
66
|
+
# Rubinius 2.0.0.
|
67
|
+
# DBMS_LOCK.SLEEP blocks ruby threads which try to call C-API.
|
68
|
+
expect[SEND_BREAK] = TIME_TO_BREAK
|
69
|
+
else
|
70
|
+
# MRI and Rubinius 1.2.4.
|
71
|
+
# DBMS_LOCK.SLEEP blocks all ruby threads.
|
72
|
+
expect[SEND_BREAK] = TIME_IN_PLSQL + TIME_TO_BREAK
|
73
|
+
end
|
74
|
+
do_test_ocibreak(@conn, expect)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_non_blocking_mode
|
78
|
+
@conn.non_blocking = true
|
79
|
+
assert_equal(true, @conn.non_blocking?)
|
80
|
+
expect = []
|
81
|
+
if server_is_runing_on_windows?
|
82
|
+
if $oracle_server_version >= OCI8::ORAVER_9_0
|
83
|
+
# raise after sleeping #{TIME_IN_PLSQL} seconds.
|
84
|
+
expect[PLSQL_DONE] = "Invalid status"
|
85
|
+
expect[OCIBREAK] = TIME_IN_PLSQL
|
86
|
+
else
|
87
|
+
expect[PLSQL_DONE] = TIME_IN_PLSQL
|
88
|
+
expect[OCIBREAK] = "Invalid status"
|
89
|
+
end
|
90
|
+
else
|
91
|
+
# raise immediately by OCI8#break.
|
92
|
+
expect[PLSQL_DONE] = "Invalid status"
|
93
|
+
expect[OCIBREAK] = TIME_TO_BREAK
|
94
|
+
end
|
95
|
+
expect[SEND_BREAK] = TIME_TO_BREAK
|
96
|
+
do_test_ocibreak(@conn, expect)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_timeout
|
100
|
+
@conn.non_blocking = true
|
101
|
+
start_time = Time.now
|
102
|
+
if server_is_runing_on_windows?
|
103
|
+
end_time = start_time + 5
|
104
|
+
else
|
105
|
+
end_time = start_time + 1
|
106
|
+
end
|
107
|
+
|
108
|
+
if defined? Rubinius and Rubinius::VERSION < "2.0"
|
109
|
+
# Rubinius 1.2.4
|
110
|
+
expected = OCIBreak
|
111
|
+
else
|
112
|
+
# MRI and Rubinius 2.0.0
|
113
|
+
expected = Timeout::Error
|
114
|
+
end
|
115
|
+
assert_raises(expected) do
|
116
|
+
Timeout.timeout(1) do
|
117
|
+
@conn.exec("BEGIN DBMS_LOCK.SLEEP(5); END;")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
assert_in_delta(Time.now, end_time, 1)
|
121
|
+
sleep(0.01) # for truffleruby. Is truffleruby too fast?
|
122
|
+
@conn.exec("BEGIN NULL; END;")
|
123
|
+
assert_in_delta(Time.now, end_time, 1)
|
124
|
+
end
|
125
|
+
end
|
data/test/test_clob.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Low-level API
|
2
|
+
require 'oci8'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
|
5
|
+
class TestCLob < Minitest::Test
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@conn = get_oci8_connection
|
9
|
+
drop_table('test_table')
|
10
|
+
@conn.exec('CREATE TABLE test_table (filename VARCHAR2(40), content CLOB)')
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_insert
|
14
|
+
filename = File.basename($lobfile)
|
15
|
+
@conn.exec("DELETE FROM test_table WHERE filename = :1", filename)
|
16
|
+
@conn.exec("INSERT INTO test_table(filename, content) VALUES (:1, EMPTY_CLOB())", filename)
|
17
|
+
cursor = @conn.exec("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)
|
18
|
+
lob = cursor.fetch[0]
|
19
|
+
open($lobfile) do |f|
|
20
|
+
while s = f.read(1000)
|
21
|
+
lob.write(s)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
lob.close
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_insert_symbol
|
28
|
+
filename = 'test_symbol'
|
29
|
+
value = :foo_bar
|
30
|
+
@conn.exec("DELETE FROM test_table WHERE filename = :1", filename)
|
31
|
+
@conn.exec("INSERT INTO test_table(filename, content) VALUES (:1, EMPTY_CLOB())", filename)
|
32
|
+
cursor = @conn.exec("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)
|
33
|
+
lob = cursor.fetch[0]
|
34
|
+
lob.write(value)
|
35
|
+
lob.rewind
|
36
|
+
assert_equal(value.to_s, lob.read);
|
37
|
+
lob.close
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_read
|
41
|
+
test_insert() # first insert data.
|
42
|
+
filename = File.basename($lobfile)
|
43
|
+
cursor = @conn.exec("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)
|
44
|
+
lob = cursor.fetch[0]
|
45
|
+
|
46
|
+
open($lobfile) do |f|
|
47
|
+
while buf = lob.read($lobreadnum)
|
48
|
+
fbuf = f.read(buf.size)
|
49
|
+
assert_equal(fbuf, buf)
|
50
|
+
# offset += buf.size will not work fine,
|
51
|
+
# Though buf.size counts in byte,
|
52
|
+
# offset and $lobreadnum count in character.
|
53
|
+
end
|
54
|
+
assert_nil(buf)
|
55
|
+
assert(f.eof?)
|
56
|
+
assert(lob.eof?)
|
57
|
+
end
|
58
|
+
lob.close
|
59
|
+
end
|
60
|
+
|
61
|
+
# https://github.com/kubo/ruby-oci8/issues/20
|
62
|
+
def test_github_issue_20
|
63
|
+
# Skip this test if FULLTEST isn't set because it takes 4 minutes in my Linux box.
|
64
|
+
return if ENV['FULLTEST']
|
65
|
+
|
66
|
+
lob1 = OCI8::CLOB.new(@conn, ' ' * (1024 * 1024))
|
67
|
+
lob1.read(1) # to suppress `warning: assigned but unused variable - lob1`
|
68
|
+
begin
|
69
|
+
lob2 = OCI8::CLOB.new(@conn, ' ' * (128 * 1024 * 1024))
|
70
|
+
rescue OCIError
|
71
|
+
raise if $!.code != 24817
|
72
|
+
# ORA-24817: Unable to allocate the given chunk for current lob operation
|
73
|
+
GC.start
|
74
|
+
# allocate smaller size
|
75
|
+
lob2 = OCI8::CLOB.new(@conn, ' ' * (16 * 1024 * 1024))
|
76
|
+
end
|
77
|
+
lob1 = nil # lob1's value will be freed in GC.
|
78
|
+
lob2.read # GC must run here to reproduce the issue.
|
79
|
+
end
|
80
|
+
|
81
|
+
def teardown
|
82
|
+
drop_table('test_table')
|
83
|
+
@conn.logoff
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require File.dirname(__FILE__) + '/config'
|
3
|
+
|
4
|
+
class TestConnectionPool < Minitest::Test
|
5
|
+
|
6
|
+
def create_pool(min, max, incr)
|
7
|
+
OCI8::ConnectionPool.new(min, max, incr, $dbuser, $dbpass, $dbname)
|
8
|
+
rescue OCIError
|
9
|
+
raise if $!.code != 12516 && $!.code != 12520
|
10
|
+
sleep(5)
|
11
|
+
OCI8::ConnectionPool.new(min, max, incr, $dbuser, $dbpass, $dbname)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_connect
|
15
|
+
pool = create_pool(1, 5, 3)
|
16
|
+
assert_equal(1, pool.min)
|
17
|
+
assert_equal(5, pool.max)
|
18
|
+
assert_equal(3, pool.incr)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_reinitialize
|
22
|
+
pool = create_pool(1, 5, 3)
|
23
|
+
pool.reinitialize(2, 6, 4)
|
24
|
+
assert_equal(2, pool.min)
|
25
|
+
assert_equal(6, pool.max)
|
26
|
+
assert_equal(4, pool.incr)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_busy_and_open_count
|
30
|
+
check_busy_and_open_count(1, 5, 3)
|
31
|
+
check_busy_and_open_count(2, 4, 1)
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_busy_and_open_count(min_cnt, max_cnt, incr_cnt)
|
35
|
+
msg = "create_pool(#{min_cnt}, #{max_cnt}, #{incr_cnt})"
|
36
|
+
# Create a connection pool.
|
37
|
+
pool = create_pool(min_cnt, max_cnt, incr_cnt)
|
38
|
+
assert_equal(min_cnt, pool.open_count, msg)
|
39
|
+
assert_equal(0, pool.busy_count, msg)
|
40
|
+
|
41
|
+
non_blocking = true
|
42
|
+
|
43
|
+
# Create connections from the pool.
|
44
|
+
conns = []
|
45
|
+
max_cnt.times do |cnt|
|
46
|
+
conn = OCI8.new($dbuser, $dbpass, pool)
|
47
|
+
if cnt == 0
|
48
|
+
unless conn.non_blocking?
|
49
|
+
non_blocking = false
|
50
|
+
assert_raises(RuntimeError) do
|
51
|
+
# This should raise "Could not set non-blocking mode to a connection allocated from OCI8::ConnectionPool."
|
52
|
+
conn.non_blocking = true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
conns << conn
|
57
|
+
end
|
58
|
+
assert_equal(min_cnt, pool.open_count, msg)
|
59
|
+
assert_equal(0, pool.busy_count, msg)
|
60
|
+
|
61
|
+
# Execute blocking SQL statements sequentially.
|
62
|
+
max_cnt.times do |n|
|
63
|
+
thread = Thread.start do
|
64
|
+
conns[n].exec "BEGIN DBMS_LOCK.SLEEP(1); END;"
|
65
|
+
end
|
66
|
+
sleep(0.5)
|
67
|
+
assert_equal(min_cnt, pool.open_count, msg)
|
68
|
+
assert_equal(non_blocking ? 1 : 0, pool.busy_count, msg)
|
69
|
+
thread.join
|
70
|
+
end
|
71
|
+
assert_equal(min_cnt, pool.open_count, msg)
|
72
|
+
assert_equal(0, pool.busy_count, msg)
|
73
|
+
|
74
|
+
# Execute blocking SQL statements parallel to increment open_count.
|
75
|
+
threads = []
|
76
|
+
(min_cnt + 1).times do |n|
|
77
|
+
threads << Thread.start do
|
78
|
+
conns[n].exec "BEGIN DBMS_LOCK.SLEEP(5); END;"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
sleep(0.5)
|
82
|
+
assert_equal(non_blocking ? (min_cnt + incr_cnt) : min_cnt, pool.open_count, msg)
|
83
|
+
assert_equal(non_blocking ? (min_cnt + 1) : 0, pool.busy_count, msg)
|
84
|
+
|
85
|
+
# Execute blocking SQL statements parallel up to maximum.
|
86
|
+
(min_cnt + 1).upto(max_cnt - 1) do |n|
|
87
|
+
threads << Thread.start do
|
88
|
+
conns[n].exec "BEGIN DBMS_LOCK.SLEEP(4); END;"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
sleep(0.5)
|
92
|
+
assert_equal(non_blocking ? max_cnt : min_cnt, pool.open_count, msg)
|
93
|
+
assert_equal(non_blocking ? max_cnt : 0, pool.busy_count, msg)
|
94
|
+
|
95
|
+
#
|
96
|
+
threads.each do |thr|
|
97
|
+
thr.join
|
98
|
+
end
|
99
|
+
assert_equal(non_blocking ? max_cnt : min_cnt, pool.open_count, msg)
|
100
|
+
assert_equal(0, pool.busy_count, msg)
|
101
|
+
|
102
|
+
# Set timeout
|
103
|
+
pool.timeout = 1
|
104
|
+
sleep(1.5)
|
105
|
+
assert_equal(non_blocking ? max_cnt : min_cnt, pool.open_count, msg) # open_count doesn't shrink.
|
106
|
+
assert_equal(0, pool.busy_count, msg)
|
107
|
+
conns[0].ping # make a network roundtrip.
|
108
|
+
sleep(0.5)
|
109
|
+
# open_count shrinks.
|
110
|
+
# The decrement count depends on Oracle version.
|
111
|
+
assert_operator(pool.open_count, :<, max_cnt, msg)
|
112
|
+
assert_equal(0, pool.busy_count, msg)
|
113
|
+
|
114
|
+
# Close all conections.
|
115
|
+
conns.each do | conn |
|
116
|
+
conn.logoff
|
117
|
+
end
|
118
|
+
assert_equal(min_cnt, pool.open_count, msg)
|
119
|
+
assert_equal(0, pool.busy_count, msg)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_nowait
|
123
|
+
end
|
124
|
+
end
|