Skip to content

Commit 9f1019a

Browse files
Further test suite improvements.
1 parent 72eb6cf commit 9f1019a

File tree

7 files changed

+240
-6
lines changed

7 files changed

+240
-6
lines changed

tests/test_1900_lob_var.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -182,7 +182,10 @@ def __test_lob_operations(self, lob_type):
182182
self.assertEqual(lob.size(), 10000)
183183
self.assertRaisesRegex(oracledb.DatabaseError, "^DPY-2014:",
184184
lob.trim, new_size=50, newSize=60)
185+
self.assertRaises(TypeError, lob.trim, new_size="10000")
185186
self.assertRaises(TypeError, lob.trim, newSize="10000")
187+
lob.trim(new_size=40)
188+
self.assertEqual(lob.size(), 40)
186189
lob.trim()
187190
self.assertEqual(lob.size(), 0)
188191
self.assertIsInstance(lob.getchunksize(), int)

tests/test_2400_pool.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ def __perform_reconfigure_test(self, parameter_name, parameter_value,
9191
wait_timeout=5000, stmtcachesize=25,
9292
max_lifetime_session=1000,
9393
max_sessions_per_shard=3, ping_interval=30,
94-
getmode=oracledb.POOL_GETMODE_WAIT):
94+
getmode=oracledb.POOL_GETMODE_WAIT,
95+
soda_metadata_cache=False):
9596
creation_args = dict(min=min, max=max, increment=increment,
9697
timeout=timeout, wait_timeout=wait_timeout,
9798
stmtcachesize=stmtcachesize,
9899
max_lifetime_session=max_lifetime_session,
99100
max_sessions_per_shard=max_sessions_per_shard,
100-
ping_interval=ping_interval, getmode=getmode)
101+
ping_interval=ping_interval, getmode=getmode,
102+
soda_metadata_cache=soda_metadata_cache)
101103
reconfigure_args = {}
102104
reconfigure_args[parameter_name] = parameter_value
103105

@@ -111,7 +113,8 @@ def __perform_reconfigure_test(self, parameter_name, parameter_value,
111113
max_lifetime_session=pool.max_lifetime_session,
112114
max_sessions_per_shard=pool.max_sessions_per_shard,
113115
ping_interval=pool.ping_interval,
114-
getmode=pool.getmode)
116+
getmode=pool.getmode,
117+
soda_metadata_cache=pool.soda_metadata_cache)
115118
expected_args = creation_args.copy()
116119
expected_args.update(reconfigure_args)
117120
self.assertEqual(actual_args, expected_args)
@@ -487,6 +490,8 @@ def test_2416_test_reconfigure_pool_with_missing_values(self):
487490
self.__perform_reconfigure_test("ping_interval", 50)
488491
self.__perform_reconfigure_test("getmode",
489492
oracledb.POOL_GETMODE_NOWAIT)
493+
if test_env.get_client_version() >= (19, 11):
494+
self.__perform_reconfigure_test("soda_metadata_cache", True)
490495

491496
@unittest.skipIf(test_env.get_is_thin(),
492497
"thin mode doesn't support all the pool params yet")
@@ -783,5 +788,24 @@ def test_2435_acquire_with_different_cclass(self):
783788
self.assertEqual(next_sid_serial, sid_serial)
784789
self.assertEqual(pool.opened, 1)
785790

791+
def test_2436_pool_params_negative(self):
792+
"2436 - test creating a pool invalid params"
793+
self.assertRaisesRegex(oracledb.ProgrammingError, "^DPY-2027:",
794+
oracledb.create_pool, params="bad params")
795+
796+
def test_2437_conn_release_and_drop_negative(self):
797+
"2437 - test releasing and dropping an invalid connection"
798+
pool = test_env.get_pool()
799+
self.assertRaises(TypeError, pool.release, ["invalid connection"])
800+
self.assertRaises(TypeError, pool.drop, ["invalid connection"])
801+
802+
@unittest.skipIf(test_env.get_is_thin(),
803+
"thin mode doesn't set a pool name")
804+
def test_2438_name(self):
805+
"2438 - test getting pool name"
806+
pool = test_env.get_pool()
807+
expected_name = "^OCI:SP:.+"
808+
self.assertRegex(pool.name, expected_name)
809+
786810
if __name__ == "__main__":
787811
test_env.run_test_cases()

tests/test_2700_aq.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ def test_2715_enqueue_transformation(self):
404404
queue.enqoptions.transformation = \
405405
transformation_str = "%s.transform1" % self.connection.username
406406
queue.enqoptions.transformation = transformation_str
407+
if test_env.get_client_version() >= (23, 1):
408+
self.assertEqual(queue.enqoptions.transformation,
409+
transformation_str)
407410
props = self.connection.msgproperties(payload=book)
408411
queue.enqone(props)
409412
self.connection.commit()
@@ -560,5 +563,21 @@ def test_2726_set_payload_bytes(self):
560563
props.payload = bytes_val
561564
self.assertEqual(props.payload, bytes_val)
562565

566+
def test_2727_queue_attributes(self):
567+
"2727 - test getting queue attributes"
568+
queue = self.get_and_clear_queue(self.book_queue_name,
569+
self.book_type_name)
570+
self.assertEqual(queue.name, self.book_queue_name)
571+
self.assertEqual(queue.connection, self.connection)
572+
573+
def test_2728_get_write_only_attributes(self):
574+
"2728 - test getting write-only attributes"
575+
queue = self.get_and_clear_queue(self.book_queue_name,
576+
self.book_type_name)
577+
with self.assertRaises(AttributeError):
578+
queue.enqoptions.deliverymode
579+
with self.assertRaises(AttributeError):
580+
queue.deqoptions.deliverymode
581+
563582
if __name__ == "__main__":
564583
test_env.run_test_cases()

tests/test_3000_subscription.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -206,5 +206,29 @@ def test_3002_aq_subscription(self):
206206
# wait for all messages to be sent
207207
data.wait_for_messages()
208208

209+
@unittest.skip("FIXME: threaded mode fails on close of connection?")
210+
def test_3003_registerquery_returns(self):
211+
"3003 - test verifying what registerquery returns"
212+
data = DMLSubscriptionData(5)
213+
qos_constants = [
214+
oracledb.SUBSCR_QOS_QUERY,
215+
oracledb.SUBSCR_QOS_RELIABLE,
216+
oracledb.SUBSCR_QOS_DEREG_NFY,
217+
oracledb.SUBSCR_QOS_ROWIDS,
218+
oracledb.SUBSCR_QOS_BEST_EFFORT
219+
]
220+
for qos_constant in qos_constants:
221+
connection = test_env.get_connection(events=True)
222+
sub = connection.subscribe(qos=qos_constant,
223+
callback=data.callback_handler)
224+
query_id = sub.registerquery("select * from TestTempTable")
225+
if qos_constant == oracledb.SUBSCR_QOS_QUERY:
226+
self.assertEqual(type(query_id), int)
227+
self.assertEqual(type(sub.id), int)
228+
else:
229+
self.assertEqual(query_id, None)
230+
connection.unsubscribe(sub)
231+
connection.close()
232+
209233
if __name__ == "__main__":
210234
test_env.run_test_cases()

tests/test_3400_soda_collection.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,5 +565,51 @@ def test_3427_negative(self):
565565
self.assertRaises(TypeError, coll.find().version, 1971)
566566
self.assertRaises(TypeError, coll.find().limit, "a word")
567567

568+
def test_3428_fetch_array_size(self):
569+
"3428 - test fetchArraySize"
570+
soda_db = self.get_soda_database(minclient=(19, 5))
571+
coll = soda_db.createCollection("TestSodaFetchArraySize")
572+
coll.find().remove()
573+
for i in range(90):
574+
coll.save({'name': 'Emmanuel', 'age': i + 1})
575+
self.connection.commit()
576+
577+
self.setup_round_trip_checker()
578+
# setting array size to 0 will use the default value of 100
579+
# requires a single round-trip
580+
docs = coll.find().fetchArraySize(0).getDocuments()
581+
self.assertRoundTrips(1)
582+
583+
# setting array size to 1 requires a round-trip for each SodaDoc
584+
coll.find().fetchArraySize(1).getDocuments()
585+
self.assertRoundTrips(91)
586+
587+
# setting array size to 20 requires 5 round-trips
588+
coll.find().fetchArraySize(20).getDocuments()
589+
self.assertRoundTrips(5)
590+
591+
# getting a SodaDocCursor requires a round-trip
592+
coll.find().fetchArraySize(0).getCursor()
593+
self.assertRoundTrips(1)
594+
595+
# setting array size to 1 and iterating the SodaDocCursor requires a
596+
# round-trip for each SodaDoc
597+
soda_doc_cursor = coll.find().fetchArraySize(1).getCursor()
598+
for soda_doc in soda_doc_cursor:
599+
continue
600+
self.assertRoundTrips(91)
601+
602+
# setting array size to 50 and iterating the SodaDocCursor requires
603+
# two round-trips
604+
soda_doc_cursor = coll.find().fetchArraySize(50).getCursor()
605+
for soda_doc in soda_doc_cursor:
606+
continue
607+
self.assertRoundTrips(2)
608+
609+
# check a few negative scenarios
610+
self.assertRaises(TypeError, coll.find().fetchArraySize, "Mijares")
611+
self.assertRaises(TypeError, coll.find().fetchArraySize, -1)
612+
coll.drop()
613+
568614
if __name__ == "__main__":
569615
test_env.run_test_cases()

tests/test_4400_tpc.py

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2021, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2021, 2023, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -116,5 +116,109 @@ def test_4403_rollback_with_xid(self):
116116
order by IntCol""")
117117
self.assertEqual(self.cursor.fetchall(), [(1, 'tesName')])
118118

119+
def test_4404_tpc_begin_resume(self):
120+
"4404 - test resuming a transaction"
121+
self.cursor.execute("truncate table TestTempTable")
122+
xid1 = self.connection.xid(3939, "txn3939", "branch39")
123+
xid2 = self.connection.xid(3940, "txn3940", "branch40")
124+
values = [
125+
[xid1, (1, "User Info")],
126+
[xid2, (2, "Other User Info")]
127+
]
128+
for xid, data in values:
129+
self.connection.tpc_begin(xid)
130+
self.cursor.execute("""
131+
insert into TestTempTable (IntCol, StringCol1)
132+
values (:1, :2)""", data)
133+
self.connection.tpc_end()
134+
for xid, _ in values:
135+
self.assertRaisesRegex(oracledb.DatabaseError, "^ORA-24757:",
136+
self.connection.tpc_begin, xid)
137+
for xid, data in values:
138+
self.connection.tpc_begin(xid, oracledb.TPC_BEGIN_RESUME)
139+
self.cursor.execute(
140+
"select IntCol, StringCol1 from TestTempTable")
141+
res, = self.cursor.fetchall()
142+
self.assertEqual(res, data)
143+
self.connection.tpc_rollback(xid)
144+
145+
def test_4405_tpc_begin_promote(self):
146+
"4405 - test promoting a local transaction to a tpc transaction"
147+
self.cursor.execute("truncate table TestTempTable")
148+
xid = self.connection.xid(3941, "txn3941", "branch41")
149+
values = (1, "String 1")
150+
self.cursor.execute(
151+
"""insert into TestTempTable (IntCol, StringCol1)
152+
values (:1, :2)""", values)
153+
self.assertRaisesRegex(oracledb.DatabaseError, "^ORA-24776",
154+
self.connection.tpc_begin, xid)
155+
self.connection.tpc_begin(xid, oracledb.TPC_BEGIN_PROMOTE)
156+
self.cursor.execute("select IntCol, StringCol1 from TestTempTable")
157+
res, = self.cursor.fetchall()
158+
self.assertEqual(res, values)
159+
self.connection.tpc_rollback(xid)
160+
161+
def test_4406_tpc_end_with_xid(self):
162+
"4406 - test ending a transaction with parameter xid"
163+
self.cursor.execute("truncate table TestTempTable")
164+
xid1 = self.connection.xid(4406, "txn4406a", "branch3")
165+
xid2 = self.connection.xid(4406, "txn4406b", "branch4")
166+
self.connection.tpc_begin(xid1)
167+
self.cursor.execute("""
168+
insert into TestTempTable (IntCol, StringCol1)
169+
values (1, 'test4406a')""")
170+
self.connection.tpc_begin(xid2)
171+
self.assertRaisesRegex(oracledb.DatabaseError, "^ORA-24758:",
172+
self.connection.tpc_end, xid1)
173+
self.cursor.execute("""
174+
insert into TestTempTable (IntCol, StringCol1)
175+
values (2, 'test4406b')""")
176+
self.connection.tpc_end(xid2)
177+
self.assertRaisesRegex(oracledb.DatabaseError, "^ORA-25352:",
178+
self.connection.tpc_end, xid1)
179+
self.connection.tpc_rollback(xid1)
180+
self.connection.tpc_rollback(xid2)
181+
182+
def test_4407_tpc_recover(self):
183+
"4407 - test tpc_recover()"
184+
self.cursor.execute("truncate table TestTempTable")
185+
n_xids = 10
186+
for i in range(n_xids):
187+
xid = self.connection.xid(4407 + i, f"txn4407{i}", f"branch{i}")
188+
self.connection.tpc_begin(xid)
189+
self.cursor.execute("""
190+
insert into TestTempTable (IntCol, StringCol1)
191+
values (:1, 'test4407')""", [i + 1])
192+
self.connection.tpc_prepare(xid)
193+
recovers = self.connection.tpc_recover()
194+
self.assertEqual(len(recovers), n_xids)
195+
196+
self.cursor.execute("select * from DBA_PENDING_TRANSACTIONS")
197+
self.assertEqual(self.cursor.fetchall(), recovers)
198+
199+
for format_id, txn, branch in recovers:
200+
if format_id % 2 == 0:
201+
xid = self.connection.xid(format_id, txn, branch)
202+
self.connection.tpc_commit(xid)
203+
recovers = self.connection.tpc_recover()
204+
self.assertEqual(len(recovers), n_xids // 2)
205+
206+
for format_id, txn, branch in recovers:
207+
xid = self.connection.xid(format_id, txn, branch)
208+
self.connection.tpc_rollback(xid)
209+
recovers = self.connection.tpc_recover()
210+
self.assertEqual(len(recovers), 0)
211+
212+
def test_4408_tpc_recover_read_only(self):
213+
"4408 - test tpc_recover() with read-only transaction"
214+
self.cursor.execute("truncate table TestTempTable")
215+
for i in range(4):
216+
xid = self.connection.xid(4408 + i, f"txn4408{i}", f"branch{i}")
217+
self.connection.tpc_begin(xid)
218+
self.cursor.execute("select * from TestTempTable")
219+
self.connection.tpc_prepare(xid)
220+
recovers = self.connection.tpc_recover()
221+
self.assertEqual(len(recovers), 0)
222+
119223
if __name__ == "__main__":
120224
test_env.run_test_cases()

tests/test_4500_connect_params.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,5 +645,19 @@ def test_4562_connection_id_prefix(self):
645645
params.parse_connect_string("my_host4562b/my_service_name_4562b")
646646
self.assertEqual(params.connection_id_prefix, "prefix4562b")
647647

648+
def test_4563_override_parameters(self):
649+
"4563 - test overriding parameters with parse_connection_string"
650+
params = oracledb.ConnectParams()
651+
params.parse_connect_string("my_host:3578/my_service_name")
652+
params.set(service_name="new_service_name", port=613)
653+
self.assertEqual(params.service_name, "my_service_name")
654+
self.assertEqual(params.port, 3578)
655+
656+
params = oracledb.ConnectParams()
657+
params.set(service_name="my_service_name", port=613)
658+
params.parse_connect_string("my_host:3578/new_service_name")
659+
self.assertEqual(params.service_name, "new_service_name")
660+
self.assertEqual(params.port, 3578)
661+
648662
if __name__ == "__main__":
649663
test_env.run_test_cases()

0 commit comments

Comments
 (0)