Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

Commit

Permalink
Large clean up
Browse files Browse the repository at this point in the history
* Moved integration test into separate module. See https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-integration-testing/
* Removed test-framework-docker module since it tests a pre-1.0.0 Mesos framework
* Fixed most of the warnings and deprecation messages
  • Loading branch information
frankscholten committed Nov 4, 2016
1 parent 885408a commit c2cb207
Show file tree
Hide file tree
Showing 55 changed files with 169 additions and 1,303 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ subprojects {

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

tasks.withType(JavaCompile) {
compileJava {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}

Expand All @@ -56,8 +56,8 @@ subprojects {

jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
xml.enabled false
csv.enabled true
}
}

Expand Down
29 changes: 29 additions & 0 deletions cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,34 @@ afterEvaluate { project ->
}
}

sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}

configurations {
integrationTestCompile.extendsFrom mainCompile
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom mainRuntime
integrationTestRuntime.extendsFrom testRuntime
}

task integrationTest(type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
testLogging {
showStandardStreams = true
}
}

integrationTest.dependsOn buildDockerImage

project.build.dependsOn buildDockerImage

assemble.dependsOn jar
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.Test;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import static org.junit.Assert.assertEquals;
Expand All @@ -23,7 +24,7 @@ public class CommandPsTest {

private static final String FORMAT = "%-20s %-20s %s\n";
private static final Object[] COLUMNS = { "FRAMEWORK", "TASK", "STATE" };
private static final Object[] VALUES = { "marathon", "weave-scope", "TASK_RUNNING" };
private static final Object[] VALUES = {"marathon", "weave-scope", "TASK_RUNNING" };

private ByteArrayOutputStream outputStream;

Expand All @@ -36,7 +37,7 @@ public void initTest() {
}

@Test
public void execute() {
public void execute() throws UnsupportedEncodingException {
State state = new State();
Framework marathon = new Framework();
marathon.setName("marathon");
Expand Down Expand Up @@ -68,7 +69,7 @@ public void execute() {

commandPs.execute();

String result = outputStream.toString();
String result = outputStream.toString("UTF-8");
assertEquals(String.format(FORMAT, COLUMNS) + String.format(FORMAT, VALUES), result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void destroyCluster() {
@Test
public void testUpAndDestroy() {
CommandUp commandUp = new CommandUp();
commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile");
commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile");
commandUp.execute();

MesosCluster cluster = commandUp.getCluster();
Expand All @@ -59,14 +60,14 @@ public void testUpAndDestroy() {

@Test
public void testUp_invalidMinimesosFile() throws IOException {
FileUtils.write(repository.getMinimesosFile(), "invalid");
FileUtils.write(repository.getMinimesosFile(), "invalid", "UTF-8");

CommandUp commandUp = new CommandUp();
commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile");
commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile");
commandUp.execute();
MesosCluster cluster = commandUp.getCluster();

String fileContent = FileUtils.readFileToString(repository.getMinimesosFile());
String fileContent = FileUtils.readFileToString(repository.getMinimesosFile(), "UTF-8");
assertEquals("Invalid state file has not been overwritten", cluster.getClusterId(), fileContent);

CommandDestroy commandDestroy = new CommandDestroy();
Expand All @@ -80,7 +81,7 @@ public void testUp_invalidMinimesosFile() throws IOException {
@Test
public void testUp_alreadyRunning() {
CommandUp commandUp = new CommandUp();
commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile");
commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile");

commandUp.execute();
MesosCluster firstCluster = commandUp.getCluster();
Expand All @@ -101,13 +102,13 @@ public void testUp_alreadyRunning() {
@Test
public void testInfo_runningCluster() throws IOException {
CommandUp commandUp = new CommandUp();
commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile");
commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile");
commandUp.execute();

CommandInfo commandInfo = new CommandInfo(ps);
commandInfo.execute();

String result = outputStream.toString();
String result = outputStream.toString("UTF-8");

assertTrue(result.contains("Minimesos cluster is running"));
assertTrue(result.contains("Mesos version"));
Expand All @@ -118,21 +119,21 @@ public void testInfo_notRunning() throws IOException {
CommandInfo commandInfo = new CommandInfo(ps);
commandInfo.execute();

String result = outputStream.toString();
String result = outputStream.toString("UTF-8");
assertTrue("Expected phrase not found in: " + result, result.contains("Cluster ID is not found"));
}

@Test
public void testState() throws IOException {
CommandUp commandUp = new CommandUp();
commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile");
commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile");
commandUp.execute();
MesosCluster cluster = commandUp.getCluster();

CommandState commandState = new CommandState(ps);
commandState.execute();

JSONObject state = new JSONObject(outputStream.toString());
JSONObject state = new JSONObject(outputStream.toString("UTF-8"));

assertEquals("master@" + cluster.getMaster().getIpAddress() + ":5050", state.getString("leader"));
}
Expand All @@ -146,11 +147,11 @@ public void testInstallCommandValidation() {
@Test
public void testInstall() {
CommandUp commandUp = new CommandUp();
commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile");
commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile");
commandUp.execute();

CommandInstall install = new CommandInstall();
install.setMarathonFile("src/test/resources/app.json");
install.setMarathonFile("src/integration-test/resources/app.json");

install.execute();
}
Expand All @@ -161,7 +162,7 @@ public void testInstall_alreadyRunning() {
commandUp.execute();

CommandInstall install = new CommandInstall();
install.setMarathonFile("src/test/resources/app.json");
install.setMarathonFile("src/integration-test/resources/app.json");

install.execute();
install.execute();
Expand All @@ -172,17 +173,17 @@ public void testState_notRunning() throws IOException {
CommandState commandState = new CommandState(ps);
commandState.execute();

String result = outputStream.toString();
String result = outputStream.toString("UTF-8");
assertTrue(result.contains("Minimesos cluster is not running"));
}

@Test
public void testCompleteInitFile() {
public void testCompleteInitFile() throws UnsupportedEncodingException {
CommandUp commandUp = new CommandUp(ps);
commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile");
commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile");
commandUp.execute();

String result = outputStream.toString();
String result = outputStream.toString("UTF-8");

assertTrue("Command up output does not contain expected line", result.contains("Minimesos cluster is running"));
assertTrue(result.contains("Mesos version"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.mockito.Mockito;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

public class CommandUninstallTest {

Expand Down Expand Up @@ -43,22 +44,22 @@ public void initTest() {
}

@Test
public void execute() {
public void execute() throws UnsupportedEncodingException {
Mockito.doNothing().when(marathon).deleteApp("app");

commandUninstall.execute();

String result = outputStream.toString();
String result = outputStream.toString("UTF-8");
Assert.assertEquals("Deleted app 'app'\n", result);
}

@Test
public void execute_appDoesNotExist() {
public void execute_appDoesNotExist() throws UnsupportedEncodingException {
Mockito.doThrow(new MinimesosException("App does not exist")).when(marathon).deleteApp("app");

commandUninstall.execute();

String result = outputStream.toString();
String result = outputStream.toString("UTF-8");
Assert.assertEquals("", result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ public void testExecute_missingMinimesosFile() throws IOException {

@Test(expected = MinimesosException.class)
public void testExecute_invalidMinimesosFile() throws IOException {
commandUp.setClusterConfigPath("src/test/resources/configFiles/invalid-minimesosFile");
commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/invalid-minimesosFile");
commandUp.execute();
}

@Test
public void testBasicClusterConfig() throws IOException {
commandUp.setClusterConfigPath("src/test/resources/clusterconfig/basic.groovy");
commandUp.setClusterConfigPath("src/integration-test/resources/clusterconfig/basic.groovy");
commandUp.execute();

verify(mesosCluster).start();
}

@Test
public void testExecute_mapPortsToHost() {
commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile");
commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile");
commandUp.setMapPortsToHost(true);
commandUp.execute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ClusterConfig readClusterConfigFromMinimesosFile() {
if (clusterConfigFile != null) {
ConfigParser configParser = new ConfigParser();
try {
return configParser.parse(IOUtils.toString(clusterConfigFile));
return configParser.parse(IOUtils.toString(clusterConfigFile, "UTF-8"));
} catch (Exception e) {
String msg = String.format("Failed to load cluster configuration from %s: %s", getClusterConfigPath(), e.getMessage());
throw new MinimesosException(msg, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,28 @@ public void testInstall() throws IOException {
@Test
public void testUnsupportedCommand() throws IOException {
main.run(new String[]{"unsupported"});
String result = outputStream.toString();
String result = outputStream.toString("UTF-8");
assertUsageText(result);
}

@Test
public void testMinusMinusHelp() throws IOException {
main.run(new String[]{"--help"});
String result = outputStream.toString();
String result = outputStream.toString("UTF-8");
assertUsageText(result);
}

@Test
public void testInstallNoParameters() throws IOException {
main.run(new String[]{"install"});
String output = outputStream.toString();
String output = outputStream.toString("UTF-8");
assertTrue(output.contains("Usage: install [options]"));
}

@Test
public void testHelp() throws IOException {
main.run(new String[]{"help"});
String result = outputStream.toString();
String result = outputStream.toString("UTF-8");
assertUsageText(result);
}

Expand Down
55 changes: 44 additions & 11 deletions minimesos/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
apply plugin: "groovy"

sourceSets {
main {
groovy {
// this makes the groovy-compiler compile groovy- as well as java-files.
// Needed, because java is normally compiled before groovy.
// Since we are using groovy objects from java, we need it the other way round.
srcDirs = ['src/main/groovy', 'src/main/java']
}
java {
srcDirs = [] // don't compile Java code twice
}
}

integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}

dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.5'
compile 'com.github.docker-java:docker-java:3.0.6'
Expand All @@ -16,23 +39,33 @@ dependencies {
testCompile "org.mockito:mockito-core:1.+"
// using guru.nidi as maintenanance of the original project is dropped https://github.com/clarkware/jdepend/pull/9
testCompile "guru.nidi:jdepend:2.9.5"

integrationTestCompile 'junit:junit:4.11'
integrationTestCompile 'com.jayway.awaitility:awaitility:1.6.3'
}

sourceSets {
main {
groovy {
// this makes the groovy-compiler compile groovy- as well as java-files.
// Needed, because java is normally compiled before groovy.
// Since we are using groovy objects from java, we need it the other way round.
srcDirs = ['src/main/groovy', 'src/main/java']
}
java {
srcDirs = [] // don't compile Java code twice
}
compileGroovy {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}

configurations {
integrationTestCompile.extendsFrom mainCompile
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom mainRuntime
integrationTestRuntime.extendsFrom testRuntime
}

task integrationTest(type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
testLogging {
showStandardStreams = true
}
}

task installMinimesosScript(type: Copy) {
from "$rootDir/bin/minimesos"
into "/usr/local/bin"
}

integrationTest.dependsOn project(":cli").buildDockerImage
Loading

0 comments on commit c2cb207

Please sign in to comment.