Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Commit

Permalink
Merge branch 'robot'
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitfred committed Feb 11, 2012
2 parents cf2b58e + 6594fde commit 4896d98
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 15 deletions.
1 change: 1 addition & 0 deletions installer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>org.kercoin.magrit.Installer</mainClass>
Expand Down
85 changes: 70 additions & 15 deletions installer/src/main/java/org/kercoin/magrit/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,22 @@ static enum Profile {
}

private static final int BUFFER_SIZE = 2048;

private Installer() {


private final String[] args;

private Installer(String[] args) {
this.args = args;
}

private final File TEMP = new File(System.getProperty("java.io.tmpdir"));
private final String FILE_SEP = System.getProperty("file.separator");

private final File QUICKTEST_DIRECTORY = new File(TEMP, "magrit-quick");

private final Scanner in = new Scanner(System.in);

private Profile profile = Profile.UNKNOWN;
private File directory = QUICKTEST_DIRECTORY;

private String getVersion() {
String file = "META-INF/maven/org.kercoin.magrit/magrit-installer/pom.properties";
Expand All @@ -80,17 +85,23 @@ private String getVersion() {

private void go() {
try {
try {
if (isInteractive()) {
greetings();
} catch (InterruptedException e) {}
grabConfiguration();
grabConfiguration();
} else {
readConfigurationFromArgs();
}
install();
} catch(ExitException ee) {
} catch (ExitException ee) {
p(ee.getMessage());
}
}

private void greetings() throws InterruptedException {
private boolean isInteractive() {
return args == null || args.length == 0;
}

private void greetings() {
banner("Welcome to the MAGRIT INSTALLER", "Version: " + getVersion());

p("This will install Magrit in your system for a clean developer experience.");
Expand All @@ -106,29 +117,47 @@ private void greetings() throws InterruptedException {
p("If you just want to give a try to Magrit, you can quick test it :-)");
p("This will install Magrit and all working/temporary files in " + TEMP.getAbsolutePath() + FILE_SEP + "magrit-quick.");

Thread.sleep(1000);
pause();
nl();

p("So...");
Thread.sleep(1000);
pause();
nl();
}

private void pause() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}

private void grabConfiguration() {
int i = ask("Do you want to 1) TRY or to 2) INSTALL ? (1/2)", 1, 2);
if (i == 1) {
profile = Profile.QUICKTEST;
} else if (i == 2) {
profile = Profile.INSTALL;
directory = askDirectory("Where to install: [/tmp/magrit-quick]");
}
nl();
}


private void readConfigurationFromArgs() {
if ("--quick".equals(args[0])) {
profile = Profile.QUICKTEST;
} else if ("--install".equals(args[0]) && args.length == 2) {
profile = Profile.INSTALL;
directory = new File(args[1]);
}
}

private void install() {
switch(profile) {
case INSTALL:
banner("INSTALL");
throw new ExitException("Not yet available :-(");
quicktestSetup();
break;
case QUICKTEST:
banner("QUICKTEST setup");
quicktestSetup();
Expand All @@ -153,7 +182,7 @@ private void write(InputStream inputStream, File destDir, String name)

private void quicktestSetup() {
try {
final File magritDir = new File(TEMP, "magrit-quick");
final File magritDir = directory;
p("Setup sandbox: " + magritDir.getAbsolutePath());

// mkdir -p /tmp/magrit-quick/{bares,builds,keys}
Expand Down Expand Up @@ -271,6 +300,7 @@ public static void inflate(File archive, File where) {
}

private int ask(String question, int... validValues) {
in.reset();
int i=Integer.MIN_VALUE;
int tries=0;
p(question);
Expand All @@ -286,7 +316,32 @@ private int ask(String question, int... validValues) {
}
throw new ExitException("I give up!");
}


private File askDirectory(String question) {
in.reset();
in.nextLine();
String path="";
int tries=0;
p(question);
while (tries++<3) {
System.out.print("> ");
path = in.nextLine().trim();
if ("".equals(path)) {
return QUICKTEST_DIRECTORY;
}
File p = new File(path);
if (!p.isDirectory()) {
p(Color.RED, path + " isn't a directory");
} else if (!p.canWrite()) {
p(Color.RED, path + " isn't writable, check permissions");
} else if (!p.canExecute()) {
p(Color.RED, path + " isn't executable, check permissions");
}
return p;
}
throw new ExitException("I give up!");
}

@SuppressWarnings("serial")
static class ExitException extends RuntimeException {
ExitException(String message) {super(message);}
Expand All @@ -302,7 +357,7 @@ private boolean in(int actual, int... validValues) {
}

public static void main(String[] args) {
new Installer().go();
new Installer(args).go();
}

// ---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<module>client</module>
<module>server</module>
<module>installer</module>
<module>robot</module>
</modules>

</project>
Expand Down
86 changes: 86 additions & 0 deletions robot/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.kercoin.magrit</groupId>
<artifactId>magrit</artifactId>
<version>rebecca-SNAPSHOT</version>
</parent>

<artifactId>magrit-robot</artifactId>
<packaging>pom</packaging>

<name>magrit-robot</name>
<description>Automatated Regression Tests for Magrit.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<magrit.installer.directory>${project.build.directory}</magrit.installer.directory>
<magrit.installer.filename>magrit-last.jar</magrit.installer.filename>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.kercoin.magrit</groupId>
<artifactId>magrit-installer</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${magrit.installer.directory}</outputDirectory>
<destFileName>${magrit.installer.filename}</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>bash</executable>
<!-- optional -->
<workingDirectory>${basedir}</workingDirectory>
<arguments>
<argument>run.sh</argument>
<argument>${magrit.installer.directory}/${magrit.installer.filename}</argument>
</arguments>
</configuration>
</plugin>
</plugins>

<!--resources>
<resource>
<directory>src/main/bash</directory>
<filtering>true</filtering>
</resource>
</resources-->
</build>

</project>

91 changes: 91 additions & 0 deletions robot/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

function info {
echo "[INFO]" $*
}

function error {
echo "[ERROR]" $*
}

BASEDIR=$(pwd)

failures=0
errors=0
oks=0

function lsTestCases {
find . -maxdepth 1 -regex "\./t[0-9]*" -type d
}

function runTestCase {
local tc=$1
cd $tc
count=${#tc}
local i=0
while [ $i -lt $count ]; do
padding="-$padding"
let "i ++"
done
echo "/-- $tc --------------------------------------------------------------------------\\"
ts1=$(date +%s)
ns1=$(date +%N)
PATH=${BASEDIR}/${install_dir}/scripts:$PATH bash run.sh
ec=$?
ts2=$(date +%s)
ns2=$(date +%N)
echo "\\--$padding----------------------------------------------------------------------------/"
sec=$(echo "scale=3; ($ts2 - $ts1) * 1 + $ns2 / 1000000000 - $ns1 / 1000000000" | bc -l)
info "Took ${sec} sec"
if [ $ec -gt 0 ]; then
let "failures ++"
elif [ $ec -lt 0 ]; then
let "errors ++"
else
let "oks ++"
fi
cd $BASEDIR
info "-----------------------------------"
}

info "-----------------------------------"
info "Running integration tests"
info

installer=$1
install_dir='target/local'
rm -rf ${install_dir}
mkdir -p ${install_dir}

info "Installing..."
java -jar ${installer} --install ${install_dir} > /dev/null
bash ${install_dir}/setup.sh
info "Starting..."
bash ${install_dir}/start.sh > target/output.log &
PID=$(wait-tcp 2022 5) || exit 2
info "Server started"
info "-----------------------------------"
info "TESTS"
for tc in $(lsTestCases); do
runTestCase $tc
done
mistakes=$(( $failures + $errors ))
total=$(( $oks + $mistakes ))
info "OK: $oks"
info "Failures: $failures"
info "Errors: $errors"
info "Total: $total"
info "-----------------------------------"
info "Killing server"
kill $PID

info "Done"

info "-----------------------------------"
if [ $mistakes -eq 0 ]; then
info "TEST SUCCESSED"
else
error "TEST FAILED"
fi
exit $mistakes

26 changes: 26 additions & 0 deletions robot/t1/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

function check {
if [ $1 -gt 0 ]; then
exit $1
fi
}

(
magrit build-log -3
check $?
) | tee output.log

lines=$(wc -l <output.log)

function assert {
test $1 -eq $2
local ec=$?
if [ $ec -gt 0 ]; then
echo "{assert} Expected $1 but was $2"
exit $ec
fi
}

assert 4 $lines

0 comments on commit 4896d98

Please sign in to comment.