Skip to content

Commit fb71f11

Browse files
Additional test cases for AQ.
1 parent 011e062 commit fb71f11

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

test/AQ.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,86 @@
55
"""Module for testing AQ objects."""
66

77
import cx_Oracle
8+
import decimal
9+
import threading
810

911
class TestAQ(BaseTestCase):
12+
bookData = [
13+
("Wings of Fire", "A.P.J. Abdul Kalam",
14+
decimal.Decimal("15.75")),
15+
("The Story of My Life", "Hellen Keller",
16+
decimal.Decimal("10.50")),
17+
("The Chronicles of Narnia", "C.S. Lewis",
18+
decimal.Decimal("25.25"))
19+
]
20+
21+
def __deqInThread(self, results):
22+
connection = cx_Oracle.connect(USERNAME, PASSWORD, TNSENTRY)
23+
booksType = connection.gettype("UDT_BOOK")
24+
book = booksType.newobject()
25+
options = connection.deqoptions()
26+
options.wait = 10
27+
props = connection.msgproperties()
28+
if connection.deq("BOOKS", options, props, book):
29+
results.append((book.TITLE, book.AUTHORS, book.PRICE))
30+
connection.commit()
1031

1132
def __verifyAttribute(self, obj, attrName, value):
1233
setattr(obj, attrName, value)
1334
self.assertEqual(getattr(obj, attrName), value)
1435

36+
def testDeqEmpty(self):
37+
"test dequeuing an empty queue"
38+
booksType = self.connection.gettype("UDT_BOOK")
39+
book = booksType.newobject()
40+
options = self.connection.deqoptions()
41+
options.wait = cx_Oracle.DEQ_NO_WAIT
42+
props = self.connection.msgproperties()
43+
messageId = self.connection.deq("BOOKS", options, props, book)
44+
self.assertEqual(messageId, None)
45+
46+
def testDeqEnq(self):
47+
"test enqueuing and dequeuing multiple messages"
48+
booksType = self.connection.gettype("UDT_BOOK")
49+
options = self.connection.enqoptions()
50+
props = self.connection.msgproperties()
51+
for title, authors, price in self.bookData:
52+
book = booksType.newobject()
53+
book.TITLE = title
54+
book.AUTHORS = authors
55+
book.PRICE = price
56+
self.connection.enq("BOOKS", options, props, book)
57+
options = self.connection.deqoptions()
58+
options.navigation = cx_Oracle.DEQ_FIRST_MSG
59+
options.wait = cx_Oracle.DEQ_NO_WAIT
60+
results = []
61+
while self.connection.deq("BOOKS", options, props, book):
62+
row = (book.TITLE, book.AUTHORS, book.PRICE)
63+
results.append(row)
64+
self.connection.commit()
65+
self.assertEqual(results, self.bookData)
66+
67+
def testDeqModeRemoveNoData(self):
68+
"test dequeuing with DEQ_REMOVE_NODATA option"
69+
booksType = self.connection.gettype("UDT_BOOK")
70+
book = booksType.newobject()
71+
title, authors, price = self.bookData[1]
72+
book.TITLE = title
73+
book.AUTHORS = authors
74+
book.PRICE = price
75+
options = self.connection.enqoptions()
76+
props = self.connection.msgproperties()
77+
self.connection.enq("BOOKS", options, props, book)
78+
options = self.connection.deqoptions()
79+
options.navigation = cx_Oracle.DEQ_FIRST_MSG
80+
options.wait = cx_Oracle.DEQ_NO_WAIT
81+
options.mode = cx_Oracle.DEQ_REMOVE_NODATA
82+
book = booksType.newobject()
83+
messageId = self.connection.deq("BOOKS", options, props, book)
84+
self.connection.commit()
85+
self.assertTrue(messageId is not None)
86+
self.assertEqual(book.TITLE, "")
87+
1588
def testDeqOptions(self):
1689
"test getting/setting dequeue options attributes"
1790
options = self.connection.deqoptions()
@@ -26,11 +99,42 @@ def testDeqOptions(self):
2699
self.__verifyAttribute(options, "visibility", cx_Oracle.ENQ_IMMEDIATE)
27100
self.__verifyAttribute(options, "wait", 1287)
28101

102+
def testDeqWithWait(self):
103+
"test waiting for dequeue"
104+
results = []
105+
thread = threading.Thread(target = self.__deqInThread,
106+
args = (results,))
107+
thread.start()
108+
booksType = self.connection.gettype("UDT_BOOK")
109+
book = booksType.newobject()
110+
title, authors, price = self.bookData[0]
111+
book.TITLE = title
112+
book.AUTHORS = authors
113+
book.PRICE = price
114+
options = self.connection.enqoptions()
115+
props = self.connection.msgproperties()
116+
self.connection.enq("BOOKS", options, props, book)
117+
self.connection.commit()
118+
thread.join()
119+
self.assertEqual(results, [(title, authors, price)])
120+
29121
def testEnqOptions(self):
30122
"test getting/setting enqueue options attributes"
31123
options = self.connection.enqoptions()
32124
self.__verifyAttribute(options, "visibility", cx_Oracle.ENQ_IMMEDIATE)
33125

126+
def testErrorsForInvalidValues(self):
127+
"test errors for invalid values for options"
128+
booksType = self.connection.gettype("UDT_BOOK")
129+
book = booksType.newobject()
130+
options = self.connection.enqoptions()
131+
props = self.connection.msgproperties()
132+
self.assertRaises(TypeError, self.connection.deq, "BOOKS", options,
133+
props, book)
134+
options = self.connection.deqoptions()
135+
self.assertRaises(TypeError, self.connection.enq, "BOOKS", options,
136+
props, book)
137+
34138
def testMsgProps(self):
35139
"test getting/setting message properties attributes"
36140
props = self.connection.msgproperties()

test/sql/SetupTest.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ create or replace type &main_user..udt_Building as object (
9292
);
9393
/
9494

95+
create or replace type &main_user..udt_Book as object (
96+
Title varchar2(100),
97+
Authors varchar2(100),
98+
Price number(5,2)
99+
);
100+
/
101+
95102
-- create tables
96103
create table &main_user..TestNumbers (
97104
IntCol number(9) not null,
@@ -202,6 +209,15 @@ create table &main_user..TestRowids (
202209
URowidCol urowid
203210
);
204211

212+
-- create queue table and queues for testing advanced queuing
213+
begin
214+
dbms_aqadm.create_queue_table('&main_user..BOOK_QUEUE',
215+
'&main_user..UDT_BOOK');
216+
dbms_aqadm.create_queue('&main_user..BOOKS', '&main_user..BOOK_QUEUE');
217+
dbms_aqadm.start_queue('&main_user..BOOKS');
218+
end;
219+
/
220+
205221
-- populate tables
206222
begin
207223
for i in 1..10 loop

0 commit comments

Comments
 (0)