667481 members! Sign up to stay informed.

Sponsored Links


Resources

Enterprise Java
Research Library

Get Java white papers, product information, case studies and webcasts

News News News Messages: 9 Messages: 9 Messages: 9 Printer friendly Printer friendly Printer friendly Post reply Post reply Post reply XML XML XML

Article: Testing Concurrent Programs

Posted by: Regina Lynch on September 27, 2006 DIGG
Testing concurrent programs can be extremely difficult; concurrent tests are themselves concurrent programs, which are difficult to write, and failures in concurrent programs are often rare probabilistic events rather than deterministic ones.

In this article, Brian Goetz, author of the recently-released Java Concurrency in Practice, explores some of the major issues in testing concurrent classes, and offers some techniques for constructing concurrent programs that make them easier to test.

What techniques have you found help overcome inevitable obstacles when testing concurrent programs?

Threaded replies

·  Article: Testing Concurrent Programs by Regina Lynch on Wed Sep 27 11:02:25 EDT 2006
  ·  Re: Article: Testing Concurrent Programs by Ilya Sterin on Wed Sep 27 11:42:30 EDT 2006
    ·  TestNG is the way to go for multi-tread testing by Ruslan Zenin on Thu Sep 28 10:48:39 EDT 2006
      ·  Re: TestNG is the way to go for multi-tread testing by Ilya Sterin on Thu Sep 28 11:49:09 EDT 2006
        ·  Re: TestNG is the way to go for multi-tread testing by Cedric Beust on Thu Sep 28 14:42:57 EDT 2006
  ·  Re: Article: Testing Concurrent Programs by Gideon Low on Wed Sep 27 12:09:36 EDT 2006
    ·  Re: Article: Testing Concurrent Programs by Ilya Sterin on Wed Sep 27 13:04:55 EDT 2006
    ·  Re: Article: Testing Concurrent Programs by Guido Anzuoni on Thu Sep 28 08:25:04 EDT 2006
      ·  Re: Article: Testing Concurrent Programs by Cedric Beust on Thu Sep 28 14:50:29 EDT 2006
        ·  Re: Article: Testing Concurrent Programs by Guido Anzuoni on Fri Sep 29 03:49:43 EDT 2006
  Message #218939 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Article: Testing Concurrent Programs

Posted by: Ilya Sterin on September 27, 2006 in response to Message #218768
Interesting, very well needed resource. I actually found the TestNG has nice build in support for concurrency, though allowing a test to run in specified number of threads and iterations. I didn't do a full fledged threading test, but it allowed me to consistently test a ThreadLocal implementation.



private volatile static Map<Long, Integer> objKeys = new HashMap<Long, Integer>();

@Test(threadPoolSize = 3, invocationCount = 6)
public void testGetConfiguration() {

ObjectManager objManager = ObjectManagerBuilder.buildObjectManager();

assertNotNull(objManager);

if (objKeys.get(Thread.currentThread().getId()) == null)
objKeys.put(Thread.currentThread().getId(), objManager.getId());

assertEquals(objKeys.get(Thread.currentThread().getId()).intValue(), objManager.getId());

}


  Message #218941 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Article: Testing Concurrent Programs

Posted by: Gideon Low on September 27, 2006 in response to Message #218768
This may be obvious, but newer developers may miss it (as I did long ago) . . . To detect many of the potential problems in an application with high concurrency, you have to use a multi-processor machine!

Cheers,

Gideon

  Message #218949 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Article: Testing Concurrent Programs

Posted by: Ilya Sterin on September 27, 2006 in response to Message #218941
This may be obvious, but newer developers may miss it (as I did long ago) . . . To detect many of the potential problems in an application with high concurrency, you have to use a multi-processor machine!

Cheers,

Gideon


Or today's dual core chips, which actually did a pretty good job disclosing a race condition bug I had. Also a unit test written with TestNG.

Ilya

  Message #218997 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Article: Testing Concurrent Programs

Posted by: Guido Anzuoni on September 28, 2006 in response to Message #218941
This may be obvious, but newer developers may miss it (as I did long ago) . . . To detect many of the potential problems in an application with high concurrency, you have to use a multi-processor machine!

Cheers,

Gideon

Really ?
I don't think Dijkstra had such a beast approaching the dining philosophers problem.
Concurrency problems must be detected (and solved) on paper.
Different story are the detection of concurrency bugs.

Guido.

  Message #219016 Post reply Post reply Post reply Go to top Go to top Go to top

TestNG is the way to go for multi-tread testing

Posted by: Ruslan Zenin on September 28, 2006 in response to Message #218939
I found that TestNG has pretty decent implementation of multi-threading. Easy to use, yet powerful!

Thank you Cedric for listening to developers and implementing this feature in TestNG!

This feature makes TestNG well ahead of the rest unit testing tools!

What Ilya has shown clearly demonstrates TestNG multi-thread functionality!

  Message #219023 Post reply Post reply Post reply Go to top Go to top Go to top

Re: TestNG is the way to go for multi-tread testing

Posted by: Ilya Sterin on September 28, 2006 in response to Message #219016
I found that TestNG has pretty decent implementation of multi-threading. Easy to use, yet powerful!

Thank you Cedric for listening to developers and implementing this feature in TestNG!

This feature makes TestNG well ahead of the rest unit testing tools!

What Ilya has shown clearly demonstrates TestNG multi-thread functionality!


Yeah, it would be nice for more fine grained thread control.

Right now, the threads and invocation don't really have a 1 to 1 mapping, so although there are three threads, there is no guarantee that say 2 invocations will run in the same thread, etc... It would be nice to add such a feature.



@Test(threadPoolSize = 3, invocationCount = 6, threadMap =
{2, 2, 2})

Basically stating that each thread has 2 invocations each. I'm sure there is a cleaner, friendlier way of doing this, with maybe more flexibility, but in general, we need to control thread/invocation combos.

Ilya

  Message #219030 Post reply Post reply Post reply Go to top Go to top Go to top

Re: TestNG is the way to go for multi-tread testing

Posted by: Cedric Beust on September 28, 2006 in response to Message #219023
Hi Ilya,

Yeah, it would be nice for more fine grained thread control.

Right now, the threads and invocation don't really have a 1 to 1 mapping, so although there are three threads, there is no guarantee that say 2 invocations will run in the same thread, etc... It would be nice to add such a feature.



@Test(threadPoolSize = 3, invocationCount = 6, threadMap =
{2, 2, 2})

Basically stating that each thread has 2 invocations each. I'm sure there is a cleaner, friendlier way of doing this, with maybe more flexibility, but in general, we need to control thread/invocation combos.

Ilya

I added a few functionalities recently to enable some of this. For example, you can specify that all the test methods inside a class should be run in the same thread, even if the current suite is being run in parallel (@Test(sequential = true)).

This was necessary for users who want to run their tests multithreaded for the speed gain, but who sometimes have to test methods that are not multithread-safe. Now, they can simply put these methods in a class that has the above attribute and TestNG will run them in the same thread.

As for your request and the threadMap, let me think about that (and let's take the discussion to the testng-users mailing-list).

--
Cedric

  Message #219032 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Article: Testing Concurrent Programs

Posted by: Cedric Beust on September 28, 2006 in response to Message #218997
Really ?
I don't think Dijkstra had such a beast approaching the dining philosophers problem.
Concurrency problems must be detected (and solved) on paper.
Different story are the detection of concurrency bugs.

Guido.

The world was much simpler back then :-)

Nowadays, it's pretty much impossible to guarantee multithread safety other than using statistical testing...

--
Cedric

  Message #219058 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Article: Testing Concurrent Programs

Posted by: Guido Anzuoni on September 29, 2006 in response to Message #219032
Really ?
I don't think Dijkstra had such a beast approaching the dining philosophers problem.
Concurrency problems must be detected (and solved) on paper.
Different story are the detection of concurrency bugs.

Guido.

The world was much simpler back then :-)

Nowadays, it's pretty much impossible to guarantee multithread safety other than using statistical testing...

--
Cedric

AFAICR from my studies, testing is a NP-complete problem.
In this respect you can only be quite confident that your
implementation is sufficiently robust.
You cannot guarantee anything.
But, again, your are talking about the implementation and
bug detection.
The solution must work or fail on paper.
As many of the problems' solutions.

Guido.

P.S.
I don't think the world was really much simpler back then.

New content on TheServerSide.comNew content on TheServerSide.comNew content on TheServerSide.com

Dependency Injection in Java EE 6 - Part 1

Reza Rahman explores the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6. (November 2, Article)

SAML: It's Not just for Web services

SAML is an XML-based standard for exchanging authentication and authorization data between security domains. The single most important problem that SAML was created to solve is the Web browser Single Sign-On problem. Many organizations are debating whether to stay with version 1.1 or move to 2.0. This article makes observations about both options. (September 28, Article)

Programming is Also Teaching Your Team

Joe Ottinger takes a look at how people learn, and applies it to the practice of programming. He notes that understanding how people learn is an essential part of working in a programming team. (September 22, Article)

Can Java EE Deliver The Asynchronous Web?

Stephen Maryka gave us an article about the Asynchronous Web and posed a number of questions that get examined like an approach to delivering Asynchronous Web capabilities through extensions to existing Java EE technologies. (July 14, Article)

JSF Flex

JavaServer Faces Flex goal is to provide users capability in creating standard Flex components, part of flexSDK which is open sourced through MPL license, as normal JSF components. This article by Ji Hoon Kim will provide an overview of creating a simple multilingual JSF page consisting of JSF Flex tags. (June 29, Article)

The Rules of SOA - A Road to a Successful SOA Implementation

In this session Jeff explores the key characteristics of successful SOA projects. He covers some of the patterns, and anti-patterns, tool sets, and strategies that he himself learned the hard way. Last, he provides a strategy and blueprint for achieving a high likelihood of success in your SOA project. (June 23, Tech Talk)

Ari Zilka Talks About Terracotta 3.1

Ari Zilka, CTO of Terracotta, Inc., talks about the new features in Terracotta 3.1, announced during JavaOne and available now. (June 15, Tech Talk)

Enterprise Application Integration, and Spring

In this Tech Talk, Josh Long explores an integration challenge using Spring Integration and walks through the implementation, employing and expanding on the basic patterns of Enterprise Application Integration to tie together components into a function integration solution, and then demonstrates how Spring Integration helps address the integration requirements. (June 15, Tech Talk)

Google Web Toolkit: An Introduction

In this Tech Talk, David Geary teaches you: The basics of Google Web Toolkit; How to implement Ajax-enabled applications in Java; Internationalization; Hooking into the browser history mechanism; Remote procedure calls. (June 4, Tech Talk)

Just Enough Early Architecture to Guide Development

Jon Kern discusses the best architecture/technical solutions and ensure that they are repeated by all developers. By tackling the architecture up-front in a serial manner, subsequent parallel development will be much more manageable and predictable. (May 28, Tech Talk)

Productive Programmer: On the Lam from the Furniture Police

This keynote describes the frustrations of modern knowledge workers in their quest to actually get some work done, and solutions for how to guard yourself against all those distractions. Neal Ford talks about environments, coding, acceleration, automation, and avoiding repetition as ways to defeat the misguided attempts to sap your ability to produce good work. (May 26, Tech Talk)

Auto-Scaling Your Existing Web Application

Gil demonstrates how new, aggressive uses of already abundant compute capacity by common applications offer competitive value for application designers. (May 21, Tech Talk)

Automating Hibernate Mapping and Queries For Java Web Development

Chris Keene introduces WaveMaker as a new way to automate the ability to generate Hibernate classes in order to more quickly bring OR mapping into an application. (May 19, Article)

Auto-Scaling Your Existing Web Application

In this session Nati Shalom demonstrates how to take a standard Java EE web application and scale it out or down dynamically without changes to the application code. Seeing as most web applications are over-provisioned to meet infrequent peak loads, this is a dramatic change because it enables growing your application as needed, when needed, without paying for unutilized resources. (May 19, Tech Talk)

Free Book PDF Download: Mastering EJB Third Edition

Mastering EJB was one of the original and most influential EJB books in the industry. Mastering EJB III now returns with two new expert co-authors, updated for EJB 2.1 and 30% new chapters including security, integration, best practices, open source, and more.
(Book PDF Download)

Application Server Matrix

The Application Server Matrix is a detailed listing of J2EE vendors and their application server products, with information on latest version numbers, J2EE spec support and licensing, pricing, platform support, and links to product downloads and reviews.
(Application Server Comparison Matrix)

News | Blogs | Discussions | Tech talks | Patterns | Reviews | White Papers | Downloads | Articles | Media kit | About
Java Solutions
All Content Copyright ©2007 TheServerSide Privacy Policy
Site Map