简体   繁体   English

如何模拟用于单元测试的服务器重新启动任务-Java?

[英]How to simulate a server reboot task for Unit Testing - Java?

I need to unit test a 'wait for reboot' action written in my code. 我需要对代码中编写的“等待重启”操作进行单元测试。 The code waits upto a specified timeout value given by the user for the server to restart and come up. 该代码等待用户给出的指定超时值,以使服务器重新启动并启动。 When the timeout value is elapsed, it will throw a Timed out exception. 当超时值过去时,它将抛出“超时”异常。

To test that, I need to simulate the behaviour of a server reboot. 为了测试这一点,我需要模拟服务器重启的行为。 Is that really possible?? 那真的有可能吗?

Note: I am using TestNG framework for my unit testing. 注意:我正在使用TestNG框架进行单元测试。

Well, In a simple manner, listen to different port OR different URL. 好吧,以一种简单的方式,监听不同的端口或不同的URL。 It simulates server is down. 它模拟服务器已关闭。

You can wait for some time in thread and change back URL to correct to simulate server UP! 您可以在线程中等待一段时间,然后改回URL以更正以模拟服务器UP!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM