BlockingQueue 接口的 JUnit 测试
是否已有一些用于测试 BlockingQueue
接口的 JUnit
测试?我可以下载一些课程,按播放,然后它会变成红色(希望是绿色:-)),而无需我花一天时间思考所有测试用例?
我用谷歌搜索但找不到任何东西。
一些想法?
编辑: G_H 提供的测试用例非常适合调试基础知识。对于大量的多线程使用,是否仍然存在一个很好的测试,这确实会引发竞争和死锁?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 BlockingQueue 接口是 Java 并发实用程序的一部分,它是根据 Java 规范请求 166 (JSR-166) 开发的,因此我认为相应技术兼容性工具包(或“tck”)中的代码应该是一个很好的起点。毕竟,规范的实现必须通过所述套件的测试才能被认为是兼容的。
我没能从 JCP 网站获得它(可能需要会员资格),但资源似乎是 可在此处获取。感兴趣的是 BlockingQueueTest 及其超类 JSR166TestCase,可以分别找到其最新修订版 此处 和 此处< /a>.似乎是根据知识共享获得许可的,但我建议您验证给定链接的可靠性以及您自己使用的许可限制。
幸运的是,所有这些似乎都在使用 JUnit。我不确定版本,但他们使用的是
testMethod
约定而不是注释。经过一些调整,我想这段代码可能会很好地帮助您前进。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.