2

Is there already some existing JUnit test for testing a BlockingQueue interface? Some class I can download, press play and then it turns red (hopefully green :-)), without me having to spend a day thinking of all test cases?

I googled but couldn't find anything.

some ideas?

EDIT: The test case that G_H provided was very good for debugging the basics. Is there maybe still a good test for heavy multithreaded use, that really provokes races and deadlocks?

Franz Kafka
  • 10,623
  • 20
  • 93
  • 149

1 Answers1

1

Since the BlockingQueue interface is part of the Java concurrency utilities, which were developed under the Java Specification Request 166 (JSR-166), I figure the code from the corresponding technology compatibility toolkit (or "tck") should be a good starting point. After all, implementations of the spec must pass said kit's tests in order to be considered compatible.

I've had no luck getting it from the JCP site (maybe requires membership), but the resources seem to be available here. Of interest are BlockingQueueTest and its super class JSR166TestCase, the most recent revisions of which can be found respectively here and here. Seems to be licensed under creative commons, but I advise you to verify the reliability of the given link and licensing constraints vis-a-vis your use for yourself.

Fortunately all of this seems to be using JUnit. I'm not certain about the version, but they're using the testMethod convention rather than annotations. With some adaptation I guess this code could be good to get you going.

G_H
  • 11,739
  • 3
  • 38
  • 82
  • Thanks, the test works after a few modifications, but it only really tests the basics. I can't see multiple threads being started, race conditions tested and deadlocks detected. That is the stuff I am more scared about than the basic javadoc specs... – Franz Kafka Oct 29 '11 at 14:41
  • @FranzKafka Didn't actually read the test cases... I would expect that sort of stuff to be tested as well. It's usually a bit of work in unit tests. Did some of that myself for a synchronized collection and it required some helper classes. Maybe there's a good test suite out there for multi-threading. I'd be interested in seeing that as well. – G_H Oct 30 '11 at 03:09