Question
A module consists of two threads, a Producer and a consumer. There is a DB containing a table (OrderTable), that has two columns OrderNumber(int) &
A module consists of two threads, a Producer and a consumer.
There is a DB containing a table (OrderTable), that has two columns
OrderNumber(int) & Order(varchar(256))
The requirement is use a Producer Thread (or multiple Producer Threads) to send order data to a Consumer Thread, and the Consumer Thread stores the order data in the DB.
This is code common to both threads
Map
// representing the ordernumber
// map is C++ std::map or Java map
Int orderNumber = 1
Mutex orderMapLock // mutex used to lock orderMap
A Producer thread runs this code
Void ProducerCode(string order) { // order is a string like ProductId=12345|Num=1
Lock(orderMapLock)
Int curOrderNum = orderNumber++
orderMap.insert(Map
UnLock(orderMapLock)
}
A consumer thread runs this code
Void ConsumerCode() {
Lock(orderMapLock)
Int numOrders = 0
For (int I = 0; I < len(orderMap); I++) { // len(orderMap) is length of map
// Assume 1st element of map is at orderMap[0]
String order = orderMap[i].key
Int orderNumber = orderMap[i].value
Print(Order Number = %d, Order = %s ,
orderNumber,order) // orderMap[i] is ith element
StoreinOrderTableinDB(orderNumber,order) // Assume OrderTable has
// two columns an int for OrderNumber and a varchar for Order
numOrders++
}
If (numOrders) {
orderMap.clear() // clears the Map
UnLock(orderMapLock)
}
}
a)Write an Integration Test Case for both threads and a Test Oracle. The Test Oracle can assume that each tests starts fresh; i.e. the OrderTable is empty
b)Write Integration Test Cases for both threads, that exposes two major flaws
c)Suggest code changes to solve the major flaws exposed in b.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started