-
-
Save virajkulkarni14/94f541e7e8d3d27265fdd06d4d82573f to your computer and use it in GitHub Desktop.
JUnit @rule for starting a RabbitMQ container (based on other rule - see comments)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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