supermarket simulator.pdf

Upload: benitopro

Post on 03-Jun-2018

236 views

Category:

Documents


2 download

TRANSCRIPT

  • 8/12/2019 Supermarket simulator.pdf

    1/27

    Supermarket

    checkout simulationConcurrency and parallelism

    Txomin Sirera Ibarluzea - 13110349

    18/11/2013

    All about a supermarket checkouts simulation application carried out to help managers to

    reach a decision about the purchasing of new scanners.

  • 8/12/2019 Supermarket simulator.pdf

    2/27

  • 8/12/2019 Supermarket simulator.pdf

    3/27

    Content index

    1. Supermarket background ...................................................................................................... 4

    1.1. Application requirements ............................................................................................. 4

    1.1.1. Functional requirements ....................................................................................... 4

    1.1.2. Non-functional requirements................................................................................ 5

    1.2. Development environment ........................................................................................... 5

    1.3. Structure of the application .......................................................................................... 5

    2. Supermarket class diagram ................................................................................................... 6

    3. Class details ........................................................................................................................... 7

    3.1. CheckOut ....................................................................................................................... 7

    3.1.1. Variables ................................................................................................................ 7

    3.1.2. Constructor ............................................................................................................ 8

    3.1.3. Operations ............................................................................................................. 8

    3.2. Customer ..................................................................................................................... 12

    3.2.1. Variables .............................................................................................................. 12

    3.2.2. Constructor .......................................................................................................... 12

    3.2.3. Operations ........................................................................................................... 12

    3.3. Item ............................................................................................................................. 14

    3.3.1. Variables .............................................................................................................. 14

    3.3.2. Constructor .......................................................................................................... 14

    3.3.3. Operations ........................................................................................................... 14

    3.4. Worker......................................................................................................................... 15

    3.4.1. Variables .............................................................................................................. 15

    3.4.2. Constructor .......................................................................................................... 15

    3.4.3. Operations ........................................................................................................... 15

    3.5. SpecialWorker ............................................................................................................. 16

    3.6. Supermarket ................................................................................................................ 16

    3.6.1. Variables .............................................................................................................. 16

    3.6.2. Constructor .......................................................................................................... 17

    3.6.3. Operations ........................................................................................................... 17

    4. Process phases .................................................................................................................... 19

    4.1. Supermarket ................................................................................................................ 19

    4.2. Worker......................................................................................................................... 20

    4.3. Customer ..................................................................................................................... 20

  • 8/12/2019 Supermarket simulator.pdf

    4/27

    4.4. Interpreting the output ............................................................................................... 22

    5. Testing the application ........................................................................................................ 24

    5.1. Worker behaviour test ................................................................................................ 24

    5.2. Customer behaviour test ............................................................................................. 24

    5.2.1. Successfully treated customer ............................................................................ 24

    5.2.1. Unsuccessfully treated customer ........................................................................ 25

    5.3. Encountered errors ..................................................................................................... 25

    Illustration indexFigure 1: Supermarket ................................................................................................................... 4

    Figure 2: Class diagram ................................................................................................................. 6

    Figure 3: CheckOut class details .................................................................................................. 11

    Figure 4: Customer class details .................................................................................................. 14

    Figure 5: Item class details .......................................................................................................... 15

    Figure 6: Worker class details ..................................................................................................... 16

    Figure 7: SpecialWorker class details .......................................................................................... 16

    Figure 8: Supermarket class details ............................................................................................. 18

    Figure 9: Customer/Worker interaction...................................................................................... 19

    Figure 10: Supermarket flow chart ............................................................................................. 20

    Figure 11: Worker flow chart ...................................................................................................... 20

    Figure 12: Customer flow chart ................................................................................................... 21

  • 8/12/2019 Supermarket simulator.pdf

    5/27

    1. Supermarket backgroundA big supermarket

    1chain wants a simulation of their checkouts. There is a new scanners

    technology on the market, the use of them would reduce the scanning time for each item,

    because they are much more reliable, but three of the new scanners cost as much as five ofthe old ones. The managers want to know if it worth the purchase of these products. The aim

    of the application is to help them reach a conclusion giving them a source of data to make or

    not the investment.

    This document gives all the information needed for the understanding and comprehension of

    that project.

    Figure 1: Supermarket

    1.1. Application requirementsManagers have decided that the application should cover the following functional and non-

    functional requirements.

    1.1.1. Functional requirementsAll these requirements have been implemented in the application using final variables,providing easy modifiable simulations.

    A variable number of functioning checkouts. The number of products for each trolley to be generated randomly within a user

    specified range.

    The time for each product to be entered at the checkout to be generated randomlywithin a user specified range.

    One or more checkouts to have a restriction on the number of items

    1See Figure 1

  • 8/12/2019 Supermarket simulator.pdf

    6/27

    The rate the customer arrives at the checkouts to be generated randomly within a userspecified range.

    Total wait time for each customer. Total utilization for each checkout. Total products processed. Average customer waiting time. Average checkout utilisation. Average products per trolley. The number of lost customers (Customers will leave the store if they need to join a

    queue more than six deep or if the car park is full).

    1.1.2. Non-functional requirementsThe non-functional requirements are basically related with reliability and use of the checkouts,

    these two features are connected with concurrent programming. First goes the reliability

    (safety) and then the checkout utilisation (liveness), this has been the order followed whenprogramming, resulting in a high performance application.

    1.2. Development environmentThe application has been built in Java programming language and it has been release under the

    Eclipse IDE2. One of the main characteristics of the application is the use of concurrency,

    resulting on different responses every time it is executed.

    The class diagrams have been built with Visual Paradigms3for UML 2.0 tool; this is

    a UML CASE Tool supporting UML 2, SysML and Business Process Modelling Notation

    (BPMN) from the Object Management Group (OMG). In addition to modelling support, it

    provides report generation and code engineering capabilities including code generation. It

    can reverse engineer diagrams from code, and provide round-trip engineering for

    various programming languages.

    1.3. Structure of the applicationThe application has an internal structure based on package distribution:

    Main: Contains the main class (Supermarket4) of the application. Customer: Contains all classes related with the customer. Checkout: Contains all classes related with the checkout functions. Worker: Contains all classes related with the worker.

    2

    For further information check http://www.eclipse.org/3For further information check http://www.visual-paradigm.com/

    4See Supermarket class

  • 8/12/2019 Supermarket simulator.pdf

    7/27

    2. Supermarket class diagramThe class diagram of an application provides a general idea of its structure and attributes and

    operations in each class, the one below (Figure 1) shows just the relations between them.

    Figure 2: Class diagram

    There, can be seen that the Supermarket class is in the middle of the application, within it

    executes and finalizes the application. There is the mainoperation and the variable

    initialization. These variables are composed by a list of Worker and Customer, a CheckOut

    object and more control variables.

    The Worker class is a generalization for SpecialWorker, which is used as fast checkout; it has

    a limit of maximum quantity of products if someone wants to use it. This class receives the

    CheckOut in its constructor to use it synchronized5operations, because each

    Worker/SpecialWorker is a thread.

    The Item object is used by the Customer several times to simulate the goods that are going to

    be bought. This one also receives the CheckOut class in its constructor because the same

    reason as the Worker does.

    5Thread synchronization ensures that objects are modified by only one thread at a time and that

    threads are prevented from accessing partially updated objects during modification by another thread

  • 8/12/2019 Supermarket simulator.pdf

    8/27

    3. Class detailsIn the lines below each class of the application is presented in detail, explaining what do each

    variable count and what each operation do.

    3.1. CheckOutThe CheckOut6class has all the synchronized operations. These operations are used by theCustomer, Worker and Supermarket threads; the last one is using it to get the summaries of

    each checkout and more detailed information about purchases and customers.

    3.1.1. Variables NO_SELECTED_CHECKOUT: This variable sets the number associated with a no selected

    checkout. Helps to identify customers with more than x tries to enter in a queue. The

    type is a final int.

    numberOfCustomersInSupermarket: This variable counts the total customers insidethe supermarket. Its type is an int.

    lostCustomers: This variable counts the amount of customers lost because the capacityof the car park. Its type is an int.

    checkOutId: This variable is a unique identification for each checkout. Its type is an int. totalCustomersInQueue: This variable counts the total amount of customers in all

    queues. Its type is an int.

    totalCustomersForCustomCheckOut: This variable counts the total amount ofcustomers in custom queues. Its type is an int.

    specialCheckOutsBegin: This variable contains the value of the first special checkout id.Its type is an int.

    allowedCustomCustomersInQueue: This variable sets the total amount of customersallowed to be in queues. Its type is an int.

    lostCustomersAfterShopping: This variable counts the amount of customers lostbecause the availability of the queues. Its type is an int.

    totalCustomerWaitTime: This variable is used to know the wait time in the queue foreach customer. Its type is a long.

    itemsInCheckOut: This variable reflects the total amount of items treated by eachcheckout. Its type is an array of ints.

    customersInQueue: This variable reflects the quantity of customers in each checkoutqueue. Its type is an array of ints.

    customersInCheckOut: This variable reflects the total amount of customers treated byeach checkout. Its type is an array of ints.

    paid: This variable reflects the current status of each checkout in terms of paying. Itstype is an array of booleans.

    charged: This variable reflects the current status of each checkout in terms of charging.Its type is an array of booleans.

    occupied: This variable reflects the current status of each checkout in terms ofavailability. Its type is an array of booleans.

    6See Figure2

  • 8/12/2019 Supermarket simulator.pdf

    9/27

    queueAvailability: This variable reflects the current status of each queue checkout interms of availability. Its type is an array of booleans.

    noQueueAvailable: This variable gathers if all queues are full. Its type is a boolean.3.1.2. Constructor

    The constructor is used to initialize all variables.

    All int variables are initialized to 0 apart from specialCheckOutsBegin, which gets thevalue of the least of total checkout quantity and number of special checkouts.

    Sizes for arrays are set; all of them, apart from allowedCustomCustomersInQueue, arethe same as the checkout quantities. The other one is initialized with the least of the

    total checkouts multiplied by the maximum amount of customers in queue and the

    special checkout quantity multiplied by maximum amount of customers in queue.

    o int arrays are initialized to 0 for each checkout.o paid, charged and occupied are initialized to false for each checkout.o queueAvailability is initialized to true for each checkout.

    3.1.3. OperationsAll operations in this class has the prefix of synchronized, that is because is the class Customer

    and Worker are going to use independently changing variables, that is the reason of that

    prefix.

    enterSupermarket:o Receives: int.o Returns: Boolean.o Execution: This operation is executed by the customer. The operation checks

    the total amount of customers in the supermarket car park, if it is full, the

    customer does not enter the supermarket incrementing the value of

    lostCustomers, if not it parks the car and enters inside, incrementing the

    numberOfCustomersInSupermarket. After all the process, it returns if it enters

    or not.

    selectQueue:o Receives: int and int.o Returns: int.o Variables:

    queueSelected: This says if the customer has or not selected a queue.Its type is a Boolean.

    noForSpecialCheckOut: This says if the customer can use a specialcheckout or not. Its type is a Boolean.

    intents: Total attempts of trying to enter in a queue. Its type is an int.o Execution: This operation is executed by the customer. It prints out that

    customer is doing the shopping, and how many items do it entered in the

    trolley. The items quantity is passed into the checkCustomerOption7operation

    and after that the value of noForSpecialCheckOut is changed. Depending on

    the value of that, the customer is going to try to find a free queue. If the

    7See checkCustomerOption operation

  • 8/12/2019 Supermarket simulator.pdf

    10/27

  • 8/12/2019 Supermarket simulator.pdf

    11/27

    o Execution: This operation is executed by the customer. The operation is calledafter the customer has selected a queue. The value of the customers in the

    queue for that checkout is incremented as the total customers in queues. If

    the quantity of customers in queues is equal to the maximum customers

    permitted, the noQueueAvailable becomes true, and then it notifies the other

    of the updates done. Finally, if the checkout selected is occupied, the

    customer waits until it becomes available.

    waitCustomers:o Receives: int.o Returns:o Execution: This operation is called by the worker; it makes the worker wait

    until some customer enters the queue associated with its own checkout, when

    this happens the worker changes its availability and notifies the other.

    charge:o Receives: int.o Returns:o Execution: This operation is called by the worker, here it waits until the

    customer has paid , when that happens it changes its availability and updates

    the value of the charged on true, then it notifies the other.

    getSummary:o Receives:o Returns:o Variables:

    totalTreatedCustomers: This variable counts the quantity of the totalamount of customers treated. Its type is an int.

    totalTreatedItems: This variable counts the quantity of the totalamount of items treated. Its type is an int.

    o Execution: This operation is executed by the supermarket. The operationexecutes a loop that goes from the first to the last checkout getting their

    amount of clients and items treated; after the loop, the general information is

    shown.

    closeSupermarket:o Receives:o

    Returns:o Execution: This operation is executed by the supermarket. The operation is

    executed once the number of customers in supermarket is 0 and it is closed. It

    changes the status of the paid and charged lists and then notifies the others.

    checkCustomerOption:o Receives: int.o Returns: Boolean.o Variables:

    noForSpecialCheckOut: This variable determines if the customer canaccess or not the special checkout. Its type is a Boolean.

  • 8/12/2019 Supermarket simulator.pdf

    12/27

    o Execution: This operation takes into account the value received and itcompares with SPECIAL_CHECKOUT_MAX_ITEM_QTY

    10, if is less than it the

    value of noForSpecialCheckOut is set on false, else it is true. The value is

    returned to be used in other operations and notified to the others.

    collectSurvey:o Receives: long.o Returns:o Execution: This operation is called by the customer; it updates the value of

    totalCustomerWaitTime summing up the value received. Then it notifies to the

    others of the change.

    leftGoodsAndGoHomeUpset:o Receives: int.o Returns:o Execution: This operation is executed by the customer. The operation reduces

    the number of customers in the supermarket and sums the number ofcustomers lost after doing the shopping. Then it notifies about the changes.

    Figure 3: CheckOut class details

    10See Supermarket class

  • 8/12/2019 Supermarket simulator.pdf

    13/27

    3.2. CustomerThis class is the one which simulates the customer behaviour. It is a thread, so each customer

    executes the run operation inside, that execution is made simultaneously by every customer.

    3.2.1. Variables MAX_ITEMS: This variable sets the number associated with the maximum items that a

    customer can purchase. The type is a final int.

    MAX_PARKING_TIME: This variable sets the number associated with the maximumtime that a customer can spend parking the car. The type is a final int.

    MAX_SHOPPING_TIME: This variable sets the number associated with the maximumtime that a customer can spend doing the shopping. The type is a final int.

    checkout: This variable contains all functionalities of the Checkout class, allowing thecustomer to use its operations. Its type is a Checkout.

    entered: This variable sets if the customer has entered in the supermarket or not. Itstype is a Boolean.

    items: This variable holds the items purchased by the customer. Its type is an array ofItem.

    checkOutId: This variable is related to the id checkout selected by the customer afterthe shopping process. Its type is an int.

    customerId: This variable is the id of each customer, this helps to distinguish them. Itstype is an int.

    startWaitTime: This variable holds the exact time when the customer enters a queue.Its type is a long.

    endWaitTime: This variable holds the exact time when the customer leaves a queue.Its type is a long.

    totalWaitTime: This variable holds the total time when the customer enters a queue.Its type is a long.

    3.2.2. ConstructorThe constructor is used to initialize all variables.

    This constructor receives two variables:o int: It is an identification number.o CheckOut: It carries all operations of the class.

    The checkout and the customer id are equalled to the variables the customer has. All long variables are initialized to 0. The entered Boolean is set to false.3.2.3. Operations run:

    o Receives:o Returns:o Execution: This operation is executed when the customer is created and called.

    The first thing a customer does is to park the car. When it is trying to park the

  • 8/12/2019 Supermarket simulator.pdf

    14/27

  • 8/12/2019 Supermarket simulator.pdf

    15/27

    o Execution: It simulates the customer shopping time; it only sleeps the threadof the customer for the number calculated for shoppingTime variable.

    Figure 4: Customer class details

    3.3. ItemThe Item

    18object is created to simulate the goods the customer buys.

    3.3.1. Variables ITEM_WAITING_MAX_VALUE: This variable sets the number of maximum number of

    waiting for items to be processed. The type is a final int.

    ITEM_WAITING_MIN_VALUE: This variable sets the number of minimum number ofwaiting for items to be processed. The type is a final int.

    itemWaitingDifference: It keeps the value of the possible numbers to be used whengenerating the item waiting time. Its type is an int.

    itemWaitValue: It contains the value of the waiting time of the item. Its type is an int.3.3.2. Constructor

    The constructor is used to initialize all variables.

    The itemWaitingDifference is set with the least between ITEM_WAITING_MAX_VALUEand ITEM_WAITING_MIN_VALUE. And then the itemWaitValue is set randomly from 1to the value get in the itemWaitingDifference.

    3.3.3. Operations getItemWaitValue:

    o Receives:o Returns: int.o Execution: Just an operation to get the value of the variable itemWaitValue.

    18See Figure 4

  • 8/12/2019 Supermarket simulator.pdf

    16/27

    Figure 5: Item class details

    3.4. WorkerThis class is the one which simulates the worker behaviour. It is a thread, so each worker

    executes the run operation inside, that execution is made simultaneously by every worker.

    3.4.1. Variables checkOutId: This variable is the id of each customer, this helps to distinguish them. Its

    type is an int.

    checkout: This variable contains all functionalities of the Checkout class, allowing thecustomer to use its operations. Its type is a Checkout.

    3.4.2. ConstructorThe constructor is used to initialize all variables.

    This constructor receives two variables:o int: It is an identification number.o CheckOut: It carries all operations of the class.

    The checkout and the worker id are equalled to the variables the customer has.3.4.3. Operations run:

    o Receives:o Returns:o Execution: This operation is executed while the supermarket is opened, once it

    closes, the execution ends. First it calls the waitCustomer19

    operation passing

    its own id. Then it charges the customers. And these steps are repeated until

    the end.

    goHome:o Receives: int.o Returns:o Execution: It prints out that the worker has gone home.

    19See waitCustomer operation in CheckOut class

  • 8/12/2019 Supermarket simulator.pdf

    17/27

    Figure 6: Worker class details

    3.5. SpecialWorkerThe SpecialWorker

    20extends the Worker class, so it has the same operations and variables that

    its predecessor has.

    Figure 7: SpecialWorker class details

    3.6. SupermarketThe Supermarket

    21class its the main class. This class is where the application starts the

    initialization and first steps for the simulation. Most of its variables are static, making it

    available at the class level.

    3.6.1. Variables MAX_CUSTOMER_QTY_IN_SUPERMARKET_CAR_PARK: This variable sets the number

    of maximum number of customers in the car park. The type is a final int.

    SUPERMARKET_OPEN_TIME: This variable simulates the opening hour of thesupermarket. The type is a final int.

    SUPERMARKET_CLOSE_TIME: This variable simulates the closing hour of thesupermarket. The type is a final int.

    MAX_CUSTOMERS_IN_QUEUE: This variable sets the maximum number of customerthat can be waiting in the same queue. The type is a final int.

    MAX_CHECKOUTS: This variable sets the maximum number of checkouts in thesupermarket. The type is a final int.

    MAX_SPECIAL_CHECKOUTS: This variable sets the maximum number of specialcheckouts in the supermarket. The type is a final int.

    SPECIAL_CHECKOUT_MAX_ITEM_QTY: This variable sets the maximum number ofitems allowed to access the special checkouts. The type is a final int.

    MAX_QUEUE_INTENTS: This variable sets the maximum attempts that a customer cando to try to enter in a queue before it leaves the supermarket. The type is a final int.

    closed: This variable sets if the supermarket it closed or not. Its type is a Boolean. workers: A set of workers that contains every of them and its executions. Its type is an

    array of Worker.

    customers: A set of customers that contains every of them and its executions. Its typeis an arrayList of Customer.

    20See Figure 6

    21See Figure 7

  • 8/12/2019 Supermarket simulator.pdf

    18/27

    checkout: The variable that contains all operations of the CheckOut class. Its type is aCheckOut.

    supermarketOpenTime: This variable holds the total time of the supermarket since itopens till close time. Its type is an int.

    3.6.2. ConstructorThe constructor is used to initialize all variables.

    The array of workers is initialized with the size of MAX_CHECKOUTS22, the checkOutvariable is pointed to its class CheckOut and the supermarketOpenTime contains the

    least between SUPERMARKET_CLOSE_TIME23

    and SUPERMARKET_OPEN_TIME24

    .

    The next step is to initialize the workers; there is a loop that depending on the quantityof MAX_SPECIAL_CHECKOUTS

    25creates a custom or a special checkout passing their id

    and checkOut variables. After that loop, there is another that sets the customers

    depending on supermarketOpenTime26

    ; customers are created with an id and the

    checkOut variables.

    Finally, the Boolean of closed is set to false.3.6.3. Operations main: Its the starting point for the execution of the code in the application. There are

    initialized the constructor and the operations that are going to be executed.

    placeWorkers:o Receives:o Returns:o Executes: This operation consists in a loop that starts the threads of the

    workers array.

    openSupermarket:o Receives:o Returns:o Executes: This operation consists in a loop that starts the threads of the

    customers arrayList.

    closeSupermarket:o Receives:o Returns:o

    Executes: This operation waits for the finalization of the customer threadsusing the join method. After that it gets the summaries of the checkouts

    (getSummary27

    ), changes the value of the closed Boolean into true and after

    calling the goHome28

    operation for each worker, it closes the supermarket

    22See Supermarket class

    23See Supermarket class

    24See Supermarket class

    25See Supermarket class

    26

    See Supermarket class27See getSummary operation in CheckOut class

    28See goHome operation in CheckOut class

  • 8/12/2019 Supermarket simulator.pdf

    19/27

    with closeSupermarket29

    operation finishing the application and printing all

    the results on the screen.

    Figure 8: Supermarket class details

    29See closeSupermarket operation in CheckOut class

  • 8/12/2019 Supermarket simulator.pdf

    20/27

    4. Process phasesWhen the application is executed there can be seen a principal way that later on is divided on

    two: what the worker does and what the customer does. The process is based in threading and

    their synchronization, so there can be seen an interaction between customer and worker using

    the checkout. After their execution, they join the principal way again, finishing the execution.

    The figure below (Figure 8) shows the interaction between Customer30

    and Worker31

    , an

    asterisk means that the process changes a Boolean variable state which unlocks the next step

    execution. When a customer or a worker calls a synchronized operation and inside it there is a

    wait method, the caller is slept and every time the notifyAll is called it is woken up and

    tries to execute the next step, if someone is ahead, it falls asleep again.

    Figure 9: Customer/Worker interaction

    4.1. SupermarketWhen the application is launched this is the first thing what happens, the supermarket opens

    its doors, positions the workers and creates all customers. After all customers are gone, it gets

    the summary of each checkout, makes the workers go home and it closes.

    The figure below (Figure 8) shows the supermarket behaviour as a flow chart.

    30See 4.3 point

    31See 4.2 point

  • 8/12/2019 Supermarket simulator.pdf

    21/27

    Figure 10: Supermarket flow chart

    4.2. WorkerWhen the supermarket is opened and places worker

    32, each worker starts waiting for a

    customer. Once a customer has entered its queue and reached the checkout, charges the

    customer after being paid and updates the values of the customers and items treated quantity.

    This process is repeated while there are no more customers and supermarket is closed when

    that happens, they go home.

    The figure below (Figure 9) shows the worker behaviour as a flow chart.

    Figure 11: Worker flow chart

    4.3. CustomerAfter the doors of the supermarket are opened, customers are created, each one has to park

    the car and this takes some time, but the car park has a limit, so if the limit is reached, they

    leave the supermarket without doing the shopping.

    32Special workers are placed too, but at the moment the only difference is that customers have an item

    limit to use them.

  • 8/12/2019 Supermarket simulator.pdf

    22/27

  • 8/12/2019 Supermarket simulator.pdf

    23/27

    4.4. Interpreting the output --SUPERMARKET OPENED--: This means that the supermarket has just been opened. WorkerNplaced in checkout: This means that the customer number N has been placed

    in the assigned checkout.

    CustomerMparking the car: This means that the customer number M is parking thecar.

    CustomerMis gone because supermarket car park is full: This means that the car parkmaximum capacity to harbour cars has reached and the customer number M has left

    the supermarket without even entering inside.

    CustomerMenters supermarket: This means that the customer number M has enteredthe supermarket.

    CustomerMshopping...(X): This means that the customer number M is doing theshopping and it has taken X number of items in the trolley.

    CustomerMleaves supermarket(X) after trying to get in a queue Ntimes: This meansthat the customer number M has left the supermarket because it tried to access in a

    queue more than N times. The X number means how many customers are in the

    supermarket.

    CustomerMwaiting in queue(X) for checkOutN:This means that the customer numberM is waiting in the queue for the checkout number N. The X number means the

    amount of customers waiting in the queue.

    CustomerMhas paid in checkOutNand leaves supermarket(X): This means that thecustomer number M has paid in the checkout number N and has left the supermarket.

    The X number means the amount of customer in the supermarket.

    Customer

    M

    waiting time:X:

    This means that the customer number M has wait X time. ///////NO QUEUES AVAILABLE////////: This means that all queues are full and the

    customer has to wait to enter one.

    ********CheckOutNsummary******: This means that the summary of the number Ncheckout begins.

    o Total clients treated:X:This means that X number of customers have beentreated by the checkout number N.

    o Total items treated:X: This means that X number of items have been treatedby the checkout number N.

    Total treated customers:X:This means that X number of customers have been treatedtotally since the supermarket opened till close time.

    Total treated products:X: This means that X number of items have been treated totallysince the supermarket opened till close time.

    Lost customers because queue availability:X:This means that the supermarket has lostX number of customers because they have tried to enter a queue unsuccessfully.

    Lost customers because car park availability:X: This means that the supermarket haslost X number of customers because the lack of spaces in the car park.

    Average products per trolley:X: This means that X amount of items are the generalaverage in each trolley.

    Average wait time per customer:

    X:This means that the customers has spent X time in

    average since they enter a queue until they left the supermarket.

  • 8/12/2019 Supermarket simulator.pdf

    24/27

    WorkerNhas gone home: This means that the worker number N has gone home. --SUPERMARKET CLOSED--: This means that the supermarket is closed.

  • 8/12/2019 Supermarket simulator.pdf

    25/27

    5. Testing the applicationIt must be said that applications that contains threads inside are not easy to test, because you

    can get the same result 99% of the times, but get an error when the other 1% is executed. The

    testing of this application has been carried out, mostly, by the use of the debugger the Eclipse

    IDE provides.

    Both tests have been done after the application was finished, making the test as easy as

    changing final variables. It must be said that all variables and operations have been declared as

    public to have access to them in every part of the code, making their tracking easier.

    5.1. Worker behaviour testTo test the worker behaviour only one worker was executed, so all customer are going to use

    the checkout assigned to it. As the worker is a thread, the run method is the only interesting

    one for testing, so a breakpoint is set in it there and in the operations it calls to check the

    successfulness of all steps. Once the application is launched on the debug mode, the resultsare the following:

    1. The worker is successfully placed and has a checkout assigned2. As the Boolean of the supermarket status is false, it enters the loop.3. The worker is waiting.

    a. When a customer came it wakes up4. Changes the availability status5. Waits until its paid

    a. When the customer pays it wakes up6. Changes the status of the checkout and says to the customer that it was already

    charged.

    These six steps were repeated while the amount of customers in the supermarket is 0. Apart

    from the debug, the system prints out all the activity, so it is quite easy to track what is going

    on.

    5.2. Customer behaviour testThe customer behaviour is more difficult to track, but the well-structure of the application has

    helped a lot in this aspect. For example the naming of the operations is very logic, so the steps

    can be distinguished easily. There are two types of customers, the ones that have been treated

    successfully and the customers that have left the supermarket due to some reason.

    As all customers are threads, the only interesting operation inside the class is the run; that is

    why a breakpoint is set there before the debugging process. Once the application is launched,

    the results are the following.

    5.2.1. Successfully treated customer1. The customer is successfully created and tries to enter the supermarket2. As there are no customers, the customer enters the supermarket3. The customer makes the shopping4. The customer selects a queue5. The customer enters a queue

  • 8/12/2019 Supermarket simulator.pdf

    26/27

    6. The customer updates the value of the pay statusa. Waits until the worker chargesb. Once it happens it wakes up

    7. Changes the control values8. Passes its wait time values to the application

    These steps are executed by every successfully treated customer. Apart from the debug, the

    system prints out all the activity, so it is quite easy to track what is going on.

    5.2.1. Unsuccessfully treated customerHere there are two kinds of customers too, the ones that leave the supermarket even entering

    inside and the ones that after making the shopping has left the supermarket. For both of them,

    the debug breakpoint is set in the selectQueue33

    and enterSupermarket34

    operations.

    Without entering the supermarket:1.

    The customer is successfully created and tries to enter the supermarket

    2. The supermarket is full and the customer cannot enter3. The customer leaves the supermarket

    After entering the supermarket:1. The customer is successfully created and tries to enter the supermarket2. As there are no customers, the customer enters the supermarket3. The customer makes the shopping4. The customer selects a queue5. The customer reaches the maximum attempts permitted to access a queue6. The customer leaves the supermarket

    As is said previously, apart from the debug, the system prints out all the activity, so it is quite

    easy to track what is going on.

    5.3. Encountered errorsWhile the testing has being done, there have been encountered some errors, most errors are

    related with the threading issue, but there are few ones linked with logic.

    About logic issues, the biggest trouble has been to find a logic to select a queue properly, this

    happens because if the customer can use a special checkout priories the use of them. If they

    are not available, it looks at the customs, as it happens in real life. The issue is that the

    customers for custom checkouts and special checkouts must be separate; this provides the

    amount of customers for each type of checkout.

    On the other hand, the biggest issue related to threading was that after all the execution the

    workers continued running. To fix this problem the application was modified to print out the

    living status of each worker thread, the result was that they were waiting for something. That

    did not make sense at first because there were no customers in the supermarket. So after

    several tests, the problem was found. The workers were waiting for customers because the

    33See selectQueue operation in CheckOut class

    34See enterSupermarket operation in CheckOut class

  • 8/12/2019 Supermarket simulator.pdf

    27/27

    loop before the wait method in waitCustomer35

    operation specified that the thread had to

    wait until there were no customers. That is true, but when there were no customers in the

    supermarket workers were waiting for them the solution has been to add a new rule where

    says that the wait must be called while there are no customers in queue AND the

    supermarket is open.

    35See waitCustomer operation in CheckOut class