Skip to content

Commit c8d6f5c

Browse files
Test suite improvements.
1 parent cc8e8e4 commit c8d6f5c

7 files changed

+1372
-129
lines changed

tests/test_2700_aq.py renamed to tests/test_2700_aq_dbobject.py

+38-126
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
# -----------------------------------------------------------------------------
2424

2525
"""
26-
2700 - Module for testing AQ
26+
2700 - Module for testing AQ with DbObject payloads.
2727
"""
2828

29-
import datetime
3029
import decimal
3130
import threading
3231
import unittest
@@ -43,64 +42,6 @@ class TestCase(test_env.BaseTestCase):
4342
("The Story of My Life", "Hellen Keller", decimal.Decimal("10.50")),
4443
("The Chronicles of Narnia", "C.S. Lewis", decimal.Decimal("25.25")),
4544
]
46-
json_queue_name = "TEST_JSON_QUEUE"
47-
json_data = [
48-
[
49-
2.75,
50-
True,
51-
"Ocean Beach",
52-
b"Some bytes",
53-
{"keyA": 1.0, "KeyB": "Melbourne"},
54-
datetime.datetime(2022, 8, 1, 0, 0),
55-
],
56-
[
57-
True,
58-
False,
59-
"String",
60-
b"Some Bytes",
61-
{},
62-
{"name": None},
63-
{"name": "John"},
64-
{"age": 30},
65-
{"Permanent": True},
66-
{
67-
"employee": {
68-
"name": "John",
69-
"age": 30,
70-
"city": "Delhi",
71-
"Parmanent": True,
72-
}
73-
},
74-
{"employees": ["John", "Matthew", "James"]},
75-
{
76-
"employees": [
77-
{"employee1": {"name": "John", "city": "Delhi"}},
78-
{"employee2": {"name": "Matthew", "city": "Mumbai"}},
79-
{"employee3": {"name": "James", "city": "Bangalore"}},
80-
]
81-
},
82-
],
83-
[
84-
datetime.datetime.today(),
85-
datetime.datetime(2004, 2, 1, 3, 4, 5),
86-
datetime.datetime(2020, 12, 2, 13, 29, 14),
87-
datetime.timedelta(8.5),
88-
datetime.datetime(2002, 12, 13, 9, 36, 0),
89-
oracledb.Timestamp(2002, 12, 13, 9, 36, 0),
90-
datetime.datetime(2002, 12, 13),
91-
],
92-
dict(name="John", age=30, city="New York"),
93-
[
94-
0,
95-
1,
96-
25.25,
97-
6088343244,
98-
-9999999999999999999,
99-
decimal.Decimal("0.25"),
100-
decimal.Decimal("10.25"),
101-
decimal.Decimal("319438950232418390.273596"),
102-
],
103-
]
10445

10546
def __deq_in_thread(self, results):
10647
with test_env.get_connection() as conn:
@@ -537,33 +478,7 @@ def notification_callback(message):
537478
conn.unsubscribe(sub)
538479

539480
def test_2721(self):
540-
"2721 - test enqueuing and dequeuing JSON payloads"
541-
queue = self.get_and_clear_queue(self.json_queue_name, "JSON")
542-
self.assertEqual(queue.payload_type, "JSON")
543-
for data in self.json_data:
544-
props = self.conn.msgproperties(payload=data)
545-
queue.enqone(props)
546-
self.conn.commit()
547-
queue.deqoptions.wait = oracledb.DEQ_NO_WAIT
548-
results = []
549-
while True:
550-
props = queue.deqone()
551-
if props is None:
552-
break
553-
results.append(props.payload)
554-
self.conn.commit()
555-
self.assertEqual(results, self.json_data)
556-
557-
def test_2722(self):
558-
"2722 - test enqueuing to a JSON queue without a JSON payload"
559-
queue = self.get_and_clear_queue(self.json_queue_name, "JSON")
560-
string_message = "This is a string message"
561-
props = self.conn.msgproperties(payload=string_message)
562-
with self.assertRaisesFullCode("DPY-2062"):
563-
queue.enqone(props)
564-
565-
def test_2723(self):
566-
"2723 - test message props enqtime"
481+
"2721 - test message props enqtime"
567482
queue = self.get_and_clear_queue(
568483
self.book_queue_name, self.book_type_name
569484
)
@@ -579,8 +494,8 @@ def test_2723(self):
579494
end_date = end_date.replace(microsecond=0)
580495
self.assertTrue(start_date <= props.enqtime <= end_date)
581496

582-
def test_2724(self):
583-
"2724 - test message props declared attributes"
497+
def test_2722(self):
498+
"2722 - test message props declared attributes"
584499
queue = self.get_and_clear_queue(
585500
self.book_queue_name, self.book_type_name
586501
)
@@ -597,29 +512,29 @@ def test_2724(self):
597512
for attr_name in values:
598513
self.assertEqual(getattr(props, attr_name), values[attr_name])
599514

600-
def test_2725(self):
601-
"2725 - test error for invalid type for payload_type"
515+
def test_2723(self):
516+
"2723 - test error for invalid type for payload_type"
602517
self.assertRaises(
603518
TypeError, self.conn.queue, "THE QUEUE", payload_type=4
604519
)
605520

606-
def test_2726(self):
607-
"2726 - test setting bytes to payload"
521+
def test_2724(self):
522+
"2724 - test setting bytes to payload"
608523
props = self.conn.msgproperties()
609524
bytes_val = b"Hello there"
610525
props.payload = bytes_val
611526
self.assertEqual(props.payload, bytes_val)
612527

613-
def test_2727(self):
614-
"2727 - test getting queue attributes"
528+
def test_2725(self):
529+
"2725 - test getting queue attributes"
615530
queue = self.get_and_clear_queue(
616531
self.book_queue_name, self.book_type_name
617532
)
618533
self.assertEqual(queue.name, self.book_queue_name)
619534
self.assertEqual(queue.connection, self.conn)
620535

621-
def test_2728(self):
622-
"2728 - test getting write-only attributes"
536+
def test_2726(self):
537+
"2726 - test getting write-only attributes"
623538
queue = self.get_and_clear_queue(
624539
self.book_queue_name, self.book_type_name
625540
)
@@ -628,8 +543,8 @@ def test_2728(self):
628543
with self.assertRaises(AttributeError):
629544
queue.deqoptions.deliverymode
630545

631-
def test_2729(self):
632-
"2729 - test correlation deqoption"
546+
def test_2727(self):
547+
"2727 - test correlation deqoption"
633548
queue = self.get_and_clear_queue(
634549
self.book_queue_name, self.book_type_name
635550
)
@@ -655,8 +570,8 @@ def test_2729(self):
655570
correlated_messages = queue.deqmany(num_messages + 1)
656571
self.assertEqual(len(correlated_messages), num_messages)
657572

658-
def test_2730(self):
659-
"2730 - test correlation deqoption with pattern-matching characters"
573+
def test_2728(self):
574+
"2728 - test correlation deqoption with pattern-matching characters"
660575
queue = self.get_and_clear_queue(
661576
self.book_queue_name, self.book_type_name
662577
)
@@ -672,8 +587,8 @@ def test_2730(self):
672587
messages = queue.deqmany(5)
673588
self.assertEqual(len(messages), 2)
674589

675-
def test_2731(self):
676-
"2731 - test condition deqoption with priority"
590+
def test_2729(self):
591+
"2729 - test condition deqoption with priority"
677592
queue = self.get_and_clear_queue(
678593
self.book_queue_name, self.book_type_name
679594
)
@@ -699,8 +614,8 @@ def test_2731(self):
699614
data = book.TITLE, book.AUTHORS, book.PRICE
700615
self.assertEqual(data, self.book_data[ix])
701616

702-
def test_2732(self):
703-
"2732 - test mode deqoption with DEQ_REMOVE_NODATA"
617+
def test_2730(self):
618+
"2730 - test mode deqoption with DEQ_REMOVE_NODATA"
704619
queue = self.get_and_clear_queue(
705620
self.book_queue_name, self.book_type_name
706621
)
@@ -720,42 +635,39 @@ def test_2732(self):
720635
self.assertIsNone(message.payload.AUTHORS)
721636
self.assertIsNone(message.payload.PRICE)
722637

723-
def test_2733(self):
724-
"2733 - test payload_type returns the correct value"
638+
def test_2731(self):
639+
"2731 - test payload_type returns the correct value"
725640
books_type = self.conn.gettype(self.book_type_name)
726641
queue = self.conn.queue(self.book_queue_name, books_type)
727642
self.assertEqual(queue.payload_type, books_type)
728643

729-
queue = self.conn.queue("TEST_RAW_QUEUE")
730-
self.assertIsNone(queue.payload_type)
731-
732-
def test_2734(self):
733-
"2734 - test deprecated attributes (enqOptions, deqOptions)"
734-
queue = self.get_and_clear_queue("TEST_RAW_QUEUE")
644+
def test_2732(self):
645+
"2732 - test deprecated attributes (enqOptions, deqOptions)"
646+
books_type = self.conn.gettype(self.book_type_name)
647+
queue = self.conn.queue(self.book_queue_name, books_type)
735648
self.assertEqual(queue.enqOptions, queue.enqoptions)
736649
self.assertEqual(queue.deqOptions, queue.deqoptions)
737650

738-
def test_2735(self):
739-
"2735 - test deprecated AQ methods (enqOne, deqOne)"
740-
value = b"Test 2734"
741-
queue = self.get_and_clear_queue("TEST_RAW_QUEUE")
742-
queue.enqOne(self.conn.msgproperties(value))
651+
def test_2733(self):
652+
"2733 - test deprecated AQ methods (enqOne, deqOne)"
653+
books_type = self.conn.gettype(self.book_type_name)
654+
queue = self.conn.queue(self.book_queue_name, books_type)
655+
book = queue.payload_type.newobject()
656+
book.TITLE, book.AUTHORS, book.PRICE = self.book_data[0]
657+
queue.enqOne(self.conn.msgproperties(book))
743658
props = queue.deqOne()
744-
self.assertEqual(props.payload, value)
659+
book = props.payload
660+
results = (book.TITLE, book.AUTHORS, book.PRICE)
661+
self.assertEqual(results, self.book_data[0])
745662

746-
def test_2736(self):
747-
"2736 - test enqueuing to an object queue with the wrong payload"
663+
def test_2734(self):
664+
"2734 - test enqueuing to an object queue with the wrong payload"
748665
queue = self.get_and_clear_queue(
749666
self.book_queue_name, self.book_type_name
750667
)
751668
props = self.conn.msgproperties(payload="A string")
752669
with self.assertRaisesFullCode("DPY-2062"):
753670
queue.enqone(props)
754-
typ = self.conn.gettype("UDT_SUBOBJECT")
755-
obj = typ.newobject()
756-
props = self.conn.msgproperties(payload=obj)
757-
with self.assertRaisesFullCode("DPY-2062"):
758-
queue.enqone(props)
759671

760672

761673
if __name__ == "__main__":

tests/test_2800_bulk_aq.py renamed to tests/test_2800_aq_bulk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2024, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2025, 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

tests/test_7800_aq_raw.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import oracledb
3030
import test_env
31+
import threading
3132

3233

3334
class TestCase(test_env.BaseTestCase):
@@ -40,6 +41,15 @@ class TestCase(test_env.BaseTestCase):
4041
b"sample raw data 6",
4142
]
4243

44+
def __deq_in_thread(self, results):
45+
with test_env.get_connection() as conn:
46+
queue = conn.queue("TEST_RAW_QUEUE")
47+
queue.deqoptions.wait = 10
48+
props = queue.deqone()
49+
if props is not None:
50+
results.append(props.payload)
51+
conn.commit()
52+
4353
def __verify_attr(self, obj, attrName, value):
4454
setattr(obj, attrName, value)
4555
self.assertEqual(getattr(obj, attrName), value)
@@ -107,10 +117,17 @@ def test_7804(self):
107117
self.__verify_attr(options, "visibility", oracledb.ENQ_IMMEDIATE)
108118

109119
def test_7805(self):
110-
"7805 - test errors for invalid values for enqueue"
120+
"7805 - test waiting for dequeue"
111121
queue = self.get_and_clear_queue("TEST_RAW_QUEUE")
122+
results = []
123+
thread = threading.Thread(target=self.__deq_in_thread, args=(results,))
124+
thread.start()
112125
value = self.raw_data[0]
113-
self.assertRaises(TypeError, queue.enqone, value)
126+
props = self.conn.msgproperties(payload=value)
127+
queue.enqone(props)
128+
self.conn.commit()
129+
thread.join()
130+
self.assertEqual(results, [value])
114131

115132
def test_7806(self):
116133
"7806 - test getting/setting message properties attributes"
File renamed without changes.

0 commit comments

Comments
 (0)