I Have a Multi-threaded, shared-taxi simulator that I implemented.
In addition to the threads that produce real-time activities and display the road-map, the projects contains the following threads:
- A
MatchMakerthread that runs a matching algorithm between taxies and passengers. - Each
Taxiruns on its own thread, which calculates at any given moment the current position of the taxi and the shortest route to pick up and drop off all the passengers that theMatchMakerhas matched to it.
I want to write a JUnit test to check the order of operations (pickup, dropoff and route-changing) that each taxi is doing.
My naive solution is to make each thread write to a log file after each operation, e.g.
"Taxi <taxi-id> picked up <passenger-id>."
then reconstruct the order of operations from the log file. And finally, check if it matches my expectations.
However, I'm pretty sure that this approach is inefficient.
So, what is the correct/traditional way to test a thread's operations order?