redis.embedded.ports.EphemeralPortProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of embedded-redis Show documentation
Show all versions of embedded-redis Show documentation
Redis embedded server for Java integration testing
package redis.embedded.ports;
import redis.embedded.PortProvider;
import redis.embedded.exceptions.RedisBuildingException;
import java.io.IOException;
import java.net.ServerSocket;
/**
* Created by piotrturek on 29/01/15.
*/
public class EphemeralPortProvider implements PortProvider {
@Override
public int next() {
try {
final ServerSocket socket = new ServerSocket(0);
socket.setReuseAddress(false);
int port = socket.getLocalPort();
socket.close();
return port;
} catch (IOException e) {
//should not ever happen
throw new RedisBuildingException("Could not provide ephemeral port", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy