Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 orderMap // string is key representing the order, int is value

// 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) // Inserts an element into the 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

=+ Explain the difference between financial liabilities and equity.

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago