Skip to content

Instantly share code, notes, and snippets.

@negz
Last active December 7, 2015 19:26
Show Gist options
  • Save negz/34f308bb0bf4a2701837 to your computer and use it in GitHub Desktop.
Save negz/34f308bb0bf4a2701837 to your computer and use it in GitHub Desktop.
Potential helios solo / testing usage.
package com.spotify.wiggum;
import com.google.common.net.HostAndPort;
import com.spotify.helios.testing.TemporaryJob;
import com.spotify.helios.testing.TemporaryJobs;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ServiceIT {
private final HeliosDeployment deployment = HeliosSoloDeployment.fromEnv().build();
@Rule
public TemporaryJobs temporaryJobs = TemporaryJobs.create(deployment.client());
private final HttpClient client = new DefaultHttpClient();
private TemporaryJob temporaryJob;
@Before
public void setup() {
// Deploy the wiggum image created during the last build.The wiggum container will be listening
// on a dynamically allocated port. 4229 is the port wiggum listens on in the container.
temporaryJob = temporaryJobs.job()
.imageFromBuild()
.port("wiggum", 4229)
.deploy();
}
@AfterClass
public void teardown() {
deployment.close()
}
@Test
public void testPing() throws Exception {
// send a request to a /ping endpoint using the host and dynamically
// allocated port of the job
HostAndPort port = temporaryJob.address("wiggum");
String pingUri = String.format("http://%s:%d/ping",
port.getHostText(),
port.getPort());
HttpResponse response = client.execute(new HttpGet(pingUri));
assertEquals("ping failed", 200, response.getStatusLine().getStatusCode());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment