kstyrc / embedded-redis

Redis embedded server for Java integration testing
840 stars 368 forks source link

The Redis Server does not stop upon application crash. #84

Open ChetanBhasin opened 7 years ago

ChetanBhasin commented 7 years ago

When the application crashes, the Redis server along with it does not stop. So if a test crashes, a person has to manually stop the process by killing it to free up the port.

dcrn commented 7 years ago

This is a problem with my project's unit tests also. We have to manually kill the redis server process after every test failure. (v0.6 on Windows)

maksymkovalenko commented 7 years ago

Just add a shutdown hook.

Runtime.getRuntime().addShutdownHook(new Thread() {
    public void run() { redis.stop(); }
});
ValeryIvanov commented 6 years ago

@maksymkovalenko this does not seem to work... could you please add more detailed example? where should this be added? in constructor?

stephenc commented 6 years ago

So, there is a way this could perhaps be made to work. Instead of launching redis directly, embedded-redis could use a wrapper script to kill redis when the JVM terminates... i.e. a wrapper script that does something like: https://stackoverflow.com/a/4054436/1589700

On the other hand, outside of testing, there could be valid reasons for keeping the process alive... for example if one were using redis to store application state and restarting the JVM to live self-"update" the application, you might be really annoyed if the embedded redis dies with the JVM