在 Jmeter Junit 测试的设置中使用 JDBC

发布于 2024-10-08 08:10:11 字数 204 浏览 0 评论 0原文

我试图在通过 Jmeter 运行的 Junit 测试的设置和拆卸方法中使用 JDBC 连接到我的 MySQL 数据库。 Jmeter 将创建多个线程,每个线程将运行我的测试的一个实例。

我遇到的问题是,如果我在 Junit 测试的设置中实例化我的数据源,那么我的连接池就会耗尽连接。有没有办法设计我的测试以避免这种情况发生?我试图避免增加最大 MySQL 连接数来解决这个问题。

I was trying to use the JDBC to connect to my MySQL database in the setup and teardown methods of my Junit tests that are being run through Jmeter. Jmeter will create multiple threads, each of which will run one instance of my test.

The issue that I run into, is if I instantiate my datasource in the setup of my Junit test, then my connection pool runs out of connections. Is there a way to design my test so that this does not happen? I'm trying to avoid increasing my max MySQL connections to solve this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

零時差 2024-10-15 08:10:11

是的,请确保每个测试都关闭连接并在完成后将其返回到池中。听起来好像没有发生,但我不能确定。

如果情况并非如此,我建议更好地调整连接和线程池大小,以免耗尽。

Yes, make sure that each test closes the connection and returns it to the pool when it's done. Sounds like that's not happening, but I can't be sure.

If that's not the case, I'd recommend tuning your connection and thread pool sizes better so you don't run out.

无尽的现实 2024-10-15 08:10:11

一些建议:

  • 如果可能的话,使用模拟或模拟框架,如mockito。
  • 如果您还没有使用连接池,那么这可能会减轻拥有更多所需连接的开销。

A couple suggestions:

  • If possible use mocks or a mocking framework like mockito.
  • Use connection pooling if you're not already - this might alleviate the overhead of having more connections that you need.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文