User: Password:
   Keep me logged in.
Register  |  I forgot my password

Login  |  Register

Efficient Java Tools  - Listing Details
Statisticsw
  • Active Links: 58
  • Pending Links: 6
  • Todays Links: 0
  • Active Articles: 6
  • Pending Articles: 0
  • Todays Articles: 0
  • Total Categories: 33
  • Sub Categories: 20

ID:116
Title:MultithreadedTC - a framework for testing concurrent Java applications
Pagerank:4
Short Description:
Listing Thumbnail

The MultithreadedTC framework was created to make it easier to test small concurrent abstractions. It enables test designers to guarantee a specific interleaving of two or more threads, even in the presence of blocking and timing issues.

Description:

Features are:

Concurrent application designers often want to run many (unrelated or loosely related) threads of activity to maximize throughput.

MultithreadedTC is different. It supports test cases that exercise a specific interleaving of threads. This is motivated by the principle that concurrent applications should be built using small concurrent abstractions such as bounded buffers, semaphores and latches. Separating the concurrency logic from the rest of the application logic in this way makes it easier to understand and test concurrent applications. Since these abstractions are small, it should be possible to deterministically test every (significant) interleaving in separate tests.

But how can one guarantee a specific interleaving of different threads in the presence of blocking and timing issues? Consider the following example of some operations on a bounded blocking buffer (e.g. ArrayBlockingQueue) with capacity 1.

We want a test to confirm that put 17 causes Thread 1 to block until take 42 occurs in Thread 2. The test must guarantee that take 42 is not executed until after put 17. How could a designer guarantee this interleaving of the two threads? 

One approach is to use Thread.sleep() in Thread 2 to delay its first statement long enough to "guarantee" that Thread 1 has blocked. But this approach makes the test timing-dependent ― timing can be thrown off by, say, an ill-timed garbage collector. This also does not work well when stepping through the code in a debugger. 

Another common approach for coordinating activities in two threads is to use a CountDownLatch. Of course the problem is that the statement c.countDown() cannot be executed until after Thread 1 unblocks... which will not occur until Thread 2 take()s.

In other words, this test is deadlocked! The class TestFramework, provides most of the scaffolding required to run MultithreadedTC tests. It uses reflection to identify all relevant methods in the test class, invokes them simultaneously in different threads. It regulates these threads using a separate clock thread. 

The clock thread checks periodically to see if all threads are blocked. If all threads are blocked and at least one is waiting for a tick, the clock thread advances the clock to the next desired tick. The clock thread also detects deadlock (when all threads are blocked, none are waiting for a tick, and none are in state TIMED_WAITING), and can stop a test that is going on too long (a thread is in state RUNNABLE for too long.) 

The test threads are placed into a new thread group, and any threads created by these test cases will be placed in this thread group by default. All threads in the thread group will be considered by the clock thread when deciding whether to advance the clock, declare a deadlock, or stop a long-running test.class MultithreadedTestCase extends junit.framework.Assert and provides the base functionality required by all tests. (NOTE: MultithreadedTestCase does NOT extend junit.framework.TestCase). A test using this class consists of:

  • an optional initialize() method,
  • one or more "thread" methods which are invoked in different threads,
  • an optional finish() method that is run after all threads have completed.
  • runOnce(MultithreadedTestCase) -- run a test sequence once,
  • runManyTimes(MultithreadedTestCase, int) -- run a test sequence as many times as specified by the int parameter, until one of the test runs fails.
Category:Testing
Link Owner:
Date Added:November 30, 2009 09:18:57 PM
Number Hits:7
URL:    http://www.cs.umd.edu/projects/PL/multithreadedtc/
Ratings
You must be logged in to leave a rating.
Average rating: (0 votes)
Reviews

No Reviews Yet.


You must be logged in to leave a Comment.
 
Bookmark Me
Latest articles
Java Licensing with Agilis
Agilis provides secure, flexible Java protection solutions to software vendors worldwide. Capabilities include Internet-based product activation on connected and disconnected systems, intranet or Internet-based floating licensing, node-locked licensing, named-user licensing, feature configuration, custom licensing, server licensing, trial licensing, subscription licensing, usage-based licensing, licensing via resellers or OEMs, revocable licensing, license reporting, user compliance management, backoffice integration and more.

FireStorm/DAO: What is DAO Design Pattern?
The Data Access Object (DAO) design pattern provides a technique for separating object persistence and data access logic from any particular persistence mechanism or API. There are clear benefits to this approach from an architectural perspective.

CA Plex: what is it?
Today’s business climate requires organizations to have business applications that help improve customer service, reduce costs, increase profits, get to market faster and respond more rapidly to competitive challenges. CA Plex provides a single, integrated environment that enables both traditional and SOA-based solutions for development. CA Plex uses building blocks known as patterns to help your development teams create and maintain large-scale business applications for multiple platforms — Windows/.NET, Java/J2EE or the IBM Power Systems/IBM i.

JCover Code Coverage: important to understand!
Why is coverage analysis important? Coverage analysis has the following benefits: * We can determine if our test suite is adequate. A test suite that achieves 65% statement coverage is hardly adequate. We cannot be confident of our product's quality with this much coverage. This figure prompts us to enhance the test suite. * We can identify redundant test cases that are not useful either in increasing code coverage or in finding new bugs. Fine tuning a test suite has immense benefits during regression testing. * We can find out if there are regions of code that cannot be exercised at all, and hence can be cleaned up. We sometimes find that an application has code to support a feature that was discontinued in an earlier release of the product! Although test cases are normally generated from the specification, coverage analysis helps us in identifying areas that require further test focus.

Codign CoView: JUnit Test Generation
Unit testing and coding go together like peanut butter and jelly. Each good by themself, but together? Now that's a good sandwich! Now you can benefit by easily creating the right JUnit test the first time. CoView provides a solution that makes sense, is unique and completely understandable. And it only takes 3 steps to have a complete set of JUnit tests for each of your classes.