Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Docker for Mac #195

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -61,40 +62,47 @@ public class AmqMessagingPluginWithFailoverIntegrationTest extends AbstractJUnit
@Inject private DockerContainerHolder<ActiveMQContainer> docker1;

private ActiveMQContainer amq1 = null;
private ActiveMqMessagingProvider msgConfig = null;
private String broker = null;
private static final int INIT_WAIT = 360;

@Before public void setUp() throws Exception {
Plugin plugin = jenkins.getPlugin("dumpling");
assertNotNull(plugin);

amq1 = docker1.get();
private boolean configureAndConnect() throws IOException {
jenkins.configure();
elasticSleep(5000);
GlobalCIConfiguration ciPluginConfig = new GlobalCIConfiguration(jenkins.getConfigPage());
ActiveMqMessagingProvider msgConfig = new ActiveMqMessagingProvider(ciPluginConfig).addMessagingProvider();
if (msgConfig == null) {
msgConfig = new ActiveMqMessagingProvider(ciPluginConfig).addMessagingProvider();
}
broker = amq1.getBroker();
msgConfig.name("test")
.broker(createFailoverUrl(amq1.getBroker()))
.broker(createFailoverUrl(broker))
.topic("CI")
.userNameAuthentication("admin", "redhat");

int counter = 0;
boolean connected = false;
while (counter < INIT_WAIT) {
try {
msgConfig.testConnection();
waitFor(driver, hasContent("Successfully connected to " + createFailoverUrl(amq1.getBroker())), 5);
connected = true;
break;
elasticSleep(1000);
jenkins.save();
return true;
} catch (Exception e) {
counter++;
elasticSleep(1000);
}
}
if (!connected) {
return false;
}

@Before public void setUp() throws Exception {
Plugin plugin = jenkins.getPlugin("dumpling");
assertNotNull(plugin);

amq1 = docker1.get();
if (!configureAndConnect()) {
throw new Exception("Did not get connection successful message in " + INIT_WAIT + " secs.");
}
elasticSleep(1000);
jenkins.save();
}

private String createFailoverUrl(String broker) {
Expand Down Expand Up @@ -158,6 +166,18 @@ public void testSimpleCIEventTrigger() throws Exception {
System.out.println("Starting AMQ");
startAMQ();

// after restart the ports may have changed (likely)
if (!amq1.getBroker().equals(broker)) {
configureAndConnect();
// re-save the jobs because the AMQ ports may have changed
for (FreeStyleJob job : jobs) {
job.configure();
job.save();
}
jobB.configure();
jobB.save();
}

System.out.println("Waiting 10 secs");
elasticSleep(10000);
waitForNoAMQTaskThreads();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@
public class ActiveMQContainer extends DockerContainer {

public String getBroker() throws IOException {
String ip = getIpAddress();
if (ip == null || ip.equals("")) {
JsonNode binding = inspect().get("HostConfig").get("PortBindings").get("61616/tcp").get(0);
String hostIP = binding.get("HostIp").asText();
String hostPort = binding.get("HostPort").asText();
ip = hostIP + ":" + hostPort;
return "tcp://"+ip;
} else {
return "tcp://"+ip+":61616";
}
return String.format("tcp://%s:%d", ipBound(61616), port(61616));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I leave have to try this locally...I had issues when I started using podman on Fedora...hence why I had protection if ip was null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will use localhost and port forwarding.
For anybody using mac you can't directly access the container ip, you need to use the forwarded ports


}
}