Skip to content

Instantly share code, notes, and snippets.

@mosheeshel
Created October 2, 2014 14:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mosheeshel/f43f80ddca9f75f11927 to your computer and use it in GitHub Desktop.
Save mosheeshel/f43f80ddca9f75f11927 to your computer and use it in GitHub Desktop.
JUnit @rule for starting a RabbitMQ container (based on other rule - see comments)
package rules;
import com.google.common.collect.ImmutableMap;
import org.eclipse.jdt.launching.SocketUtil;
import java.util.HashMap;
import java.util.Map;
/**
* Created with IntelliJ IDEA.
* User: moshe
* Date: 9/29/14
* Time: 4:02 PM
*/
public class RabbitContainerRule extends DockerContainerRule {
public static final String RABBIT_CONTAINER_IMAGE_NAME = "kenshoo/rabbitmq";
public static final String SERVICE_PORT = "RabbitMQServicePort";
public static final String MANAGEMENT_PORT = "RabbitMQManagementPort";
static String servicePort = Integer.toString(SocketUtil.findFreePort());
static String managementPort = Integer.toString(SocketUtil.findFreePort());
static String externalServicePort = Integer.toString(SocketUtil.findFreePort());
static String externalManagementPort = Integer.toString(SocketUtil.findFreePort());
static Map.Entry<String, String> internalPortEntry = new HashMap.SimpleEntry<String, String>(servicePort, externalServicePort);
static Map.Entry<String, String> externalPortEntry = new HashMap.SimpleEntry<String, String>(managementPort, externalManagementPort);
static Map<String, Map.Entry<String, String>> portEntryMap = ImmutableMap.of(SERVICE_PORT, internalPortEntry, MANAGEMENT_PORT, externalPortEntry);
static String[] cmd = new String[] {"-p" + servicePort, "-h" + managementPort} ;
public RabbitContainerRule() {
super(RABBIT_CONTAINER_IMAGE_NAME, portEntryMap, cmd);
}
public String getRabbitServicePort() {
return this.getExternalServicePorts().get(SERVICE_PORT);
}
public String getRabbitManagementPort() {
return this.getExternalServicePorts().get(MANAGEMENT_PORT);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment