Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #373 from spotify/rculbertson/test-helios-on-helios
Browse files Browse the repository at this point in the history
Added integration test which uses TempJobs
  • Loading branch information
rculbertson committed Feb 14, 2015
2 parents dbbefba + 084adaa commit 101fd37
Show file tree
Hide file tree
Showing 22 changed files with 272 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bin/helios
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [[ -e "$dir/../../helios" ]]; then
if [[ -e "$dir/../helios-tools" ]]; then
jar="$(ls -t $dir/../helios-tools/target/helios-tools*-shaded.jar | grep -v sources | grep -v javadoc | head -n 1)"
CLASSPATH="$(cd $(dirname $jar) && pwd -P)/$(basename $jar)"
echo "running in helios project, using $CLASSPATH" 1>&2
Expand Down
2 changes: 1 addition & 1 deletion bin/helios-agent
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fi
args=()
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [[ -e "$dir/../../helios" ]]; then
if [[ -e "$dir/../helios-services" ]]; then
jar="$(ls -t $dir/../helios-services/target/helios*-shaded.jar | grep -v sources | grep -v javadoc | head -n 1)"
CLASSPATH="$(cd $(dirname $jar) && pwd -P)/$(basename $jar)"
echo "running in helios project, using $CLASSPATH" 1>&2
Expand Down
2 changes: 1 addition & 1 deletion bin/helios-master
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fi
args=()
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [[ -e "$dir/../../helios" ]]; then
if [[ -e "$dir/../helios-services" ]]; then
jar="$(ls -t $dir/../helios-services/target/helios*-shaded.jar | grep -v sources | grep -v javadoc | head -n 1)"
CLASSPATH="$(cd $(dirname $jar) && pwd -P)/$(basename $jar)"
echo "running in helios project, using $CLASSPATH" 1>&2
Expand Down
15 changes: 7 additions & 8 deletions helios-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
<artifactId>helios-client</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.spotify</groupId>
<artifactId>helios-testing</artifactId>
Expand Down Expand Up @@ -70,7 +63,13 @@
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<masterImage>${project.parent.basedir}/helios-services/target/test-classes/master-image.json</masterImage>
<agentImage>${project.parent.basedir}/helios-services/target/test-classes/agent-image.json</agentImage>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -53,6 +54,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@Ignore
public class BasicFunctionalityITCase {

private static final Logger log = LoggerFactory.getLogger(BasicFunctionalityITCase.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.spotify.helios;

import com.google.common.collect.ImmutableList;

import com.spotify.helios.Utils.AgentStatusProber;
import com.spotify.helios.common.protocol.CreateJobResponse;
import com.spotify.helios.common.protocol.JobDeleteResponse;
import com.spotify.helios.common.protocol.JobDeployResponse;
import com.spotify.helios.common.protocol.JobUndeployResponse;
import com.spotify.helios.testing.TemporaryJob;
import com.spotify.helios.testing.TemporaryJobBuilder;
import com.spotify.helios.testing.TemporaryJobs;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import static com.spotify.helios.Utils.agentImage;
import static com.spotify.helios.Utils.masterImage;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

public class HeliosIT {

@Rule
public final TemporaryJobs temporaryJobs = TemporaryJobs.create();

private static final String TEST_USER = "HeliosIT";
private static final String TEST_HOST = "test-host";

private String masterEndpoint;

@Before
public void setup() throws Exception {
// zookeeper
final TemporaryJob zk = temporaryJobs.job()
.image("jplock/zookeeper:3.4.5")
.port("zk", 2181)
.deploy();

final String zkEndpoint = zk.address("zk").toString();

// helios master
final TemporaryJob master = temporaryJobs.job()
.image(masterImage())
.port("helios", 5801)
.command("--zk", zkEndpoint)
.deploy();

masterEndpoint = "http://" + master.address("helios").toString();

final ImmutableList.Builder<String> args = new ImmutableList.Builder<String>()
.add("--zk")
.add(zkEndpoint)
.add("--docker")
.add(System.getenv("DOCKER_HOST"))
.add("--name")
.add(TEST_HOST);

final String certPath = System.getenv("DOCKER_CERT_PATH");
if (certPath != null) {
args.add("--docker-cert-path=/certs");
}

// helios agent
final TemporaryJobBuilder agent = temporaryJobs.job()
.image(agentImage())
.prober(new AgentStatusProber(masterEndpoint, TEST_USER, TEST_HOST))
.port("agent", 8080) // need to expose fake port just so prober gets invoked
.command(args.build());

if (certPath != null) {
agent.volume("/certs", certPath);
}

agent.deploy();
}

@Test
public void test() throws Exception {
final CreateJobResponse create = cli(CreateJobResponse.class, "create", "test:1", "busybox");
assertThat(create.getStatus(), equalTo(CreateJobResponse.Status.OK));

final JobDeployResponse deploy = cli(JobDeployResponse.class, "deploy", "test:1", TEST_HOST);
assertThat(deploy.getStatus(), equalTo(JobDeployResponse.Status.OK));

final JobUndeployResponse undeploy = cli(JobUndeployResponse.class,
"undeploy", "--yes", "test:1", "-a");
assertThat(undeploy.getStatus(), equalTo(JobUndeployResponse.Status.OK));

final JobDeleteResponse delete = cli(JobDeleteResponse.class, "remove", "--yes", "test:1");
assertThat(delete.getStatus(), equalTo(JobDeleteResponse.Status.OK));
}

private <T> T cli(final Class<T> klass, final String... args) throws Exception {
return Utils.cli(klass, masterEndpoint, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.spotify.helios.testing.TemporaryJobs;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -22,6 +23,7 @@
* for the test to pass. It's easiest to use the vagrant image in the helios root directory
* which will install and run SkyDNS.
*/
@Ignore
public class TemporaryJobsSkyDnsITCase {

@Rule
Expand Down
100 changes: 100 additions & 0 deletions helios-integration-tests/src/test/java/com/spotify/helios/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.spotify.helios;

import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;

import com.fasterxml.jackson.databind.JsonNode;
import com.spotify.helios.cli.CliMain;
import com.spotify.helios.client.HeliosClient;
import com.spotify.helios.common.Json;
import com.spotify.helios.common.descriptors.HostStatus;
import com.spotify.helios.testing.Prober;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import static com.fasterxml.jackson.databind.node.JsonNodeType.STRING;
import static java.util.Arrays.asList;

public class Utils {

public static final String DEFAULT_IMAGE_INFO_PATH = "../helios-services/target/test-classes/";

public static <T> T cli(final Class<T> klass, final String masterEndpoint, final String... args)
throws Exception {
return cli(klass, masterEndpoint, asList(args));
}

private static <T> T cli(final Class<T> klass, final String masterEndpoint,
final List<String> args) throws Exception {
final ImmutableList<String> argList = new ImmutableList.Builder<String>()
.add("-z")
.add(masterEndpoint)
.add("--json")
.addAll(args)
.build();

return Json.read(main(argList).toString(), klass);
}

public static ByteArrayOutputStream main(final List<String> args) throws Exception {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ByteArrayOutputStream err = new ByteArrayOutputStream();
final CliMain main = new CliMain(new PrintStream(out), new PrintStream(err),
args.toArray(new String[args.size()]));
main.run();
return out;
}

public static String masterImage() throws IOException {
final String path = System.getProperty("masterImage",
DEFAULT_IMAGE_INFO_PATH + "master-image.json");
return imageInfo(path);
}

public static String agentImage() throws IOException {
final String path = System.getProperty("agentImage",
DEFAULT_IMAGE_INFO_PATH + "agent-image.json");
return imageInfo(path);
}

private static String imageInfo(final String path) throws IOException {
final String json = new String(Files.readAllBytes(Paths.get(path)));
final JsonNode node = Json.readTree(json);
final JsonNode imageNode = node.get("image");
return (imageNode == null || imageNode.getNodeType() != STRING) ? null : imageNode.asText();
}

public static class AgentStatusProber implements Prober {

private final HeliosClient client;
private final String hostName;

public AgentStatusProber(final String masterEndpoint, final String user,
final String hostName) {
this.hostName = hostName;
client = HeliosClient.newBuilder()
.setEndpoints(masterEndpoint)
.setUser(user)
.build();
}

@Override
public boolean probe(String host, int port) {
try {
final HostStatus hostStatus = client.hostStatus(hostName).get(10, TimeUnit.SECONDS);
return hostStatus != null && hostStatus.getStatus() == HostStatus.Status.UP;
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw Throwables.propagate(e);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
package com.spotify.helios.system;


import org.junit.Ignore;

@Ignore
public class CliDeploymentITCase extends CliDeploymentTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@

package com.spotify.helios.system;

import org.junit.Ignore;

@Ignore
public class ConfigFileJobCreationITCase extends ConfigFileJobCreationTest {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package com.spotify.helios.system;

import org.junit.Ignore;

@Ignore
public class DeploymentITCase extends DeploymentTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package com.spotify.helios.system;

import org.junit.Ignore;

@Ignore
public class FlappingITCase extends FlappingTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package com.spotify.helios.system;

import org.junit.Ignore;

@Ignore
public class IdMismatchJobCreateITCase extends IdMismatchJobCreateTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package com.spotify.helios.system;

import org.junit.Ignore;

@Ignore
public class ImageMissingITCase extends ImageMissingTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package com.spotify.helios.system;

import org.junit.Ignore;

@Ignore
public class JobHistoryITCase extends JobHistoryTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package com.spotify.helios.system;

import org.junit.Ignore;

@Ignore
public class JobWatchExactITCase extends JobWatchExactTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package com.spotify.helios.system;

import org.junit.Ignore;

@Ignore
public class JobWatchITCase extends JobWatchTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package com.spotify.helios.system;

import org.junit.Ignore;

@Ignore
public class PortCollisionJobITCase extends PortCollisionJobTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package com.spotify.helios.system;

import org.junit.Ignore;

@Ignore
public class PredefinedPortImageDeploymentITCase extends PredefinedPortImageDeploymentTest {

}
Loading

0 comments on commit 101fd37

Please sign in to comment.